ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/jsr166/jsr166/src/test/tck/CopyOnWriteArrayListTest.java
Revision: 1.22
Committed: Tue May 31 16:16:23 2011 UTC (12 years, 11 months ago) by jsr166
Branch: MAIN
Changes since 1.21: +20 -15 lines
Log Message:
use serialClone in serialization tests; update imports

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