--- jsr166/src/test/tck/CopyOnWriteArrayListTest.java 2015/02/27 19:28:23 1.33 +++ jsr166/src/test/tck/CopyOnWriteArrayListTest.java 2016/11/15 22:52:15 1.41 @@ -9,7 +9,6 @@ import java.util.ArrayList; import java.util.Arrays; import java.util.Collection; -import java.util.Collections; import java.util.Iterator; import java.util.LinkedList; import java.util.List; @@ -23,11 +22,26 @@ import junit.framework.TestSuite; public class CopyOnWriteArrayListTest extends JSR166TestCase { public static void main(String[] args) { - junit.textui.TestRunner.run(suite()); + main(suite(), args); } public static Test suite() { - return new TestSuite(CopyOnWriteArrayListTest.class); + class Implementation implements CollectionImplementation { + public Class klazz() { return ArrayList.class; } + public List emptyCollection() { return new CopyOnWriteArrayList(); } + public Object makeElement(int i) { return i; } + public boolean isConcurrent() { return true; } + public boolean permitsNulls() { return true; } + } + class SubListImplementation extends Implementation { + public List emptyCollection() { + return super.emptyCollection().subList(0, 0); + } + } + return newTestSuite( + CopyOnWriteArrayListTest.class, + CollectionTest.testSuite(new Implementation()), + CollectionTest.testSuite(new SubListImplementation())); } static CopyOnWriteArrayList populatedArray(int n) { @@ -63,7 +77,7 @@ public class CopyOnWriteArrayListTest ex */ public void testConstructor2() { Integer[] ints = new Integer[SIZE]; - for (int i = 0; i < SIZE-1; ++i) + for (int i = 0; i < SIZE - 1; ++i) ints[i] = new Integer(i); CopyOnWriteArrayList a = new CopyOnWriteArrayList(ints); for (int i = 0; i < SIZE; ++i) @@ -75,7 +89,7 @@ public class CopyOnWriteArrayListTest ex */ public void testConstructor3() { Integer[] ints = new Integer[SIZE]; - for (int i = 0; i < SIZE-1; ++i) + for (int i = 0; i < SIZE - 1; ++i) ints[i] = new Integer(i); CopyOnWriteArrayList a = new CopyOnWriteArrayList(Arrays.asList(ints)); for (int i = 0; i < SIZE; ++i) @@ -177,18 +191,26 @@ public class CopyOnWriteArrayListTest ex CopyOnWriteArrayList b = populatedArray(3); assertTrue(a.equals(b)); assertTrue(b.equals(a)); + assertTrue(a.containsAll(b)); + assertTrue(b.containsAll(a)); assertEquals(a.hashCode(), b.hashCode()); a.add(m1); assertFalse(a.equals(b)); assertFalse(b.equals(a)); + assertTrue(a.containsAll(b)); + assertFalse(b.containsAll(a)); b.add(m1); assertTrue(a.equals(b)); assertTrue(b.equals(a)); + assertTrue(a.containsAll(b)); + assertTrue(b.containsAll(a)); assertEquals(a.hashCode(), b.hashCode()); + + assertFalse(a.equals(null)); } /** - * containsAll returns true for collection with subset of elements + * containsAll returns true for collections with subset of elements */ public void testContainsAll() { CopyOnWriteArrayList full = populatedArray(3); @@ -197,6 +219,11 @@ public class CopyOnWriteArrayListTest ex assertTrue(full.containsAll(Arrays.asList(one, two))); assertFalse(full.containsAll(Arrays.asList(one, two, six))); assertFalse(full.containsAll(Arrays.asList(six))); + + try { + full.containsAll(null); + shouldThrow(); + } catch (NullPointerException success) {} } /** @@ -251,7 +278,7 @@ public class CopyOnWriteArrayListTest ex Integer[] elements = new Integer[SIZE]; for (int i = 0; i < SIZE; i++) elements[i] = i; - Collections.shuffle(Arrays.asList(elements)); + shuffle(elements); Collection full = populatedArray(elements); Iterator it = full.iterator(); @@ -338,7 +365,7 @@ public class CopyOnWriteArrayListTest ex ListIterator i = full.listIterator(1); int j; for (j = 0; i.hasNext(); j++) - assertEquals(j+1, i.next()); + assertEquals(j + 1, i.next()); assertEquals(2, j); } @@ -419,7 +446,7 @@ public class CopyOnWriteArrayListTest ex Integer[] elements = new Integer[SIZE]; for (int i = 0; i < SIZE; i++) elements[i] = i; - Collections.shuffle(Arrays.asList(elements)); + shuffle(elements); Collection full = populatedArray(elements); assertTrue(Arrays.equals(elements, full.toArray())); @@ -437,7 +464,7 @@ public class CopyOnWriteArrayListTest ex a = new Integer[0]; assertSame(a, empty.toArray(a)); - a = new Integer[SIZE/2]; + a = new Integer[SIZE / 2]; Arrays.fill(a, 42); assertSame(a, empty.toArray(a)); assertNull(a[0]); @@ -447,7 +474,7 @@ public class CopyOnWriteArrayListTest ex Integer[] elements = new Integer[SIZE]; for (int i = 0; i < SIZE; i++) elements[i] = i; - Collections.shuffle(Arrays.asList(elements)); + shuffle(elements); Collection full = populatedArray(elements); Arrays.fill(a, 42); @@ -461,7 +488,7 @@ public class CopyOnWriteArrayListTest ex assertSame(a, full.toArray(a)); assertTrue(Arrays.equals(elements, a)); - a = new Integer[2*SIZE]; + a = new Integer[2 * SIZE]; Arrays.fill(a, 42); assertSame(a, full.toArray(a)); assertTrue(Arrays.equals(elements, Arrays.copyOf(a, SIZE)));