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.11 by jsr166, Sun Nov 22 18:57:17 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 494 | Line 483 | public class ConcurrentSkipListSubSetTes
483      /**
484       * A deserialized serialized set has same elements
485       */
486 <    public void testSerialization() {
486 >    public void testSerialization() throws Exception {
487          NavigableSet q = populatedSet(SIZE);
488 <        try {
489 <            ByteArrayOutputStream bout = new ByteArrayOutputStream(10000);
490 <            ObjectOutputStream out = new ObjectOutputStream(new BufferedOutputStream(bout));
491 <            out.writeObject(q);
492 <            out.close();
493 <
494 <            ByteArrayInputStream bin = new ByteArrayInputStream(bout.toByteArray());
495 <            ObjectInputStream in = new ObjectInputStream(new BufferedInputStream(bin));
496 <            NavigableSet r = (NavigableSet)in.readObject();
497 <            assertEquals(q.size(), r.size());
498 <            while (!q.isEmpty())
510 <                assertEquals(q.pollFirst(), r.pollFirst());
511 <        } catch (Exception e) {
512 <            e.printStackTrace();
513 <            unexpectedException();
514 <        }
488 >        ByteArrayOutputStream bout = new ByteArrayOutputStream(10000);
489 >        ObjectOutputStream out = new ObjectOutputStream(new BufferedOutputStream(bout));
490 >        out.writeObject(q);
491 >        out.close();
492 >
493 >        ByteArrayInputStream bin = new ByteArrayInputStream(bout.toByteArray());
494 >        ObjectInputStream in = new ObjectInputStream(new BufferedInputStream(bin));
495 >        NavigableSet r = (NavigableSet)in.readObject();
496 >        assertEquals(q.size(), r.size());
497 >        while (!q.isEmpty())
498 >            assertEquals(q.pollFirst(), r.pollFirst());
499      }
500  
501      /**
# Line 656 | Line 640 | public class ConcurrentSkipListSubSetTes
640              NavigableSet q = dset0();
641              q.add(null);
642              shouldThrow();
643 <        } catch (NullPointerException success) { }
643 >        } catch (NullPointerException success) {}
644      }
645  
646      /**
# Line 686 | Line 670 | public class ConcurrentSkipListSubSetTes
670              q.add(new Object());
671              q.add(new Object());
672              shouldThrow();
673 <        }
690 <        catch (ClassCastException success) {}
673 >        } catch (ClassCastException success) {}
674      }
675  
676  
# Line 699 | Line 682 | public class ConcurrentSkipListSubSetTes
682              NavigableSet q = dset0();
683              q.addAll(null);
684              shouldThrow();
685 <        }
703 <        catch (NullPointerException success) {}
685 >        } catch (NullPointerException success) {}
686      }
687      /**
688       * addAll of a collection with null elements throws NPE
# Line 711 | Line 693 | public class ConcurrentSkipListSubSetTes
693              Integer[] ints = new Integer[SIZE];
694              q.addAll(Arrays.asList(ints));
695              shouldThrow();
696 <        }
715 <        catch (NullPointerException success) {}
696 >        } catch (NullPointerException success) {}
697      }
698      /**
699       * addAll of a collection with any null elements throws NPE after
# 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 1012 | Line 989 | public class ConcurrentSkipListSubSetTes
989      /**
990       * A deserialized serialized set has same elements
991       */
992 <    public void testDescendingSerialization() {
992 >    public void testDescendingSerialization() throws Exception {
993          NavigableSet q = populatedSet(SIZE);
994 <        try {
995 <            ByteArrayOutputStream bout = new ByteArrayOutputStream(10000);
996 <            ObjectOutputStream out = new ObjectOutputStream(new BufferedOutputStream(bout));
997 <            out.writeObject(q);
998 <            out.close();
999 <
1000 <            ByteArrayInputStream bin = new ByteArrayInputStream(bout.toByteArray());
1001 <            ObjectInputStream in = new ObjectInputStream(new BufferedInputStream(bin));
1002 <            NavigableSet r = (NavigableSet)in.readObject();
1003 <            assertEquals(q.size(), r.size());
1004 <            while (!q.isEmpty())
1028 <                assertEquals(q.pollFirst(), r.pollFirst());
1029 <        } catch (Exception e) {
1030 <            e.printStackTrace();
1031 <            unexpectedException();
1032 <        }
994 >        ByteArrayOutputStream bout = new ByteArrayOutputStream(10000);
995 >        ObjectOutputStream out = new ObjectOutputStream(new BufferedOutputStream(bout));
996 >        out.writeObject(q);
997 >        out.close();
998 >
999 >        ByteArrayInputStream bin = new ByteArrayInputStream(bout.toByteArray());
1000 >        ObjectInputStream in = new ObjectInputStream(new BufferedInputStream(bin));
1001 >        NavigableSet r = (NavigableSet)in.readObject();
1002 >        assertEquals(q.size(), r.size());
1003 >        while (!q.isEmpty())
1004 >            assertEquals(q.pollFirst(), r.pollFirst());
1005      }
1006  
1007      /**

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines