ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/jsr166/jsr166/src/test/tck/ConcurrentSkipListSubSetTest.java
(Generate patch)

Comparing jsr166/src/test/tck/ConcurrentSkipListSubSetTest.java (file contents):
Revision 1.8 by jsr166, Sat Nov 21 02:07:26 2009 UTC vs.
Revision 1.12 by jsr166, Tue Dec 1 09:48:13 2009 UTC

# Line 19 | Line 19 | public class ConcurrentSkipListSubSetTes
19  
20      static class MyReverseComparator implements Comparator {
21          public int compare(Object x, Object y) {
22 <            int i = ((Integer)x).intValue();
23 <            int j = ((Integer)y).intValue();
24 <            if (i < j) return 1;
25 <            if (i > j) return -1;
26 <            return 0;
22 >            return ((Comparable)y).compareTo(x);
23          }
24      }
25  
# Line 138 | Line 134 | public class ConcurrentSkipListSubSetTes
134              NavigableSet q = set0();
135              q.add(null);
136              shouldThrow();
137 <        } catch (NullPointerException success) { }
137 >        } catch (NullPointerException success) {}
138      }
139  
140      /**
# Line 168 | Line 164 | public class ConcurrentSkipListSubSetTes
164              q.add(new Object());
165              q.add(new Object());
166              shouldThrow();
167 <        }
172 <        catch (ClassCastException success) {}
167 >        } catch (ClassCastException success) {}
168      }
169  
170  
# Line 181 | Line 176 | public class ConcurrentSkipListSubSetTes
176              NavigableSet q = set0();
177              q.addAll(null);
178              shouldThrow();
179 <        }
185 <        catch (NullPointerException success) {}
179 >        } catch (NullPointerException success) {}
180      }
181      /**
182       * addAll of a collection with null elements throws NPE
# Line 193 | Line 187 | public class ConcurrentSkipListSubSetTes
187              Integer[] ints = new Integer[SIZE];
188              q.addAll(Arrays.asList(ints));
189              shouldThrow();
190 <        }
197 <        catch (NullPointerException success) {}
190 >        } catch (NullPointerException success) {}
191      }
192      /**
193       * addAll of a collection with any null elements throws NPE after
# Line 208 | Line 201 | public class ConcurrentSkipListSubSetTes
201                  ints[i] = new Integer(i+SIZE);
202              q.addAll(Arrays.asList(ints));
203              shouldThrow();
204 <        }
212 <        catch (NullPointerException success) {}
204 >        } catch (NullPointerException success) {}
205      }
206  
207      /**
208       * Set contains all elements of successful addAll
209       */
210      public void testAddAll5() {
211 <        try {
212 <            Integer[] empty = new Integer[0];
213 <            Integer[] ints = new Integer[SIZE];
214 <            for (int i = 0; i < SIZE; ++i)
215 <                ints[i] = new Integer(SIZE-1- i);
216 <            NavigableSet q = set0();
217 <            assertFalse(q.addAll(Arrays.asList(empty)));
218 <            assertTrue(q.addAll(Arrays.asList(ints)));
219 <            for (int i = 0; i < SIZE; ++i)
228 <                assertEquals(new Integer(i), q.pollFirst());
229 <        }
230 <        finally {}
211 >        Integer[] empty = new Integer[0];
212 >        Integer[] ints = new Integer[SIZE];
213 >        for (int i = 0; i < SIZE; ++i)
214 >            ints[i] = new Integer(SIZE-1- i);
215 >        NavigableSet q = set0();
216 >        assertFalse(q.addAll(Arrays.asList(empty)));
217 >        assertTrue(q.addAll(Arrays.asList(ints)));
218 >        for (int i = 0; i < SIZE; ++i)
219 >            assertEquals(new Integer(i), q.pollFirst());
220      }
221  
222      /**
# Line 236 | Line 225 | public class ConcurrentSkipListSubSetTes
225      public void testPoll() {
226          NavigableSet q = populatedSet(SIZE);
227          for (int i = 0; i < SIZE; ++i) {
228 <            assertEquals(i, ((Integer)q.pollFirst()).intValue());
228 >            assertEquals(i, q.pollFirst());
229          }
230          assertNull(q.pollFirst());
231      }
# Line 349 | Line 338 | public class ConcurrentSkipListSubSetTes
338  
339          Object e4 = q.lower(zero);
340          assertNull(e4);
352
341      }
342  
343      /**
# Line 368 | Line 356 | public class ConcurrentSkipListSubSetTes
356  
357          Object e4 = q.higher(six);
358          assertNull(e4);
371
359      }
360  
361      /**
# Line 387 | Line 374 | public class ConcurrentSkipListSubSetTes
374  
375          Object e4 = q.floor(zero);
376          assertNull(e4);
390
377      }
378  
379      /**
# Line 406 | Line 392 | public class ConcurrentSkipListSubSetTes
392  
393          Object e4 = q.ceiling(six);
394          assertNull(e4);
409
395      }
396  
397      /**
# Line 494 | Line 479 | public class ConcurrentSkipListSubSetTes
479      /**
480       * A deserialized serialized set has same elements
481       */
482 <    public void testSerialization() {
482 >    public void testSerialization() throws Exception {
483          NavigableSet q = populatedSet(SIZE);
484 <        try {
485 <            ByteArrayOutputStream bout = new ByteArrayOutputStream(10000);
486 <            ObjectOutputStream out = new ObjectOutputStream(new BufferedOutputStream(bout));
487 <            out.writeObject(q);
488 <            out.close();
489 <
490 <            ByteArrayInputStream bin = new ByteArrayInputStream(bout.toByteArray());
491 <            ObjectInputStream in = new ObjectInputStream(new BufferedInputStream(bin));
492 <            NavigableSet r = (NavigableSet)in.readObject();
493 <            assertEquals(q.size(), r.size());
494 <            while (!q.isEmpty())
510 <                assertEquals(q.pollFirst(), r.pollFirst());
511 <        } catch (Exception e) {
512 <            e.printStackTrace();
513 <            unexpectedException();
514 <        }
484 >        ByteArrayOutputStream bout = new ByteArrayOutputStream(10000);
485 >        ObjectOutputStream out = new ObjectOutputStream(new BufferedOutputStream(bout));
486 >        out.writeObject(q);
487 >        out.close();
488 >
489 >        ByteArrayInputStream bin = new ByteArrayInputStream(bout.toByteArray());
490 >        ObjectInputStream in = new ObjectInputStream(new BufferedInputStream(bin));
491 >        NavigableSet r = (NavigableSet)in.readObject();
492 >        assertEquals(q.size(), r.size());
493 >        while (!q.isEmpty())
494 >            assertEquals(q.pollFirst(), r.pollFirst());
495      }
496  
497      /**
# Line 656 | Line 636 | public class ConcurrentSkipListSubSetTes
636              NavigableSet q = dset0();
637              q.add(null);
638              shouldThrow();
639 <        } catch (NullPointerException success) { }
639 >        } catch (NullPointerException success) {}
640      }
641  
642      /**
# Line 686 | Line 666 | public class ConcurrentSkipListSubSetTes
666              q.add(new Object());
667              q.add(new Object());
668              shouldThrow();
669 <        }
690 <        catch (ClassCastException success) {}
669 >        } catch (ClassCastException success) {}
670      }
671  
672  
# Line 699 | Line 678 | public class ConcurrentSkipListSubSetTes
678              NavigableSet q = dset0();
679              q.addAll(null);
680              shouldThrow();
681 <        }
703 <        catch (NullPointerException success) {}
681 >        } catch (NullPointerException success) {}
682      }
683      /**
684       * addAll of a collection with null elements throws NPE
# Line 711 | Line 689 | public class ConcurrentSkipListSubSetTes
689              Integer[] ints = new Integer[SIZE];
690              q.addAll(Arrays.asList(ints));
691              shouldThrow();
692 <        }
715 <        catch (NullPointerException success) {}
692 >        } catch (NullPointerException success) {}
693      }
694      /**
695       * addAll of a collection with any null elements throws NPE after
# Line 726 | Line 703 | public class ConcurrentSkipListSubSetTes
703                  ints[i] = new Integer(i+SIZE);
704              q.addAll(Arrays.asList(ints));
705              shouldThrow();
706 <        }
730 <        catch (NullPointerException success) {}
706 >        } catch (NullPointerException success) {}
707      }
708  
709      /**
710       * Set contains all elements of successful addAll
711       */
712      public void testDescendingAddAll5() {
713 <        try {
714 <            Integer[] empty = new Integer[0];
715 <            Integer[] ints = new Integer[SIZE];
716 <            for (int i = 0; i < SIZE; ++i)
717 <                ints[i] = new Integer(SIZE-1- i);
718 <            NavigableSet q = dset0();
719 <            assertFalse(q.addAll(Arrays.asList(empty)));
720 <            assertTrue(q.addAll(Arrays.asList(ints)));
721 <            for (int i = 0; i < SIZE; ++i)
746 <                assertEquals(new Integer(i), q.pollFirst());
747 <        }
748 <        finally {}
713 >        Integer[] empty = new Integer[0];
714 >        Integer[] ints = new Integer[SIZE];
715 >        for (int i = 0; i < SIZE; ++i)
716 >            ints[i] = new Integer(SIZE-1- i);
717 >        NavigableSet q = dset0();
718 >        assertFalse(q.addAll(Arrays.asList(empty)));
719 >        assertTrue(q.addAll(Arrays.asList(ints)));
720 >        for (int i = 0; i < SIZE; ++i)
721 >            assertEquals(new Integer(i), q.pollFirst());
722      }
723  
724      /**
# Line 754 | Line 727 | public class ConcurrentSkipListSubSetTes
727      public void testDescendingPoll() {
728          NavigableSet q = populatedSet(SIZE);
729          for (int i = 0; i < SIZE; ++i) {
730 <            assertEquals(i, ((Integer)q.pollFirst()).intValue());
730 >            assertEquals(i, q.pollFirst());
731          }
732          assertNull(q.pollFirst());
733      }
# Line 867 | Line 840 | public class ConcurrentSkipListSubSetTes
840  
841          Object e4 = q.lower(zero);
842          assertNull(e4);
870
843      }
844  
845      /**
# Line 886 | Line 858 | public class ConcurrentSkipListSubSetTes
858  
859          Object e4 = q.higher(m6);
860          assertNull(e4);
889
861      }
862  
863      /**
# Line 905 | Line 876 | public class ConcurrentSkipListSubSetTes
876  
877          Object e4 = q.floor(zero);
878          assertNull(e4);
908
879      }
880  
881      /**
# Line 924 | Line 894 | public class ConcurrentSkipListSubSetTes
894  
895          Object e4 = q.ceiling(m6);
896          assertNull(e4);
927
897      }
898  
899      /**
# Line 1012 | Line 981 | public class ConcurrentSkipListSubSetTes
981      /**
982       * A deserialized serialized set has same elements
983       */
984 <    public void testDescendingSerialization() {
984 >    public void testDescendingSerialization() throws Exception {
985          NavigableSet q = populatedSet(SIZE);
986 <        try {
987 <            ByteArrayOutputStream bout = new ByteArrayOutputStream(10000);
988 <            ObjectOutputStream out = new ObjectOutputStream(new BufferedOutputStream(bout));
989 <            out.writeObject(q);
990 <            out.close();
991 <
992 <            ByteArrayInputStream bin = new ByteArrayInputStream(bout.toByteArray());
993 <            ObjectInputStream in = new ObjectInputStream(new BufferedInputStream(bin));
994 <            NavigableSet r = (NavigableSet)in.readObject();
995 <            assertEquals(q.size(), r.size());
996 <            while (!q.isEmpty())
1028 <                assertEquals(q.pollFirst(), r.pollFirst());
1029 <        } catch (Exception e) {
1030 <            e.printStackTrace();
1031 <            unexpectedException();
1032 <        }
986 >        ByteArrayOutputStream bout = new ByteArrayOutputStream(10000);
987 >        ObjectOutputStream out = new ObjectOutputStream(new BufferedOutputStream(bout));
988 >        out.writeObject(q);
989 >        out.close();
990 >
991 >        ByteArrayInputStream bin = new ByteArrayInputStream(bout.toByteArray());
992 >        ObjectInputStream in = new ObjectInputStream(new BufferedInputStream(bin));
993 >        NavigableSet r = (NavigableSet)in.readObject();
994 >        assertEquals(q.size(), r.size());
995 >        while (!q.isEmpty())
996 >            assertEquals(q.pollFirst(), r.pollFirst());
997      }
998  
999      /**

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines