--- jsr166/src/test/tck/ConcurrentSkipListSubSetTest.java 2009/11/21 10:25:05 1.9 +++ jsr166/src/test/tck/ConcurrentSkipListSubSetTest.java 2010/11/04 01:04:54 1.15 @@ -11,7 +11,7 @@ import java.io.*; public class ConcurrentSkipListSubSetTest extends JSR166TestCase { public static void main(String[] args) { - junit.textui.TestRunner.run (suite()); + junit.textui.TestRunner.run(suite()); } public static Test suite() { return new TestSuite(ConcurrentSkipListSubSetTest.class); @@ -19,11 +19,7 @@ public class ConcurrentSkipListSubSetTes static class MyReverseComparator implements Comparator { public int compare(Object x, Object y) { - int i = ((Integer)x).intValue(); - int j = ((Integer)y).intValue(); - if (i < j) return 1; - if (i > j) return -1; - return 0; + return ((Comparable)y).compareTo(x); } } @@ -182,6 +178,7 @@ public class ConcurrentSkipListSubSetTes shouldThrow(); } catch (NullPointerException success) {} } + /** * addAll of a collection with null elements throws NPE */ @@ -193,6 +190,7 @@ public class ConcurrentSkipListSubSetTes shouldThrow(); } catch (NullPointerException success) {} } + /** * addAll of a collection with any null elements throws NPE after * possibly adding some elements @@ -212,18 +210,15 @@ public class ConcurrentSkipListSubSetTes * Set contains all elements of successful addAll */ public void testAddAll5() { - try { - Integer[] empty = new Integer[0]; - Integer[] ints = new Integer[SIZE]; - for (int i = 0; i < SIZE; ++i) - ints[i] = new Integer(SIZE-1- i); - NavigableSet q = set0(); - assertFalse(q.addAll(Arrays.asList(empty))); - assertTrue(q.addAll(Arrays.asList(ints))); - for (int i = 0; i < SIZE; ++i) - assertEquals(new Integer(i), q.pollFirst()); - } - finally {} + Integer[] empty = new Integer[0]; + Integer[] ints = new Integer[SIZE]; + for (int i = 0; i < SIZE; ++i) + ints[i] = new Integer(SIZE-1- i); + NavigableSet q = set0(); + assertFalse(q.addAll(Arrays.asList(empty))); + assertTrue(q.addAll(Arrays.asList(ints))); + for (int i = 0; i < SIZE; ++i) + assertEquals(new Integer(i), q.pollFirst()); } /** @@ -232,7 +227,7 @@ public class ConcurrentSkipListSubSetTes public void testPoll() { NavigableSet q = populatedSet(SIZE); for (int i = 0; i < SIZE; ++i) { - assertEquals(i, ((Integer)q.pollFirst()).intValue()); + assertEquals(i, q.pollFirst()); } assertNull(q.pollFirst()); } @@ -345,7 +340,6 @@ public class ConcurrentSkipListSubSetTes Object e4 = q.lower(zero); assertNull(e4); - } /** @@ -364,7 +358,6 @@ public class ConcurrentSkipListSubSetTes Object e4 = q.higher(six); assertNull(e4); - } /** @@ -383,7 +376,6 @@ public class ConcurrentSkipListSubSetTes Object e4 = q.floor(zero); assertNull(e4); - } /** @@ -402,30 +394,27 @@ public class ConcurrentSkipListSubSetTes Object e4 = q.ceiling(six); assertNull(e4); - } /** - * toArray contains all elements + * toArray contains all elements in sorted order */ public void testToArray() { NavigableSet q = populatedSet(SIZE); Object[] o = q.toArray(); - Arrays.sort(o); for (int i = 0; i < o.length; i++) - assertEquals(o[i], q.pollFirst()); + assertSame(o[i], q.pollFirst()); } /** - * toArray(a) contains all elements + * toArray(a) contains all elements in sorted order */ public void testToArray2() { NavigableSet q = populatedSet(SIZE); Integer[] ints = new Integer[SIZE]; - ints = (Integer[])q.toArray(ints); - Arrays.sort(ints); + assertSame(ints, q.toArray(ints)); for (int i = 0; i < ints.length; i++) - assertEquals(ints[i], q.pollFirst()); + assertSame(ints[i], q.pollFirst()); } /** @@ -459,7 +448,7 @@ public class ConcurrentSkipListSubSetTes /** * iterator.remove removes current element */ - public void testIteratorRemove () { + public void testIteratorRemove() { final NavigableSet q = set0(); q.add(new Integer(2)); q.add(new Integer(1)); @@ -691,6 +680,7 @@ public class ConcurrentSkipListSubSetTes shouldThrow(); } catch (NullPointerException success) {} } + /** * addAll of a collection with null elements throws NPE */ @@ -702,6 +692,7 @@ public class ConcurrentSkipListSubSetTes shouldThrow(); } catch (NullPointerException success) {} } + /** * addAll of a collection with any null elements throws NPE after * possibly adding some elements @@ -721,18 +712,15 @@ public class ConcurrentSkipListSubSetTes * Set contains all elements of successful addAll */ public void testDescendingAddAll5() { - try { - Integer[] empty = new Integer[0]; - Integer[] ints = new Integer[SIZE]; - for (int i = 0; i < SIZE; ++i) - ints[i] = new Integer(SIZE-1- i); - NavigableSet q = dset0(); - assertFalse(q.addAll(Arrays.asList(empty))); - assertTrue(q.addAll(Arrays.asList(ints))); - for (int i = 0; i < SIZE; ++i) - assertEquals(new Integer(i), q.pollFirst()); - } - finally {} + Integer[] empty = new Integer[0]; + Integer[] ints = new Integer[SIZE]; + for (int i = 0; i < SIZE; ++i) + ints[i] = new Integer(SIZE-1- i); + NavigableSet q = dset0(); + assertFalse(q.addAll(Arrays.asList(empty))); + assertTrue(q.addAll(Arrays.asList(ints))); + for (int i = 0; i < SIZE; ++i) + assertEquals(new Integer(i), q.pollFirst()); } /** @@ -741,7 +729,7 @@ public class ConcurrentSkipListSubSetTes public void testDescendingPoll() { NavigableSet q = populatedSet(SIZE); for (int i = 0; i < SIZE; ++i) { - assertEquals(i, ((Integer)q.pollFirst()).intValue()); + assertEquals(i, q.pollFirst()); } assertNull(q.pollFirst()); } @@ -854,7 +842,6 @@ public class ConcurrentSkipListSubSetTes Object e4 = q.lower(zero); assertNull(e4); - } /** @@ -873,7 +860,6 @@ public class ConcurrentSkipListSubSetTes Object e4 = q.higher(m6); assertNull(e4); - } /** @@ -892,7 +878,6 @@ public class ConcurrentSkipListSubSetTes Object e4 = q.floor(zero); assertNull(e4); - } /** @@ -911,7 +896,6 @@ public class ConcurrentSkipListSubSetTes Object e4 = q.ceiling(m6); assertNull(e4); - } /** @@ -931,7 +915,7 @@ public class ConcurrentSkipListSubSetTes public void testDescendingToArray2() { NavigableSet q = populatedSet(SIZE); Integer[] ints = new Integer[SIZE]; - ints = (Integer[])q.toArray(ints); + assertSame(ints, q.toArray(ints)); Arrays.sort(ints); for (int i = 0; i < ints.length; i++) assertEquals(ints[i], q.pollFirst()); @@ -968,7 +952,7 @@ public class ConcurrentSkipListSubSetTes /** * iterator.remove removes current element */ - public void testDescendingIteratorRemove () { + public void testDescendingIteratorRemove() { final NavigableSet q = dset0(); q.add(new Integer(2)); q.add(new Integer(1));