--- jsr166/src/test/tck/ArrayListTest.java 2016/10/17 17:52:30 1.1 +++ jsr166/src/test/tck/ArrayListTest.java 2017/08/04 03:43:44 1.6 @@ -6,10 +6,10 @@ */ import java.util.ArrayList; -import java.util.Collection; +import java.util.Arrays; +import java.util.List; import junit.framework.Test; -import junit.framework.TestSuite; public class ArrayListTest extends JSR166TestCase { public static void main(String[] args) { @@ -19,13 +19,43 @@ public class ArrayListTest extends JSR16 public static Test suite() { class Implementation implements CollectionImplementation { public Class klazz() { return ArrayList.class; } - public Collection emptyCollection() { return new ArrayList(); } + public List emptyCollection() { return new ArrayList(); } public Object makeElement(int i) { return i; } public boolean isConcurrent() { return false; } public boolean permitsNulls() { return true; } } - return newTestSuite(// ArrayListTest.class, - CollectionTest.testSuite(new Implementation())); + class SubListImplementation extends Implementation { + public List emptyCollection() { + return super.emptyCollection().subList(0, 0); + } + } + return newTestSuite( + // ArrayListTest.class, + CollectionTest.testSuite(new Implementation()), + CollectionTest.testSuite(new SubListImplementation())); + } + + /** + * A cloned list equals original + */ + public void testClone() throws Exception { + ArrayList x = new ArrayList<>(); + x.add(1); + x.add(2); + x.add(3); + ArrayList y = (ArrayList) x.clone(); + + assertNotSame(y, x); + assertEquals(x, y); + assertEquals(y, x); + assertEquals(x.size(), y.size()); + assertEquals(x.toString(), y.toString()); + assertTrue(Arrays.equals(x.toArray(), y.toArray())); + while (!x.isEmpty()) { + assertFalse(y.isEmpty()); + assertEquals(x.remove(0), y.remove(0)); + } + assertTrue(y.isEmpty()); } }