6 |
|
*/ |
7 |
|
|
8 |
|
import java.util.ArrayList; |
9 |
< |
import java.util.Collection; |
9 |
> |
import java.util.Arrays; |
10 |
|
import java.util.List; |
11 |
|
|
12 |
|
import junit.framework.Test; |
13 |
– |
import junit.framework.TestSuite; |
13 |
|
|
14 |
|
public class ArrayListTest extends JSR166TestCase { |
15 |
|
public static void main(String[] args) { |
20 |
|
class Implementation implements CollectionImplementation { |
21 |
|
public Class<?> klazz() { return ArrayList.class; } |
22 |
|
public List emptyCollection() { return new ArrayList(); } |
23 |
< |
public Object makeElement(int i) { return i; } |
23 |
> |
public Object makeElement(int i) { return JSR166TestCase.itemFor(i); } |
24 |
|
public boolean isConcurrent() { return false; } |
25 |
|
public boolean permitsNulls() { return true; } |
26 |
|
} |
29 |
|
return super.emptyCollection().subList(0, 0); |
30 |
|
} |
31 |
|
} |
32 |
< |
return atLeastJava9() |
33 |
< |
? newTestSuite( |
35 |
< |
// ArrayListTest.class, |
32 |
> |
return newTestSuite( |
33 |
> |
ArrayListTest.class, |
34 |
|
CollectionTest.testSuite(new Implementation()), |
35 |
< |
CollectionTest.testSuite(new SubListImplementation())) |
36 |
< |
: newTestSuite( |
37 |
< |
CollectionTest.testSuite(new Implementation())); |
35 |
> |
CollectionTest.testSuite(new SubListImplementation())); |
36 |
> |
} |
37 |
> |
|
38 |
> |
/** |
39 |
> |
* A cloned list equals original |
40 |
> |
*/ |
41 |
> |
public void testClone() throws Exception { |
42 |
> |
ArrayList<Item> x = new ArrayList<>(); |
43 |
> |
x.add(one); |
44 |
> |
x.add(two); |
45 |
> |
x.add(three); |
46 |
> |
@SuppressWarnings("unchecked") |
47 |
> |
ArrayList<Item> y = (ArrayList<Item>) x.clone(); |
48 |
> |
|
49 |
> |
assertNotSame(y, x); |
50 |
> |
mustEqual(x, y); |
51 |
> |
mustEqual(y, x); |
52 |
> |
mustEqual(x.size(), y.size()); |
53 |
> |
mustEqual(x.toString(), y.toString()); |
54 |
> |
assertTrue(Arrays.equals(x.toArray(), y.toArray())); |
55 |
> |
while (!x.isEmpty()) { |
56 |
> |
assertFalse(y.isEmpty()); |
57 |
> |
mustEqual(x.remove(0), y.remove(0)); |
58 |
> |
} |
59 |
> |
assertTrue(y.isEmpty()); |
60 |
|
} |
61 |
|
|
62 |
|
} |