--- jsr166/src/test/tck/ArrayListTest.java 2016/11/15 23:25:44 1.3 +++ jsr166/src/test/tck/ArrayListTest.java 2021/01/26 13:33:05 1.8 @@ -6,11 +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) { @@ -21,7 +20,7 @@ public class ArrayListTest extends JSR16 class Implementation implements CollectionImplementation { public Class klazz() { return ArrayList.class; } public List emptyCollection() { return new ArrayList(); } - public Object makeElement(int i) { return i; } + public Object makeElement(int i) { return JSR166TestCase.itemFor(i); } public boolean isConcurrent() { return false; } public boolean permitsNulls() { return true; } } @@ -30,13 +29,34 @@ public class ArrayListTest extends JSR16 return super.emptyCollection().subList(0, 0); } } - return atLeastJava9() - ? newTestSuite( - // ArrayListTest.class, + return newTestSuite( + ArrayListTest.class, CollectionTest.testSuite(new Implementation()), - CollectionTest.testSuite(new SubListImplementation())) - : newTestSuite( - CollectionTest.testSuite(new Implementation())); + CollectionTest.testSuite(new SubListImplementation())); + } + + /** + * A cloned list equals original + */ + public void testClone() throws Exception { + ArrayList x = new ArrayList<>(); + x.add(one); + x.add(two); + x.add(three); + @SuppressWarnings("unchecked") + ArrayList y = (ArrayList) x.clone(); + + assertNotSame(y, x); + mustEqual(x, y); + mustEqual(y, x); + mustEqual(x.size(), y.size()); + mustEqual(x.toString(), y.toString()); + assertTrue(Arrays.equals(x.toArray(), y.toArray())); + while (!x.isEmpty()) { + assertFalse(y.isEmpty()); + mustEqual(x.remove(0), y.remove(0)); + } + assertTrue(y.isEmpty()); } }