--- jsr166/src/test/tck/ConcurrentSkipListSetTest.java 2011/11/26 05:42:14 1.25 +++ jsr166/src/test/tck/ConcurrentSkipListSetTest.java 2014/12/31 20:09:08 1.32 @@ -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,6 +16,9 @@ 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()); @@ -32,16 +34,16 @@ public class ConcurrentSkipListSetTest e } /** - * Create a set of given size containing consecutive + * Returns a new set of given size containing consecutive * Integers 0 ... n. */ private ConcurrentSkipListSet 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) + for (int i = (n & 1); i < n; i += 2) assertTrue(q.add(new Integer(i))); assertFalse(q.isEmpty()); assertEquals(n, q.size()); @@ -49,7 +51,7 @@ public class ConcurrentSkipListSetTest e } /** - * Create set of first 5 ints + * Returns a new set of first 5 ints. */ private ConcurrentSkipListSet set5() { ConcurrentSkipListSet q = new ConcurrentSkipListSet(); @@ -282,13 +284,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)); @@ -461,8 +463,7 @@ public class ConcurrentSkipListSetTest e public void testToArray2() { ConcurrentSkipListSet q = populatedSet(SIZE); Integer[] ints = new Integer[SIZE]; - Integer[] array = q.toArray(ints); - assertSame(ints, array); + assertSame(ints, q.toArray(ints)); for (int i = 0; i < ints.length; i++) assertSame(ints[i], q.pollFirst()); } @@ -532,7 +533,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); @@ -686,6 +687,17 @@ public class ConcurrentSkipListSetTest e 0, setSize - 1, true, bs); } + /** + * addAll is idempotent + */ + public void testAddAll_idempotent() throws Exception { + Set x = populatedSet(SIZE); + Set y = new ConcurrentSkipListSet(x); + y.addAll(x); + assertEquals(x, y); + assertEquals(y, x); + } + static NavigableSet newSet(Class cl) throws Exception { NavigableSet result = (NavigableSet) cl.newInstance(); assertEquals(0, result.size());