ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/jsr166/jsr166/src/test/tck/ArrayListTest.java
Revision: 1.6
Committed: Fri Aug 4 03:43:44 2017 UTC (6 years, 9 months ago) by jsr166
Branch: MAIN
Changes since 1.5: +24 -0 lines
Log Message:
add testClone

File Contents

# User Rev Content
1 jsr166 1.1 /*
2     * Written by Doug Lea and Martin Buchholz with assistance from
3     * members of JCP JSR-166 Expert Group and released to the public
4     * domain, as explained at
5     * http://creativecommons.org/publicdomain/zero/1.0/
6     */
7    
8     import java.util.ArrayList;
9 jsr166 1.6 import java.util.Arrays;
10 jsr166 1.2 import java.util.List;
11 jsr166 1.1
12     import junit.framework.Test;
13    
14     public class ArrayListTest extends JSR166TestCase {
15     public static void main(String[] args) {
16     main(suite(), args);
17     }
18    
19     public static Test suite() {
20     class Implementation implements CollectionImplementation {
21     public Class<?> klazz() { return ArrayList.class; }
22 jsr166 1.2 public List emptyCollection() { return new ArrayList(); }
23 jsr166 1.1 public Object makeElement(int i) { return i; }
24     public boolean isConcurrent() { return false; }
25     public boolean permitsNulls() { return true; }
26     }
27 jsr166 1.2 class SubListImplementation extends Implementation {
28     public List emptyCollection() {
29     return super.emptyCollection().subList(0, 0);
30     }
31     }
32 jsr166 1.4 return newTestSuite(
33 jsr166 1.2 // ArrayListTest.class,
34     CollectionTest.testSuite(new Implementation()),
35 jsr166 1.4 CollectionTest.testSuite(new SubListImplementation()));
36 jsr166 1.1 }
37    
38 jsr166 1.6 /**
39     * A cloned list equals original
40     */
41     public void testClone() throws Exception {
42     ArrayList<Integer> x = new ArrayList<>();
43     x.add(1);
44     x.add(2);
45     x.add(3);
46     ArrayList<Integer> y = (ArrayList<Integer>) x.clone();
47    
48     assertNotSame(y, x);
49     assertEquals(x, y);
50     assertEquals(y, x);
51     assertEquals(x.size(), y.size());
52     assertEquals(x.toString(), y.toString());
53     assertTrue(Arrays.equals(x.toArray(), y.toArray()));
54     while (!x.isEmpty()) {
55     assertFalse(y.isEmpty());
56     assertEquals(x.remove(0), y.remove(0));
57     }
58     assertTrue(y.isEmpty());
59     }
60    
61 jsr166 1.1 }