--- jsr166/src/test/tck/ConcurrentSkipListSubSetTest.java 2015/01/17 22:55:06 1.29 +++ jsr166/src/test/tck/ConcurrentSkipListSubSetTest.java 2017/08/04 03:30:21 1.37 @@ -16,7 +16,7 @@ import junit.framework.TestSuite; public class ConcurrentSkipListSubSetTest extends JSR166TestCase { public static void main(String[] args) { - junit.textui.TestRunner.run(suite()); + main(suite(), args); } public static Test suite() { return new TestSuite(ConcurrentSkipListSubSetTest.class); @@ -30,14 +30,14 @@ public class ConcurrentSkipListSubSetTes /** * Returns a new set of given size containing consecutive - * Integers 0 ... n. + * Integers 0 ... n - 1. */ - private NavigableSet populatedSet(int n) { + private static NavigableSet populatedSet(int n) { ConcurrentSkipListSet q = new ConcurrentSkipListSet(); assertTrue(q.isEmpty()); - for (int i = n-1; i >= 0; i -= 2) + for (int i = n - 1; i >= 0; i -= 2) assertTrue(q.add(new Integer(i))); for (int i = (n & 1); i < n; i += 2) assertTrue(q.add(new Integer(i))); @@ -52,7 +52,7 @@ public class ConcurrentSkipListSubSetTes /** * Returns a new set of first 5 ints. */ - private NavigableSet set5() { + private static NavigableSet set5() { ConcurrentSkipListSet q = new ConcurrentSkipListSet(); assertTrue(q.isEmpty()); q.add(one); @@ -70,7 +70,7 @@ public class ConcurrentSkipListSubSetTes /** * Returns a new set of first 5 negative ints. */ - private NavigableSet dset5() { + private static NavigableSet dset5() { ConcurrentSkipListSet q = new ConcurrentSkipListSet(); assertTrue(q.isEmpty()); q.add(m1); @@ -122,7 +122,7 @@ public class ConcurrentSkipListSubSetTes public void testSize() { NavigableSet q = populatedSet(SIZE); for (int i = 0; i < SIZE; ++i) { - assertEquals(SIZE-i, q.size()); + assertEquals(SIZE - i, q.size()); q.pollFirst(); } for (int i = 0; i < SIZE; ++i) { @@ -135,8 +135,8 @@ public class ConcurrentSkipListSubSetTes * add(null) throws NPE */ public void testAddNull() { + NavigableSet q = set0(); try { - NavigableSet q = set0(); q.add(null); shouldThrow(); } catch (NullPointerException success) {} @@ -163,9 +163,8 @@ public class ConcurrentSkipListSubSetTes * Add of non-Comparable throws CCE */ public void testAddNonComparable() { + NavigableSet q = set0(); try { - NavigableSet q = set0(); - q.add(new Object()); q.add(new Object()); q.add(new Object()); shouldThrow(); @@ -176,8 +175,8 @@ public class ConcurrentSkipListSubSetTes * addAll(null) throws NPE */ public void testAddAll1() { + NavigableSet q = set0(); try { - NavigableSet q = set0(); q.addAll(null); shouldThrow(); } catch (NullPointerException success) {} @@ -187,9 +186,9 @@ public class ConcurrentSkipListSubSetTes * addAll of a collection with null elements throws NPE */ public void testAddAll2() { + NavigableSet q = set0(); + Integer[] ints = new Integer[SIZE]; try { - NavigableSet q = set0(); - Integer[] ints = new Integer[SIZE]; q.addAll(Arrays.asList(ints)); shouldThrow(); } catch (NullPointerException success) {} @@ -200,11 +199,11 @@ public class ConcurrentSkipListSubSetTes * possibly adding some elements */ public void testAddAll3() { + NavigableSet q = set0(); + Integer[] ints = new Integer[SIZE]; + for (int i = 0; i < SIZE - 1; ++i) + ints[i] = new Integer(i + SIZE); try { - NavigableSet q = set0(); - Integer[] ints = new Integer[SIZE]; - for (int i = 0; i < SIZE-1; ++i) - ints[i] = new Integer(i+SIZE); q.addAll(Arrays.asList(ints)); shouldThrow(); } catch (NullPointerException success) {} @@ -217,7 +216,7 @@ public class ConcurrentSkipListSubSetTes Integer[] empty = new Integer[0]; Integer[] ints = new Integer[SIZE]; for (int i = 0; i < SIZE; ++i) - ints[i] = new Integer(SIZE-1- i); + ints[i] = new Integer(SIZE - 1 - i); NavigableSet q = set0(); assertFalse(q.addAll(Arrays.asList(empty))); assertTrue(q.addAll(Arrays.asList(ints))); @@ -245,14 +244,14 @@ public class ConcurrentSkipListSubSetTes assertTrue(q.contains(i)); assertTrue(q.remove(i)); assertFalse(q.contains(i)); - assertTrue(q.contains(i-1)); + assertTrue(q.contains(i - 1)); } for (int i = 0; i < SIZE; i += 2) { assertTrue(q.contains(i)); assertTrue(q.remove(i)); assertFalse(q.contains(i)); - assertFalse(q.remove(i+1)); - assertFalse(q.contains(i+1)); + assertFalse(q.remove(i + 1)); + assertFalse(q.contains(i + 1)); } assertTrue(q.isEmpty()); } @@ -311,7 +310,7 @@ public class ConcurrentSkipListSubSetTes assertTrue(changed); assertTrue(q.containsAll(p)); - assertEquals(SIZE-i, q.size()); + assertEquals(SIZE - i, q.size()); p.pollFirst(); } } @@ -324,7 +323,7 @@ public class ConcurrentSkipListSubSetTes NavigableSet q = populatedSet(SIZE); NavigableSet p = populatedSet(i); assertTrue(q.removeAll(p)); - assertEquals(SIZE-i, q.size()); + assertEquals(SIZE - i, q.size()); for (int j = 0; j < i; ++j) { Integer x = (Integer)(p.pollFirst()); assertFalse(q.contains(x)); @@ -477,7 +476,7 @@ public class ConcurrentSkipListSubSetTes } /** - * A deserialized serialized set has same elements + * A deserialized/reserialized set equals original */ public void testSerialization() throws Exception { NavigableSet x = populatedSet(SIZE); @@ -619,7 +618,7 @@ public class ConcurrentSkipListSubSetTes public void testDescendingSize() { NavigableSet q = populatedSet(SIZE); for (int i = 0; i < SIZE; ++i) { - assertEquals(SIZE-i, q.size()); + assertEquals(SIZE - i, q.size()); q.pollFirst(); } for (int i = 0; i < SIZE; ++i) { @@ -632,8 +631,8 @@ public class ConcurrentSkipListSubSetTes * add(null) throws NPE */ public void testDescendingAddNull() { + NavigableSet q = dset0(); try { - NavigableSet q = dset0(); q.add(null); shouldThrow(); } catch (NullPointerException success) {} @@ -660,9 +659,8 @@ public class ConcurrentSkipListSubSetTes * Add of non-Comparable throws CCE */ public void testDescendingAddNonComparable() { + NavigableSet q = dset0(); try { - NavigableSet q = dset0(); - q.add(new Object()); q.add(new Object()); q.add(new Object()); shouldThrow(); @@ -673,8 +671,8 @@ public class ConcurrentSkipListSubSetTes * addAll(null) throws NPE */ public void testDescendingAddAll1() { + NavigableSet q = dset0(); try { - NavigableSet q = dset0(); q.addAll(null); shouldThrow(); } catch (NullPointerException success) {} @@ -684,9 +682,9 @@ public class ConcurrentSkipListSubSetTes * addAll of a collection with null elements throws NPE */ public void testDescendingAddAll2() { + NavigableSet q = dset0(); + Integer[] ints = new Integer[SIZE]; try { - NavigableSet q = dset0(); - Integer[] ints = new Integer[SIZE]; q.addAll(Arrays.asList(ints)); shouldThrow(); } catch (NullPointerException success) {} @@ -697,11 +695,11 @@ public class ConcurrentSkipListSubSetTes * possibly adding some elements */ public void testDescendingAddAll3() { + NavigableSet q = dset0(); + Integer[] ints = new Integer[SIZE]; + for (int i = 0; i < SIZE - 1; ++i) + ints[i] = new Integer(i + SIZE); try { - NavigableSet q = dset0(); - Integer[] ints = new Integer[SIZE]; - for (int i = 0; i < SIZE-1; ++i) - ints[i] = new Integer(i+SIZE); q.addAll(Arrays.asList(ints)); shouldThrow(); } catch (NullPointerException success) {} @@ -714,7 +712,7 @@ public class ConcurrentSkipListSubSetTes Integer[] empty = new Integer[0]; Integer[] ints = new Integer[SIZE]; for (int i = 0; i < SIZE; ++i) - ints[i] = new Integer(SIZE-1- i); + ints[i] = new Integer(SIZE - 1 - i); NavigableSet q = dset0(); assertFalse(q.addAll(Arrays.asList(empty))); assertTrue(q.addAll(Arrays.asList(ints))); @@ -743,7 +741,7 @@ public class ConcurrentSkipListSubSetTes } for (int i = 0; i < SIZE; i += 2 ) { assertTrue(q.remove(new Integer(i))); - assertFalse(q.remove(new Integer(i+1))); + assertFalse(q.remove(new Integer(i + 1))); } assertTrue(q.isEmpty()); } @@ -802,7 +800,7 @@ public class ConcurrentSkipListSubSetTes assertTrue(changed); assertTrue(q.containsAll(p)); - assertEquals(SIZE-i, q.size()); + assertEquals(SIZE - i, q.size()); p.pollFirst(); } } @@ -815,7 +813,7 @@ public class ConcurrentSkipListSubSetTes NavigableSet q = populatedSet(SIZE); NavigableSet p = populatedSet(i); assertTrue(q.removeAll(p)); - assertEquals(SIZE-i, q.size()); + assertEquals(SIZE - i, q.size()); for (int j = 0; j < i; ++j) { Integer x = (Integer)(p.pollFirst()); assertFalse(q.contains(x)); @@ -977,7 +975,7 @@ public class ConcurrentSkipListSubSetTes } /** - * A deserialized serialized set has same elements + * A deserialized/reserialized set equals original */ public void testDescendingSerialization() throws Exception { NavigableSet x = dset5();