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.14 by jsr166, Wed Aug 25 01:44:48 2010 UTC

# Line 11 | Line 11 | import java.io.*;
11  
12   public class ConcurrentSkipListSubSetTest extends JSR166TestCase {
13      public static void main(String[] args) {
14 <        junit.textui.TestRunner.run (suite());
14 >        junit.textui.TestRunner.run(suite());
15      }
16      public static Test suite() {
17          return new TestSuite(ConcurrentSkipListSubSetTest.class);
# 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      /**
183       * addAll of a collection with null elements throws NPE
184       */
# Line 193 | Line 188 | public class ConcurrentSkipListSubSetTes
188              Integer[] ints = new Integer[SIZE];
189              q.addAll(Arrays.asList(ints));
190              shouldThrow();
191 <        }
197 <        catch (NullPointerException success) {}
191 >        } catch (NullPointerException success) {}
192      }
193 +
194      /**
195       * addAll of a collection with any null elements throws NPE after
196       * possibly adding some elements
# Line 208 | Line 203 | public class ConcurrentSkipListSubSetTes
203                  ints[i] = new Integer(i+SIZE);
204              q.addAll(Arrays.asList(ints));
205              shouldThrow();
206 <        }
212 <        catch (NullPointerException success) {}
206 >        } catch (NullPointerException success) {}
207      }
208  
209      /**
210       * Set contains all elements of successful addAll
211       */
212      public void testAddAll5() {
213 <        try {
214 <            Integer[] empty = new Integer[0];
215 <            Integer[] ints = new Integer[SIZE];
216 <            for (int i = 0; i < SIZE; ++i)
217 <                ints[i] = new Integer(SIZE-1- i);
218 <            NavigableSet q = set0();
219 <            assertFalse(q.addAll(Arrays.asList(empty)));
220 <            assertTrue(q.addAll(Arrays.asList(ints)));
221 <            for (int i = 0; i < SIZE; ++i)
228 <                assertEquals(new Integer(i), q.pollFirst());
229 <        }
230 <        finally {}
213 >        Integer[] empty = new Integer[0];
214 >        Integer[] ints = new Integer[SIZE];
215 >        for (int i = 0; i < SIZE; ++i)
216 >            ints[i] = new Integer(SIZE-1- i);
217 >        NavigableSet q = set0();
218 >        assertFalse(q.addAll(Arrays.asList(empty)));
219 >        assertTrue(q.addAll(Arrays.asList(ints)));
220 >        for (int i = 0; i < SIZE; ++i)
221 >            assertEquals(new Integer(i), q.pollFirst());
222      }
223  
224      /**
# Line 236 | Line 227 | public class ConcurrentSkipListSubSetTes
227      public void testPoll() {
228          NavigableSet q = populatedSet(SIZE);
229          for (int i = 0; i < SIZE; ++i) {
230 <            assertEquals(i, ((Integer)q.pollFirst()).intValue());
230 >            assertEquals(i, q.pollFirst());
231          }
232          assertNull(q.pollFirst());
233      }
# Line 349 | Line 340 | public class ConcurrentSkipListSubSetTes
340  
341          Object e4 = q.lower(zero);
342          assertNull(e4);
352
343      }
344  
345      /**
# Line 368 | Line 358 | public class ConcurrentSkipListSubSetTes
358  
359          Object e4 = q.higher(six);
360          assertNull(e4);
371
361      }
362  
363      /**
# Line 387 | Line 376 | public class ConcurrentSkipListSubSetTes
376  
377          Object e4 = q.floor(zero);
378          assertNull(e4);
390
379      }
380  
381      /**
# Line 406 | Line 394 | public class ConcurrentSkipListSubSetTes
394  
395          Object e4 = q.ceiling(six);
396          assertNull(e4);
409
397      }
398  
399      /**
# Line 463 | Line 450 | public class ConcurrentSkipListSubSetTes
450      /**
451       * iterator.remove removes current element
452       */
453 <    public void testIteratorRemove () {
453 >    public void testIteratorRemove() {
454          final NavigableSet q = set0();
455          q.add(new Integer(2));
456          q.add(new Integer(1));
# Line 494 | Line 481 | public class ConcurrentSkipListSubSetTes
481      /**
482       * A deserialized serialized set has same elements
483       */
484 <    public void testSerialization() {
484 >    public void testSerialization() throws Exception {
485          NavigableSet q = populatedSet(SIZE);
486 <        try {
487 <            ByteArrayOutputStream bout = new ByteArrayOutputStream(10000);
488 <            ObjectOutputStream out = new ObjectOutputStream(new BufferedOutputStream(bout));
489 <            out.writeObject(q);
490 <            out.close();
491 <
492 <            ByteArrayInputStream bin = new ByteArrayInputStream(bout.toByteArray());
493 <            ObjectInputStream in = new ObjectInputStream(new BufferedInputStream(bin));
494 <            NavigableSet r = (NavigableSet)in.readObject();
495 <            assertEquals(q.size(), r.size());
496 <            while (!q.isEmpty())
510 <                assertEquals(q.pollFirst(), r.pollFirst());
511 <        } catch (Exception e) {
512 <            e.printStackTrace();
513 <            unexpectedException();
514 <        }
486 >        ByteArrayOutputStream bout = new ByteArrayOutputStream(10000);
487 >        ObjectOutputStream out = new ObjectOutputStream(new BufferedOutputStream(bout));
488 >        out.writeObject(q);
489 >        out.close();
490 >
491 >        ByteArrayInputStream bin = new ByteArrayInputStream(bout.toByteArray());
492 >        ObjectInputStream in = new ObjectInputStream(new BufferedInputStream(bin));
493 >        NavigableSet r = (NavigableSet)in.readObject();
494 >        assertEquals(q.size(), r.size());
495 >        while (!q.isEmpty())
496 >            assertEquals(q.pollFirst(), r.pollFirst());
497      }
498  
499      /**
# Line 656 | Line 638 | public class ConcurrentSkipListSubSetTes
638              NavigableSet q = dset0();
639              q.add(null);
640              shouldThrow();
641 <        } catch (NullPointerException success) { }
641 >        } catch (NullPointerException success) {}
642      }
643  
644      /**
# Line 686 | Line 668 | public class ConcurrentSkipListSubSetTes
668              q.add(new Object());
669              q.add(new Object());
670              shouldThrow();
671 <        }
690 <        catch (ClassCastException success) {}
671 >        } catch (ClassCastException success) {}
672      }
673  
674  
# Line 699 | Line 680 | public class ConcurrentSkipListSubSetTes
680              NavigableSet q = dset0();
681              q.addAll(null);
682              shouldThrow();
683 <        }
703 <        catch (NullPointerException success) {}
683 >        } catch (NullPointerException success) {}
684      }
685 +
686      /**
687       * addAll of a collection with null elements throws NPE
688       */
# Line 711 | Line 692 | public class ConcurrentSkipListSubSetTes
692              Integer[] ints = new Integer[SIZE];
693              q.addAll(Arrays.asList(ints));
694              shouldThrow();
695 <        }
715 <        catch (NullPointerException success) {}
695 >        } catch (NullPointerException success) {}
696      }
697 +
698      /**
699       * addAll of a collection with any null elements throws NPE after
700       * possibly adding some elements
# Line 726 | Line 707 | public class ConcurrentSkipListSubSetTes
707                  ints[i] = new Integer(i+SIZE);
708              q.addAll(Arrays.asList(ints));
709              shouldThrow();
710 <        }
730 <        catch (NullPointerException success) {}
710 >        } catch (NullPointerException success) {}
711      }
712  
713      /**
714       * Set contains all elements of successful addAll
715       */
716      public void testDescendingAddAll5() {
717 <        try {
718 <            Integer[] empty = new Integer[0];
719 <            Integer[] ints = new Integer[SIZE];
720 <            for (int i = 0; i < SIZE; ++i)
721 <                ints[i] = new Integer(SIZE-1- i);
722 <            NavigableSet q = dset0();
723 <            assertFalse(q.addAll(Arrays.asList(empty)));
724 <            assertTrue(q.addAll(Arrays.asList(ints)));
725 <            for (int i = 0; i < SIZE; ++i)
746 <                assertEquals(new Integer(i), q.pollFirst());
747 <        }
748 <        finally {}
717 >        Integer[] empty = new Integer[0];
718 >        Integer[] ints = new Integer[SIZE];
719 >        for (int i = 0; i < SIZE; ++i)
720 >            ints[i] = new Integer(SIZE-1- i);
721 >        NavigableSet q = dset0();
722 >        assertFalse(q.addAll(Arrays.asList(empty)));
723 >        assertTrue(q.addAll(Arrays.asList(ints)));
724 >        for (int i = 0; i < SIZE; ++i)
725 >            assertEquals(new Integer(i), q.pollFirst());
726      }
727  
728      /**
# Line 754 | Line 731 | public class ConcurrentSkipListSubSetTes
731      public void testDescendingPoll() {
732          NavigableSet q = populatedSet(SIZE);
733          for (int i = 0; i < SIZE; ++i) {
734 <            assertEquals(i, ((Integer)q.pollFirst()).intValue());
734 >            assertEquals(i, q.pollFirst());
735          }
736          assertNull(q.pollFirst());
737      }
# Line 867 | Line 844 | public class ConcurrentSkipListSubSetTes
844  
845          Object e4 = q.lower(zero);
846          assertNull(e4);
870
847      }
848  
849      /**
# Line 886 | Line 862 | public class ConcurrentSkipListSubSetTes
862  
863          Object e4 = q.higher(m6);
864          assertNull(e4);
889
865      }
866  
867      /**
# Line 905 | Line 880 | public class ConcurrentSkipListSubSetTes
880  
881          Object e4 = q.floor(zero);
882          assertNull(e4);
908
883      }
884  
885      /**
# Line 924 | Line 898 | public class ConcurrentSkipListSubSetTes
898  
899          Object e4 = q.ceiling(m6);
900          assertNull(e4);
927
901      }
902  
903      /**
# Line 981 | Line 954 | public class ConcurrentSkipListSubSetTes
954      /**
955       * iterator.remove removes current element
956       */
957 <    public void testDescendingIteratorRemove () {
957 >    public void testDescendingIteratorRemove() {
958          final NavigableSet q = dset0();
959          q.add(new Integer(2));
960          q.add(new Integer(1));
# Line 1012 | Line 985 | public class ConcurrentSkipListSubSetTes
985      /**
986       * A deserialized serialized set has same elements
987       */
988 <    public void testDescendingSerialization() {
988 >    public void testDescendingSerialization() throws Exception {
989          NavigableSet q = populatedSet(SIZE);
990 <        try {
991 <            ByteArrayOutputStream bout = new ByteArrayOutputStream(10000);
992 <            ObjectOutputStream out = new ObjectOutputStream(new BufferedOutputStream(bout));
993 <            out.writeObject(q);
994 <            out.close();
995 <
996 <            ByteArrayInputStream bin = new ByteArrayInputStream(bout.toByteArray());
997 <            ObjectInputStream in = new ObjectInputStream(new BufferedInputStream(bin));
998 <            NavigableSet r = (NavigableSet)in.readObject();
999 <            assertEquals(q.size(), r.size());
1000 <            while (!q.isEmpty())
1028 <                assertEquals(q.pollFirst(), r.pollFirst());
1029 <        } catch (Exception e) {
1030 <            e.printStackTrace();
1031 <            unexpectedException();
1032 <        }
990 >        ByteArrayOutputStream bout = new ByteArrayOutputStream(10000);
991 >        ObjectOutputStream out = new ObjectOutputStream(new BufferedOutputStream(bout));
992 >        out.writeObject(q);
993 >        out.close();
994 >
995 >        ByteArrayInputStream bin = new ByteArrayInputStream(bout.toByteArray());
996 >        ObjectInputStream in = new ObjectInputStream(new BufferedInputStream(bin));
997 >        NavigableSet r = (NavigableSet)in.readObject();
998 >        assertEquals(q.size(), r.size());
999 >        while (!q.isEmpty())
1000 >            assertEquals(q.pollFirst(), r.pollFirst());
1001      }
1002  
1003      /**

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines