9 |
|
import java.util.ArrayList; |
10 |
|
import java.util.Arrays; |
11 |
|
import java.util.Collection; |
12 |
– |
import java.util.Collections; |
12 |
|
import java.util.Iterator; |
13 |
|
import java.util.LinkedList; |
14 |
|
import java.util.List; |
26 |
|
} |
27 |
|
|
28 |
|
public static Test suite() { |
29 |
< |
return new TestSuite(CopyOnWriteArrayListTest.class); |
29 |
> |
class Implementation implements CollectionImplementation { |
30 |
> |
public Class<?> klazz() { return ArrayList.class; } |
31 |
> |
public List emptyCollection() { return new CopyOnWriteArrayList(); } |
32 |
> |
public Object makeElement(int i) { return i; } |
33 |
> |
public boolean isConcurrent() { return true; } |
34 |
> |
public boolean permitsNulls() { return true; } |
35 |
> |
} |
36 |
> |
class SubListImplementation extends Implementation { |
37 |
> |
public List emptyCollection() { |
38 |
> |
return super.emptyCollection().subList(0, 0); |
39 |
> |
} |
40 |
> |
} |
41 |
> |
return newTestSuite( |
42 |
> |
CopyOnWriteArrayListTest.class, |
43 |
> |
CollectionTest.testSuite(new Implementation())); |
44 |
> |
//CollectionTest.testSuite(new SubListImplementation())); |
45 |
|
} |
46 |
|
|
47 |
|
static CopyOnWriteArrayList<Integer> populatedArray(int n) { |
191 |
|
CopyOnWriteArrayList b = populatedArray(3); |
192 |
|
assertTrue(a.equals(b)); |
193 |
|
assertTrue(b.equals(a)); |
194 |
+ |
assertTrue(a.containsAll(b)); |
195 |
+ |
assertTrue(b.containsAll(a)); |
196 |
|
assertEquals(a.hashCode(), b.hashCode()); |
197 |
|
a.add(m1); |
198 |
|
assertFalse(a.equals(b)); |
199 |
|
assertFalse(b.equals(a)); |
200 |
+ |
assertTrue(a.containsAll(b)); |
201 |
+ |
assertFalse(b.containsAll(a)); |
202 |
|
b.add(m1); |
203 |
|
assertTrue(a.equals(b)); |
204 |
|
assertTrue(b.equals(a)); |
205 |
+ |
assertTrue(a.containsAll(b)); |
206 |
+ |
assertTrue(b.containsAll(a)); |
207 |
|
assertEquals(a.hashCode(), b.hashCode()); |
208 |
+ |
|
209 |
+ |
assertFalse(a.equals(null)); |
210 |
|
} |
211 |
|
|
212 |
|
/** |
213 |
< |
* containsAll returns true for collection with subset of elements |
213 |
> |
* containsAll returns true for collections with subset of elements |
214 |
|
*/ |
215 |
|
public void testContainsAll() { |
216 |
|
CopyOnWriteArrayList full = populatedArray(3); |
219 |
|
assertTrue(full.containsAll(Arrays.asList(one, two))); |
220 |
|
assertFalse(full.containsAll(Arrays.asList(one, two, six))); |
221 |
|
assertFalse(full.containsAll(Arrays.asList(six))); |
222 |
+ |
|
223 |
+ |
try { |
224 |
+ |
full.containsAll(null); |
225 |
+ |
shouldThrow(); |
226 |
+ |
} catch (NullPointerException success) {} |
227 |
|
} |
228 |
|
|
229 |
|
/** |
278 |
|
Integer[] elements = new Integer[SIZE]; |
279 |
|
for (int i = 0; i < SIZE; i++) |
280 |
|
elements[i] = i; |
281 |
< |
Collections.shuffle(Arrays.asList(elements)); |
281 |
> |
shuffle(elements); |
282 |
|
Collection<Integer> full = populatedArray(elements); |
283 |
|
|
284 |
|
Iterator it = full.iterator(); |
446 |
|
Integer[] elements = new Integer[SIZE]; |
447 |
|
for (int i = 0; i < SIZE; i++) |
448 |
|
elements[i] = i; |
449 |
< |
Collections.shuffle(Arrays.asList(elements)); |
449 |
> |
shuffle(elements); |
450 |
|
Collection<Integer> full = populatedArray(elements); |
451 |
|
|
452 |
|
assertTrue(Arrays.equals(elements, full.toArray())); |
474 |
|
Integer[] elements = new Integer[SIZE]; |
475 |
|
for (int i = 0; i < SIZE; i++) |
476 |
|
elements[i] = i; |
477 |
< |
Collections.shuffle(Arrays.asList(elements)); |
477 |
> |
shuffle(elements); |
478 |
|
Collection<Integer> full = populatedArray(elements); |
479 |
|
|
480 |
|
Arrays.fill(a, 42); |