ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/jsr166/jsr166/src/test/tck/CopyOnWriteArrayListTest.java
Revision: 1.24
Committed: Sat Nov 26 05:19:17 2011 UTC (12 years, 5 months ago) by jsr166
Branch: MAIN
Changes since 1.23: +2 -2 lines
Log Message:
assertEquals argument order

File Contents

# User Rev Content
1 dl 1.1 /*
2 dl 1.6 * Written by Doug Lea with assistance from members of JCP JSR-166
3     * Expert Group and released to the public domain, as explained at
4 jsr166 1.19 * http://creativecommons.org/publicdomain/zero/1.0/
5 jsr166 1.8 * Other contributors include Andrew Wright, Jeffrey Hayes,
6     * Pat Fisher, Mike Judd.
7 dl 1.1 */
8    
9     import junit.framework.*;
10 jsr166 1.22 import java.util.Arrays;
11     import java.util.Iterator;
12     import java.util.LinkedList;
13     import java.util.List;
14     import java.util.ListIterator;
15     import java.util.Vector;
16     import java.util.concurrent.CopyOnWriteArrayList;
17 dl 1.1
18 jsr166 1.10 public class CopyOnWriteArrayListTest extends JSR166TestCase {
19 jsr166 1.8
20 dl 1.1 public static void main(String[] args) {
21 jsr166 1.17 junit.textui.TestRunner.run(suite());
22 dl 1.1 }
23    
24     public static Test suite() {
25 jsr166 1.11 return new TestSuite(CopyOnWriteArrayListTest.class);
26 dl 1.1 }
27    
28 jsr166 1.10 static CopyOnWriteArrayList populatedArray(int n) {
29 jsr166 1.11 CopyOnWriteArrayList a = new CopyOnWriteArrayList();
30 dl 1.1 assertTrue(a.isEmpty());
31 jsr166 1.8 for (int i = 0; i < n; ++i)
32 dl 1.1 a.add(new Integer(i));
33     assertFalse(a.isEmpty());
34     assertEquals(n, a.size());
35     return a;
36     }
37    
38 dl 1.4 /**
39 dl 1.5 * a new list is empty
40 dl 1.4 */
41 dl 1.3 public void testConstructor() {
42 jsr166 1.11 CopyOnWriteArrayList a = new CopyOnWriteArrayList();
43 dl 1.3 assertTrue(a.isEmpty());
44     }
45    
46 dl 1.4 /**
47 dl 1.5 * new list contains all elements of initializing array
48 dl 1.4 */
49 dl 1.3 public void testConstructor2() {
50     Integer[] ints = new Integer[SIZE];
51     for (int i = 0; i < SIZE-1; ++i)
52     ints[i] = new Integer(i);
53 jsr166 1.11 CopyOnWriteArrayList a = new CopyOnWriteArrayList(ints);
54 jsr166 1.8 for (int i = 0; i < SIZE; ++i)
55 dl 1.3 assertEquals(ints[i], a.get(i));
56     }
57    
58 dl 1.4 /**
59 dl 1.5 * new list contains all elements of initializing collection
60 dl 1.4 */
61 dl 1.3 public void testConstructor3() {
62     Integer[] ints = new Integer[SIZE];
63     for (int i = 0; i < SIZE-1; ++i)
64     ints[i] = new Integer(i);
65 jsr166 1.11 CopyOnWriteArrayList a = new CopyOnWriteArrayList(Arrays.asList(ints));
66 jsr166 1.8 for (int i = 0; i < SIZE; ++i)
67 dl 1.3 assertEquals(ints[i], a.get(i));
68     }
69 jsr166 1.8
70 dl 1.1 /**
71 jsr166 1.18 * addAll adds each element from the given collection
72 dl 1.1 */
73 dl 1.4 public void testAddAll() {
74 jsr166 1.11 CopyOnWriteArrayList full = populatedArray(3);
75     Vector v = new Vector();
76     v.add(three);
77     v.add(four);
78     v.add(five);
79     full.addAll(v);
80     assertEquals(6, full.size());
81 dl 1.1 }
82    
83     /**
84 jsr166 1.18 * addAllAbsent adds each element from the given collection that did not
85     * already exist in the List
86 dl 1.1 */
87 dl 1.4 public void testAddAllAbsent() {
88 jsr166 1.11 CopyOnWriteArrayList full = populatedArray(3);
89     Vector v = new Vector();
90     v.add(three);
91     v.add(four);
92     v.add(one); // will not add this element
93     full.addAllAbsent(v);
94     assertEquals(5, full.size());
95 dl 1.1 }
96    
97     /**
98 jsr166 1.18 * addIfAbsent will not add the element if it already exists in the list
99 dl 1.1 */
100 dl 1.4 public void testAddIfAbsent() {
101 jsr166 1.11 CopyOnWriteArrayList full = populatedArray(SIZE);
102     full.addIfAbsent(one);
103     assertEquals(SIZE, full.size());
104 dl 1.1 }
105    
106     /**
107 jsr166 1.18 * addIfAbsent adds the element when it does not exist in the list
108 dl 1.1 */
109 dl 1.4 public void testAddIfAbsent2() {
110 jsr166 1.11 CopyOnWriteArrayList full = populatedArray(SIZE);
111 dl 1.3 full.addIfAbsent(three);
112     assertTrue(full.contains(three));
113 dl 1.1 }
114    
115     /**
116 jsr166 1.18 * clear removes all elements from the list
117 dl 1.1 */
118 dl 1.4 public void testClear() {
119 jsr166 1.11 CopyOnWriteArrayList full = populatedArray(SIZE);
120     full.clear();
121     assertEquals(0, full.size());
122 dl 1.1 }
123    
124 dl 1.4 /**
125 jsr166 1.18 * Cloned list is equal
126 dl 1.4 */
127     public void testClone() {
128 jsr166 1.11 CopyOnWriteArrayList l1 = populatedArray(SIZE);
129     CopyOnWriteArrayList l2 = (CopyOnWriteArrayList)(l1.clone());
130 dl 1.4 assertEquals(l1, l2);
131 jsr166 1.11 l1.clear();
132 dl 1.4 assertFalse(l1.equals(l2));
133     }
134    
135 dl 1.1 /**
136 jsr166 1.18 * contains is true for added elements
137 dl 1.1 */
138 dl 1.4 public void testContains() {
139 jsr166 1.11 CopyOnWriteArrayList full = populatedArray(3);
140     assertTrue(full.contains(one));
141     assertFalse(full.contains(five));
142 dl 1.1 }
143    
144 dl 1.4 /**
145 dl 1.7 * adding at an index places it in the indicated index
146 dl 1.4 */
147 dl 1.1 public void testAddIndex() {
148 jsr166 1.11 CopyOnWriteArrayList full = populatedArray(3);
149 dl 1.3 full.add(0, m1);
150 dl 1.1 assertEquals(4, full.size());
151 dl 1.3 assertEquals(m1, full.get(0));
152     assertEquals(zero, full.get(1));
153 dl 1.1
154 dl 1.3 full.add(2, m2);
155 dl 1.1 assertEquals(5, full.size());
156 dl 1.3 assertEquals(m2, full.get(2));
157     assertEquals(two, full.get(4));
158 dl 1.1 }
159    
160 dl 1.4 /**
161 dl 1.5 * lists with same elements are equal and have same hashCode
162 dl 1.4 */
163 dl 1.1 public void testEquals() {
164 jsr166 1.11 CopyOnWriteArrayList a = populatedArray(3);
165     CopyOnWriteArrayList b = populatedArray(3);
166 dl 1.1 assertTrue(a.equals(b));
167     assertTrue(b.equals(a));
168     assertEquals(a.hashCode(), b.hashCode());
169 dl 1.3 a.add(m1);
170 dl 1.1 assertFalse(a.equals(b));
171     assertFalse(b.equals(a));
172 dl 1.3 b.add(m1);
173 dl 1.1 assertTrue(a.equals(b));
174     assertTrue(b.equals(a));
175     assertEquals(a.hashCode(), b.hashCode());
176     }
177    
178     /**
179 jsr166 1.18 * containsAll returns true for collection with subset of elements
180 dl 1.1 */
181 dl 1.4 public void testContainsAll() {
182 jsr166 1.11 CopyOnWriteArrayList full = populatedArray(3);
183     Vector v = new Vector();
184     v.add(one);
185     v.add(two);
186     assertTrue(full.containsAll(v));
187     v.add(six);
188     assertFalse(full.containsAll(v));
189 dl 1.1 }
190    
191     /**
192 jsr166 1.18 * get returns the value at the given index
193 dl 1.1 */
194 dl 1.4 public void testGet() {
195 jsr166 1.11 CopyOnWriteArrayList full = populatedArray(3);
196 jsr166 1.14 assertEquals(0, full.get(0));
197 dl 1.1 }
198    
199     /**
200 jsr166 1.18 * indexOf gives the index for the given object
201 dl 1.1 */
202 dl 1.4 public void testIndexOf() {
203 jsr166 1.11 CopyOnWriteArrayList full = populatedArray(3);
204     assertEquals(1, full.indexOf(one));
205     assertEquals(-1, full.indexOf("puppies"));
206 dl 1.1 }
207    
208     /**
209 jsr166 1.18 * indexOf gives the index based on the given index
210     * at which to start searching
211 dl 1.1 */
212 dl 1.4 public void testIndexOf2() {
213 jsr166 1.11 CopyOnWriteArrayList full = populatedArray(3);
214     assertEquals(1, full.indexOf(one, 0));
215     assertEquals(-1, full.indexOf(one, 2));
216 dl 1.1 }
217    
218     /**
219 jsr166 1.18 * isEmpty returns true when empty, else false
220 dl 1.1 */
221 dl 1.4 public void testIsEmpty() {
222 jsr166 1.11 CopyOnWriteArrayList empty = new CopyOnWriteArrayList();
223     CopyOnWriteArrayList full = populatedArray(SIZE);
224     assertTrue(empty.isEmpty());
225     assertFalse(full.isEmpty());
226 dl 1.1 }
227    
228     /**
229 jsr166 1.18 * iterator() returns an iterator containing the elements of the list
230 dl 1.1 */
231 dl 1.4 public void testIterator() {
232 jsr166 1.11 CopyOnWriteArrayList full = populatedArray(SIZE);
233     Iterator i = full.iterator();
234     int j;
235     for (j = 0; i.hasNext(); j++)
236 jsr166 1.14 assertEquals(j, i.next());
237 jsr166 1.11 assertEquals(SIZE, j);
238 dl 1.1 }
239    
240 dl 1.4 /**
241 dl 1.5 * iterator.remove throws UnsupportedOperationException
242 dl 1.4 */
243 jsr166 1.17 public void testIteratorRemove() {
244 jsr166 1.11 CopyOnWriteArrayList full = populatedArray(SIZE);
245 dl 1.1 Iterator it = full.iterator();
246     it.next();
247     try {
248     it.remove();
249 dl 1.4 shouldThrow();
250 jsr166 1.12 } catch (UnsupportedOperationException success) {}
251 dl 1.1 }
252    
253 dl 1.4 /**
254 dl 1.5 * toString contains toString of elements
255 dl 1.4 */
256     public void testToString() {
257 jsr166 1.11 CopyOnWriteArrayList full = populatedArray(3);
258 dl 1.1 String s = full.toString();
259     for (int i = 0; i < 3; ++i) {
260 jsr166 1.20 assertTrue(s.contains(String.valueOf(i)));
261 dl 1.1 }
262 jsr166 1.8 }
263 dl 1.1
264     /**
265 jsr166 1.18 * lastIndexOf returns the index for the given object
266 dl 1.1 */
267 dl 1.4 public void testLastIndexOf1() {
268 jsr166 1.11 CopyOnWriteArrayList full = populatedArray(3);
269     full.add(one);
270     full.add(three);
271     assertEquals(3, full.lastIndexOf(one));
272     assertEquals(-1, full.lastIndexOf(six));
273 dl 1.1 }
274    
275     /**
276 jsr166 1.18 * lastIndexOf returns the index from the given starting point
277 dl 1.1 */
278 jsr166 1.21 public void testLastIndexOf2() {
279 jsr166 1.11 CopyOnWriteArrayList full = populatedArray(3);
280     full.add(one);
281     full.add(three);
282     assertEquals(3, full.lastIndexOf(one, 4));
283     assertEquals(-1, full.lastIndexOf(three, 3));
284 dl 1.1 }
285    
286     /**
287 jsr166 1.18 * listIterator traverses all elements
288 dl 1.1 */
289 dl 1.4 public void testListIterator1() {
290 jsr166 1.11 CopyOnWriteArrayList full = populatedArray(SIZE);
291     ListIterator i = full.listIterator();
292     int j;
293     for (j = 0; i.hasNext(); j++)
294 jsr166 1.14 assertEquals(j, i.next());
295 jsr166 1.11 assertEquals(SIZE, j);
296 dl 1.1 }
297    
298     /**
299 jsr166 1.18 * listIterator only returns those elements after the given index
300 dl 1.1 */
301 dl 1.4 public void testListIterator2() {
302 jsr166 1.11 CopyOnWriteArrayList full = populatedArray(3);
303     ListIterator i = full.listIterator(1);
304     int j;
305     for (j = 0; i.hasNext(); j++)
306 jsr166 1.14 assertEquals(j+1, i.next());
307 jsr166 1.11 assertEquals(2, j);
308 dl 1.1 }
309    
310     /**
311 jsr166 1.18 * remove removes and returns the object at the given index
312 dl 1.1 */
313 dl 1.4 public void testRemove() {
314 jsr166 1.11 CopyOnWriteArrayList full = populatedArray(3);
315 jsr166 1.15 assertEquals(2, full.remove(2));
316 jsr166 1.11 assertEquals(2, full.size());
317 dl 1.1 }
318    
319     /**
320 jsr166 1.18 * removeAll removes all elements from the given collection
321 dl 1.1 */
322 dl 1.4 public void testRemoveAll() {
323 jsr166 1.11 CopyOnWriteArrayList full = populatedArray(3);
324     Vector v = new Vector();
325     v.add(one);
326     v.add(two);
327     full.removeAll(v);
328     assertEquals(1, full.size());
329 dl 1.1 }
330    
331     /**
332 jsr166 1.18 * set changes the element at the given index
333 dl 1.1 */
334 dl 1.4 public void testSet() {
335 jsr166 1.11 CopyOnWriteArrayList full = populatedArray(3);
336 jsr166 1.15 assertEquals(2, full.set(2, four));
337 jsr166 1.14 assertEquals(4, full.get(2));
338 dl 1.1 }
339    
340     /**
341 jsr166 1.18 * size returns the number of elements
342 dl 1.1 */
343 dl 1.4 public void testSize() {
344 jsr166 1.11 CopyOnWriteArrayList empty = new CopyOnWriteArrayList();
345     CopyOnWriteArrayList full = populatedArray(SIZE);
346     assertEquals(SIZE, full.size());
347     assertEquals(0, empty.size());
348 dl 1.1 }
349    
350     /**
351 jsr166 1.18 * toArray returns an Object array containing all elements from the list
352 dl 1.1 */
353 dl 1.4 public void testToArray() {
354 jsr166 1.11 CopyOnWriteArrayList full = populatedArray(3);
355     Object[] o = full.toArray();
356     assertEquals(3, o.length);
357 jsr166 1.14 assertEquals(0, o[0]);
358     assertEquals(1, o[1]);
359     assertEquals(2, o[2]);
360 dl 1.1 }
361    
362     /**
363 jsr166 1.18 * toArray returns an Integer array containing all elements from
364     * the list
365 dl 1.1 */
366 dl 1.4 public void testToArray2() {
367 jsr166 1.11 CopyOnWriteArrayList full = populatedArray(3);
368     Integer[] i = new Integer[3];
369     i = (Integer[])full.toArray(i);
370     assertEquals(3, i.length);
371     assertEquals(0, i[0].intValue());
372     assertEquals(1, i[1].intValue());
373     assertEquals(2, i[2].intValue());
374 dl 1.1 }
375    
376 dl 1.4 /**
377 dl 1.5 * sublists contains elements at indexes offset from their base
378 dl 1.4 */
379 dl 1.1 public void testSubList() {
380 jsr166 1.11 CopyOnWriteArrayList a = populatedArray(10);
381 dl 1.1 assertTrue(a.subList(1,1).isEmpty());
382 jsr166 1.11 for (int j = 0; j < 9; ++j) {
383     for (int i = j ; i < 10; ++i) {
384     List b = a.subList(j,i);
385     for (int k = j; k < i; ++k) {
386     assertEquals(new Integer(k), b.get(k-j));
387     }
388     }
389     }
390 dl 1.1
391 jsr166 1.11 List s = a.subList(2, 5);
392 jsr166 1.24 assertEquals(3, s.size());
393 dl 1.3 s.set(2, m1);
394 dl 1.1 assertEquals(a.get(4), m1);
395 jsr166 1.11 s.clear();
396 jsr166 1.24 assertEquals(7, a.size());
397 dl 1.1 }
398    
399     // Exception tests
400    
401     /**
402 jsr166 1.18 * toArray throws an ArrayStoreException when the given array
403     * can not store the objects inside the list
404 dl 1.1 */
405 dl 1.4 public void testToArray_ArrayStoreException() {
406     try {
407 dl 1.1 CopyOnWriteArrayList c = new CopyOnWriteArrayList();
408     c.add("zfasdfsdf");
409     c.add("asdadasd");
410     c.toArray(new Long[5]);
411 jsr166 1.11 shouldThrow();
412 jsr166 1.13 } catch (ArrayStoreException success) {}
413 dl 1.1 }
414    
415     /**
416 jsr166 1.18 * get throws an IndexOutOfBoundsException on a negative index
417 dl 1.1 */
418 dl 1.4 public void testGet1_IndexOutOfBoundsException() {
419     try {
420 dl 1.1 CopyOnWriteArrayList c = new CopyOnWriteArrayList();
421     c.get(-1);
422 dl 1.4 shouldThrow();
423 jsr166 1.13 } catch (IndexOutOfBoundsException success) {}
424 dl 1.1 }
425 jsr166 1.8
426 dl 1.1 /**
427 jsr166 1.18 * get throws an IndexOutOfBoundsException on a too high index
428 dl 1.1 */
429 dl 1.4 public void testGet2_IndexOutOfBoundsException() {
430     try {
431 dl 1.1 CopyOnWriteArrayList c = new CopyOnWriteArrayList();
432     c.add("asdasd");
433     c.add("asdad");
434     c.get(100);
435 dl 1.4 shouldThrow();
436 jsr166 1.13 } catch (IndexOutOfBoundsException success) {}
437 dl 1.1 }
438    
439     /**
440 jsr166 1.18 * set throws an IndexOutOfBoundsException on a negative index
441 dl 1.1 */
442 dl 1.4 public void testSet1_IndexOutOfBoundsException() {
443     try {
444 dl 1.1 CopyOnWriteArrayList c = new CopyOnWriteArrayList();
445     c.set(-1,"qwerty");
446 dl 1.4 shouldThrow();
447 jsr166 1.13 } catch (IndexOutOfBoundsException success) {}
448 dl 1.1 }
449 jsr166 1.8
450 dl 1.1 /**
451 jsr166 1.18 * set throws an IndexOutOfBoundsException on a too high index
452 dl 1.1 */
453 dl 1.4 public void testSet2() {
454     try {
455 dl 1.1 CopyOnWriteArrayList c = new CopyOnWriteArrayList();
456     c.add("asdasd");
457     c.add("asdad");
458     c.set(100, "qwerty");
459 dl 1.4 shouldThrow();
460 jsr166 1.13 } catch (IndexOutOfBoundsException success) {}
461 dl 1.1 }
462    
463     /**
464 jsr166 1.18 * add throws an IndexOutOfBoundsException on a negative index
465 dl 1.1 */
466 dl 1.4 public void testAdd1_IndexOutOfBoundsException() {
467     try {
468 dl 1.1 CopyOnWriteArrayList c = new CopyOnWriteArrayList();
469     c.add(-1,"qwerty");
470 dl 1.4 shouldThrow();
471 jsr166 1.13 } catch (IndexOutOfBoundsException success) {}
472 dl 1.1 }
473 jsr166 1.8
474 dl 1.1 /**
475 jsr166 1.18 * add throws an IndexOutOfBoundsException on a too high index
476 dl 1.1 */
477 dl 1.4 public void testAdd2_IndexOutOfBoundsException() {
478     try {
479 dl 1.1 CopyOnWriteArrayList c = new CopyOnWriteArrayList();
480     c.add("asdasd");
481     c.add("asdasdasd");
482     c.add(100, "qwerty");
483 dl 1.4 shouldThrow();
484 jsr166 1.13 } catch (IndexOutOfBoundsException success) {}
485 dl 1.1 }
486    
487     /**
488 jsr166 1.18 * remove throws an IndexOutOfBoundsException on a negative index
489 dl 1.1 */
490 dl 1.4 public void testRemove1_IndexOutOfBounds() {
491     try {
492 dl 1.1 CopyOnWriteArrayList c = new CopyOnWriteArrayList();
493     c.remove(-1);
494 dl 1.4 shouldThrow();
495 jsr166 1.13 } catch (IndexOutOfBoundsException success) {}
496 dl 1.1 }
497    
498     /**
499 jsr166 1.18 * remove throws an IndexOutOfBoundsException on a too high index
500 dl 1.1 */
501 dl 1.4 public void testRemove2_IndexOutOfBounds() {
502     try {
503 dl 1.1 CopyOnWriteArrayList c = new CopyOnWriteArrayList();
504     c.add("asdasd");
505     c.add("adasdasd");
506     c.remove(100);
507 dl 1.4 shouldThrow();
508 jsr166 1.13 } catch (IndexOutOfBoundsException success) {}
509 dl 1.1 }
510 jsr166 1.8
511 dl 1.1 /**
512 jsr166 1.18 * addAll throws an IndexOutOfBoundsException on a negative index
513 dl 1.1 */
514 dl 1.4 public void testAddAll1_IndexOutOfBoundsException() {
515     try {
516 dl 1.1 CopyOnWriteArrayList c = new CopyOnWriteArrayList();
517     c.addAll(-1,new LinkedList());
518 dl 1.4 shouldThrow();
519 jsr166 1.13 } catch (IndexOutOfBoundsException success) {}
520 dl 1.1 }
521 jsr166 1.8
522 dl 1.1 /**
523 jsr166 1.18 * addAll throws an IndexOutOfBoundsException on a too high index
524 dl 1.1 */
525 dl 1.4 public void testAddAll2_IndexOutOfBoundsException() {
526     try {
527 dl 1.1 CopyOnWriteArrayList c = new CopyOnWriteArrayList();
528     c.add("asdasd");
529     c.add("asdasdasd");
530     c.addAll(100, new LinkedList());
531 dl 1.4 shouldThrow();
532 jsr166 1.13 } catch (IndexOutOfBoundsException success) {}
533 dl 1.1 }
534    
535     /**
536 jsr166 1.18 * listIterator throws an IndexOutOfBoundsException on a negative index
537 dl 1.1 */
538 dl 1.4 public void testListIterator1_IndexOutOfBoundsException() {
539     try {
540 dl 1.1 CopyOnWriteArrayList c = new CopyOnWriteArrayList();
541     c.listIterator(-1);
542 dl 1.4 shouldThrow();
543 jsr166 1.13 } catch (IndexOutOfBoundsException success) {}
544 dl 1.1 }
545    
546     /**
547 jsr166 1.18 * listIterator throws an IndexOutOfBoundsException on a too high index
548 dl 1.1 */
549 dl 1.4 public void testListIterator2_IndexOutOfBoundsException() {
550     try {
551 dl 1.1 CopyOnWriteArrayList c = new CopyOnWriteArrayList();
552     c.add("adasd");
553     c.add("asdasdas");
554     c.listIterator(100);
555 dl 1.4 shouldThrow();
556 jsr166 1.13 } catch (IndexOutOfBoundsException success) {}
557 dl 1.1 }
558    
559     /**
560 jsr166 1.18 * subList throws an IndexOutOfBoundsException on a negative index
561 dl 1.1 */
562 dl 1.4 public void testSubList1_IndexOutOfBoundsException() {
563     try {
564 dl 1.1 CopyOnWriteArrayList c = new CopyOnWriteArrayList();
565     c.subList(-1,100);
566 dl 1.4 shouldThrow();
567 jsr166 1.13 } catch (IndexOutOfBoundsException success) {}
568 dl 1.1 }
569    
570     /**
571 jsr166 1.18 * subList throws an IndexOutOfBoundsException on a too high index
572 dl 1.1 */
573 dl 1.4 public void testSubList2_IndexOutOfBoundsException() {
574     try {
575 dl 1.1 CopyOnWriteArrayList c = new CopyOnWriteArrayList();
576     c.add("asdasd");
577     c.subList(1,100);
578 dl 1.4 shouldThrow();
579 jsr166 1.13 } catch (IndexOutOfBoundsException success) {}
580 dl 1.1 }
581    
582     /**
583 jsr166 1.18 * subList throws IndexOutOfBoundsException when the second index
584     * is lower then the first
585 dl 1.1 */
586 dl 1.4 public void testSubList3_IndexOutOfBoundsException() {
587     try {
588 dl 1.1 CopyOnWriteArrayList c = new CopyOnWriteArrayList();
589     c.subList(3,1);
590 dl 1.4 shouldThrow();
591 jsr166 1.13 } catch (IndexOutOfBoundsException success) {}
592 dl 1.2 }
593    
594 dl 1.4 /**
595 jsr166 1.16 * a deserialized serialized list is equal
596 dl 1.4 */
597 jsr166 1.12 public void testSerialization() throws Exception {
598 jsr166 1.22 List x = populatedArray(SIZE);
599     List y = serialClone(x);
600 dl 1.2
601 jsr166 1.22 assertTrue(x != y);
602     assertEquals(x.size(), y.size());
603     assertEquals(x.toString(), y.toString());
604     assertTrue(Arrays.equals(x.toArray(), y.toArray()));
605     assertEquals(x, y);
606     assertEquals(y, x);
607     while (!x.isEmpty()) {
608     assertFalse(y.isEmpty());
609     assertEquals(x.remove(0), y.remove(0));
610     }
611     assertTrue(y.isEmpty());
612 dl 1.1 }
613 jsr166 1.8
614 dl 1.1 }