ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/jsr166/jsr166/src/test/tck/CopyOnWriteArrayListTest.java
Revision: 1.11
Committed: Sat Nov 21 02:07:26 2009 UTC (14 years, 5 months ago) by jsr166
Branch: MAIN
Changes since 1.10: +126 -126 lines
Log Message:
untabify

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