--- jsr166/src/test/tck/ConcurrentSkipListSubSetTest.java 2014/12/31 20:09:08 1.27 +++ jsr166/src/test/tck/ConcurrentSkipListSubSetTest.java 2017/03/11 18:20:46 1.36 @@ -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,10 +323,10 @@ 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 I = (Integer)(p.pollFirst()); - assertFalse(q.contains(I)); + Integer x = (Integer)(p.pollFirst()); + assertFalse(q.contains(x)); } } } @@ -431,27 +430,19 @@ public class ConcurrentSkipListSubSetTes */ public void testIterator() { NavigableSet q = populatedSet(SIZE); - int i = 0; Iterator it = q.iterator(); - while (it.hasNext()) { + int i; + for (i = 0; it.hasNext(); i++) assertTrue(q.contains(it.next())); - ++i; - } assertEquals(i, SIZE); + assertIteratorExhausted(it); } /** * iterator of empty set has no elements */ public void testEmptyIterator() { - NavigableSet q = set0(); - int i = 0; - Iterator it = q.iterator(); - while (it.hasNext()) { - assertTrue(q.contains(it.next())); - ++i; - } - assertEquals(0, i); + assertIteratorExhausted(set0().iterator()); } /** @@ -627,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) { @@ -640,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) {} @@ -668,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(); @@ -681,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) {} @@ -692,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) {} @@ -705,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) {} @@ -722,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))); @@ -751,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()); } @@ -810,7 +800,7 @@ public class ConcurrentSkipListSubSetTes assertTrue(changed); assertTrue(q.containsAll(p)); - assertEquals(SIZE-i, q.size()); + assertEquals(SIZE - i, q.size()); p.pollFirst(); } } @@ -823,10 +813,10 @@ 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 I = (Integer)(p.pollFirst()); - assertFalse(q.contains(I)); + Integer x = (Integer)(p.pollFirst()); + assertFalse(q.contains(x)); } } }