--- jsr166/src/test/tck/ConcurrentSkipListSetTest.java 2013/04/02 22:18:25 1.29 +++ jsr166/src/test/tck/ConcurrentSkipListSetTest.java 2015/04/25 04:55:30 1.38 @@ -4,7 +4,6 @@ * http://creativecommons.org/publicdomain/zero/1.0/ */ -import junit.framework.*; import java.util.Arrays; import java.util.BitSet; import java.util.Collection; @@ -17,9 +16,12 @@ import java.util.Set; import java.util.SortedSet; import java.util.concurrent.ConcurrentSkipListSet; +import junit.framework.Test; +import junit.framework.TestSuite; + public class ConcurrentSkipListSetTest extends JSR166TestCase { public static void main(String[] args) { - junit.textui.TestRunner.run(suite()); + main(suite(), args); } public static Test suite() { return new TestSuite(ConcurrentSkipListSetTest.class); @@ -39,9 +41,9 @@ public class ConcurrentSkipListSetTest e 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) + for (int i = (n & 1); i < n; i += 2) assertTrue(q.add(new Integer(i))); assertFalse(q.isEmpty()); assertEquals(n, q.size()); @@ -75,7 +77,7 @@ public class ConcurrentSkipListSetTest e */ public void testConstructor3() { try { - ConcurrentSkipListSet q = new ConcurrentSkipListSet((Collection)null); + new ConcurrentSkipListSet((Collection)null); shouldThrow(); } catch (NullPointerException success) {} } @@ -86,7 +88,7 @@ public class ConcurrentSkipListSetTest e public void testConstructor4() { try { Integer[] ints = new Integer[SIZE]; - ConcurrentSkipListSet q = new ConcurrentSkipListSet(Arrays.asList(ints)); + new ConcurrentSkipListSet(Arrays.asList(ints)); shouldThrow(); } catch (NullPointerException success) {} } @@ -99,7 +101,7 @@ public class ConcurrentSkipListSetTest e Integer[] ints = new Integer[SIZE]; for (int i = 0; i < SIZE-1; ++i) ints[i] = new Integer(i); - ConcurrentSkipListSet q = new ConcurrentSkipListSet(Arrays.asList(ints)); + new ConcurrentSkipListSet(Arrays.asList(ints)); shouldThrow(); } catch (NullPointerException success) {} } @@ -164,8 +166,8 @@ public class ConcurrentSkipListSetTest e * add(null) throws NPE */ public void testAddNull() { + ConcurrentSkipListSet q = new ConcurrentSkipListSet(); try { - ConcurrentSkipListSet q = new ConcurrentSkipListSet(); q.add(null); shouldThrow(); } catch (NullPointerException success) {} @@ -193,9 +195,8 @@ public class ConcurrentSkipListSetTest e * Add of non-Comparable throws CCE */ public void testAddNonComparable() { + ConcurrentSkipListSet q = new ConcurrentSkipListSet(); try { - ConcurrentSkipListSet q = new ConcurrentSkipListSet(); - q.add(new Object()); q.add(new Object()); q.add(new Object()); shouldThrow(); @@ -206,8 +207,8 @@ public class ConcurrentSkipListSetTest e * addAll(null) throws NPE */ public void testAddAll1() { + ConcurrentSkipListSet q = new ConcurrentSkipListSet(); try { - ConcurrentSkipListSet q = new ConcurrentSkipListSet(); q.addAll(null); shouldThrow(); } catch (NullPointerException success) {} @@ -217,9 +218,9 @@ public class ConcurrentSkipListSetTest e * addAll of a collection with null elements throws NPE */ public void testAddAll2() { + ConcurrentSkipListSet q = new ConcurrentSkipListSet(); + Integer[] ints = new Integer[SIZE]; try { - ConcurrentSkipListSet q = new ConcurrentSkipListSet(); - Integer[] ints = new Integer[SIZE]; q.addAll(Arrays.asList(ints)); shouldThrow(); } catch (NullPointerException success) {} @@ -230,11 +231,11 @@ public class ConcurrentSkipListSetTest e * possibly adding some elements */ public void testAddAll3() { + ConcurrentSkipListSet q = new ConcurrentSkipListSet(); + Integer[] ints = new Integer[SIZE]; + for (int i = 0; i < SIZE-1; ++i) + ints[i] = new Integer(i); try { - ConcurrentSkipListSet q = new ConcurrentSkipListSet(); - Integer[] ints = new Integer[SIZE]; - for (int i = 0; i < SIZE-1; ++i) - ints[i] = new Integer(i); q.addAll(Arrays.asList(ints)); shouldThrow(); } catch (NullPointerException success) {} @@ -282,13 +283,13 @@ public class ConcurrentSkipListSetTest e */ public void testRemoveElement() { ConcurrentSkipListSet q = populatedSet(SIZE); - for (int i = 1; i < SIZE; i+=2) { + for (int i = 1; i < SIZE; i += 2) { assertTrue(q.contains(i)); assertTrue(q.remove(i)); assertFalse(q.contains(i)); assertTrue(q.contains(i-1)); } - for (int i = 0; i < SIZE; i+=2) { + for (int i = 0; i < SIZE; i += 2) { assertTrue(q.contains(i)); assertTrue(q.remove(i)); assertFalse(q.contains(i)); @@ -367,8 +368,8 @@ public class ConcurrentSkipListSetTest e assertTrue(q.removeAll(p)); 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)); } } } @@ -471,27 +472,21 @@ public class ConcurrentSkipListSetTest e */ public void testIterator() { ConcurrentSkipListSet 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() { - ConcurrentSkipListSet q = new ConcurrentSkipListSet(); - int i = 0; - Iterator it = q.iterator(); - while (it.hasNext()) { - assertTrue(q.contains(it.next())); - ++i; - } - assertEquals(0, i); + NavigableSet s = new ConcurrentSkipListSet(); + assertIteratorExhausted(s.iterator()); + assertIteratorExhausted(s.descendingSet().iterator()); } /** @@ -531,7 +526,7 @@ public class ConcurrentSkipListSetTest e NavigableSet x = populatedSet(SIZE); NavigableSet y = serialClone(x); - assertTrue(x != y); + assertNotSame(x, y); assertEquals(x.size(), y.size()); assertEquals(x, y); assertEquals(y, x); @@ -730,7 +725,7 @@ public class ConcurrentSkipListSetTest e // Add entries till we're back to original size while (set.size() < size) { int element = min + rnd.nextInt(rangeSize); - assertTrue(element >= min && element<= max); + assertTrue(element >= min && element <= max); put(set, element, bs); } } @@ -756,7 +751,7 @@ public class ConcurrentSkipListSetTest e // Add entries till we're back to original size while (set.size() < size) { int element = min - 5 + rnd.nextInt(rangeSize + 10); - if (element >= min && element<= max) { + if (element >= min && element <= max) { put(set, element, bs); } else { try {