--- jsr166/src/test/tck/CopyOnWriteArraySetTest.java 2015/02/27 19:28:23 1.30 +++ jsr166/src/test/tck/CopyOnWriteArraySetTest.java 2015/02/27 19:41:24 1.31 @@ -31,7 +31,7 @@ public class CopyOnWriteArraySetTest ext assertTrue(a.isEmpty()); for (int i = 0; i < n; i++) a.add(i); - assertFalse(a.isEmpty()); + assertEquals(n == 0, a.isEmpty()); assertEquals(n, a.size()); return a; } @@ -67,10 +67,10 @@ public class CopyOnWriteArraySetTest ext } /** - * addAll adds each element from the given collection + * addAll adds each non-duplicate element from the given collection */ public void testAddAll() { - CopyOnWriteArraySet full = populatedSet(3); + Set full = populatedSet(3); assertTrue(full.addAll(Arrays.asList(three, four, five))); assertEquals(6, full.size()); assertFalse(full.addAll(Arrays.asList(three, four, five))); @@ -78,11 +78,10 @@ public class CopyOnWriteArraySetTest ext } /** - * addAll adds each element from the given collection that did not - * already exist in the set + * addAll adds each non-duplicate element from the given collection */ public void testAddAll2() { - CopyOnWriteArraySet full = populatedSet(3); + Set full = populatedSet(3); // "one" is duplicate and will not be added assertTrue(full.addAll(Arrays.asList(three, four, one))); assertEquals(5, full.size()); @@ -94,7 +93,7 @@ public class CopyOnWriteArraySetTest ext * add will not add the element if it already exists in the set */ public void testAdd2() { - CopyOnWriteArraySet full = populatedSet(3); + Set full = populatedSet(3); full.add(one); assertEquals(3, full.size()); } @@ -103,7 +102,7 @@ public class CopyOnWriteArraySetTest ext * add adds the element when it does not exist in the set */ public void testAdd3() { - CopyOnWriteArraySet full = populatedSet(3); + Set full = populatedSet(3); full.add(three); assertTrue(full.contains(three)); } @@ -112,16 +111,17 @@ public class CopyOnWriteArraySetTest ext * clear removes all elements from the set */ public void testClear() { - CopyOnWriteArraySet full = populatedSet(3); + Collection full = populatedSet(3); full.clear(); assertEquals(0, full.size()); + assertTrue(full.isEmpty()); } /** * contains returns true for added elements */ public void testContains() { - CopyOnWriteArraySet full = populatedSet(3); + Collection full = populatedSet(3); assertTrue(full.contains(one)); assertFalse(full.contains(five)); } @@ -148,7 +148,7 @@ public class CopyOnWriteArraySetTest ext * containsAll returns true for collections with subset of elements */ public void testContainsAll() { - CopyOnWriteArraySet full = populatedSet(3); + Collection full = populatedSet(3); assertTrue(full.containsAll(Arrays.asList())); assertTrue(full.containsAll(Arrays.asList(one))); assertTrue(full.containsAll(Arrays.asList(one, two))); @@ -160,10 +160,8 @@ public class CopyOnWriteArraySetTest ext * isEmpty is true when empty, else false */ public void testIsEmpty() { - CopyOnWriteArraySet empty = new CopyOnWriteArraySet(); - CopyOnWriteArraySet full = populatedSet(3); - assertTrue(empty.isEmpty()); - assertFalse(full.isEmpty()); + assertTrue(populatedSet(0).isEmpty()); + assertFalse(populatedSet(3).isEmpty()); } /** @@ -203,7 +201,7 @@ public class CopyOnWriteArraySetTest ext * iterator remove is unsupported */ public void testIteratorRemove() { - CopyOnWriteArraySet full = populatedSet(3); + Collection full = populatedSet(3); Iterator it = full.iterator(); it.next(); try { @@ -217,7 +215,7 @@ public class CopyOnWriteArraySetTest ext */ public void testToString() { assertEquals("[]", new CopyOnWriteArraySet().toString()); - CopyOnWriteArraySet full = populatedSet(3); + Collection full = populatedSet(3); String s = full.toString(); for (int i = 0; i < 3; ++i) assertTrue(s.contains(String.valueOf(i))); @@ -229,7 +227,7 @@ public class CopyOnWriteArraySetTest ext * removeAll removes all elements from the given collection */ public void testRemoveAll() { - CopyOnWriteArraySet full = populatedSet(3); + Set full = populatedSet(3); assertTrue(full.removeAll(Arrays.asList(one, two))); assertEquals(1, full.size()); assertFalse(full.removeAll(Arrays.asList(one, two))); @@ -240,7 +238,7 @@ public class CopyOnWriteArraySetTest ext * remove removes an element */ public void testRemove() { - CopyOnWriteArraySet full = populatedSet(3); + Collection full = populatedSet(3); full.remove(one); assertFalse(full.contains(one)); assertEquals(2, full.size()); @@ -250,8 +248,8 @@ public class CopyOnWriteArraySetTest ext * size returns the number of elements */ public void testSize() { - CopyOnWriteArraySet empty = new CopyOnWriteArraySet(); - CopyOnWriteArraySet full = populatedSet(3); + Collection empty = new CopyOnWriteArraySet(); + Collection full = populatedSet(3); assertEquals(3, full.size()); assertEquals(0, empty.size()); }