40
41 public class ArrayListTest extends JSR166TestCase {
42 public static void main(String[] args) {
43 main(suite(), args);
44 }
45
46 public static Test suite() {
47 class Implementation implements CollectionImplementation {
48 public Class<?> klazz() { return ArrayList.class; }
49 public List emptyCollection() { return new ArrayList(); }
50 public Object makeElement(int i) { return i; }
51 public boolean isConcurrent() { return false; }
52 public boolean permitsNulls() { return true; }
53 }
54 class SubListImplementation extends Implementation {
55 public List emptyCollection() {
56 return super.emptyCollection().subList(0, 0);
57 }
58 }
59 return newTestSuite(
60 // ArrayListTest.class,
61 CollectionTest.testSuite(new Implementation()),
62 CollectionTest.testSuite(new SubListImplementation()));
63 }
64
65 /**
66 * A cloned list equals original
67 */
68 public void testClone() throws Exception {
69 ArrayList<Integer> x = new ArrayList<>();
70 x.add(1);
71 x.add(2);
72 x.add(3);
73 ArrayList<Integer> y = (ArrayList<Integer>) x.clone();
74
75 assertNotSame(y, x);
76 assertEquals(x, y);
77 assertEquals(y, x);
78 assertEquals(x.size(), y.size());
79 assertEquals(x.toString(), y.toString());
80 assertTrue(Arrays.equals(x.toArray(), y.toArray()));
|
40
41 public class ArrayListTest extends JSR166TestCase {
42 public static void main(String[] args) {
43 main(suite(), args);
44 }
45
46 public static Test suite() {
47 class Implementation implements CollectionImplementation {
48 public Class<?> klazz() { return ArrayList.class; }
49 public List emptyCollection() { return new ArrayList(); }
50 public Object makeElement(int i) { return i; }
51 public boolean isConcurrent() { return false; }
52 public boolean permitsNulls() { return true; }
53 }
54 class SubListImplementation extends Implementation {
55 public List emptyCollection() {
56 return super.emptyCollection().subList(0, 0);
57 }
58 }
59 return newTestSuite(
60 ArrayListTest.class,
61 CollectionTest.testSuite(new Implementation()),
62 CollectionTest.testSuite(new SubListImplementation()));
63 }
64
65 /**
66 * A cloned list equals original
67 */
68 public void testClone() throws Exception {
69 ArrayList<Integer> x = new ArrayList<>();
70 x.add(1);
71 x.add(2);
72 x.add(3);
73 ArrayList<Integer> y = (ArrayList<Integer>) x.clone();
74
75 assertNotSame(y, x);
76 assertEquals(x, y);
77 assertEquals(y, x);
78 assertEquals(x.size(), y.size());
79 assertEquals(x.toString(), y.toString());
80 assertTrue(Arrays.equals(x.toArray(), y.toArray()));
|