ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/jsr166/jsr166/src/test/tck/CopyOnWriteArrayListTest.java
Revision: 1.25
Committed: Sat Nov 26 07:39:02 2011 UTC (12 years, 5 months ago) by jsr166
Branch: MAIN
Changes since 1.24: +12 -10 lines
Log Message:
improve toArray methods

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.25 static CopyOnWriteArrayList<Integer> populatedArray(int n) {
29     CopyOnWriteArrayList<Integer> a
30     = new CopyOnWriteArrayList<Integer>();
31 dl 1.1 assertTrue(a.isEmpty());
32 jsr166 1.8 for (int i = 0; i < n; ++i)
33 jsr166 1.25 a.add(i);
34 dl 1.1 assertFalse(a.isEmpty());
35     assertEquals(n, a.size());
36     return a;
37     }
38    
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.1 /**
72 jsr166 1.18 * addAll adds each element from the given collection
73 dl 1.1 */
74 dl 1.4 public void testAddAll() {
75 jsr166 1.11 CopyOnWriteArrayList full = populatedArray(3);
76     Vector v = new Vector();
77     v.add(three);
78     v.add(four);
79     v.add(five);
80     full.addAll(v);
81     assertEquals(6, full.size());
82 dl 1.1 }
83    
84     /**
85 jsr166 1.18 * addAllAbsent adds each element from the given collection that did not
86     * already exist in the List
87 dl 1.1 */
88 dl 1.4 public void testAddAllAbsent() {
89 jsr166 1.11 CopyOnWriteArrayList full = populatedArray(3);
90     Vector v = new Vector();
91     v.add(three);
92     v.add(four);
93     v.add(one); // will not add this element
94     full.addAllAbsent(v);
95     assertEquals(5, full.size());
96 dl 1.1 }
97    
98     /**
99 jsr166 1.18 * addIfAbsent will not add the element if it already exists in the list
100 dl 1.1 */
101 dl 1.4 public void testAddIfAbsent() {
102 jsr166 1.11 CopyOnWriteArrayList full = populatedArray(SIZE);
103     full.addIfAbsent(one);
104     assertEquals(SIZE, full.size());
105 dl 1.1 }
106    
107     /**
108 jsr166 1.18 * addIfAbsent adds the element when it does not exist in the list
109 dl 1.1 */
110 dl 1.4 public void testAddIfAbsent2() {
111 jsr166 1.11 CopyOnWriteArrayList full = populatedArray(SIZE);
112 dl 1.3 full.addIfAbsent(three);
113     assertTrue(full.contains(three));
114 dl 1.1 }
115    
116     /**
117 jsr166 1.18 * clear removes all elements from the list
118 dl 1.1 */
119 dl 1.4 public void testClear() {
120 jsr166 1.11 CopyOnWriteArrayList full = populatedArray(SIZE);
121     full.clear();
122     assertEquals(0, full.size());
123 dl 1.1 }
124    
125 dl 1.4 /**
126 jsr166 1.18 * Cloned list is equal
127 dl 1.4 */
128     public void testClone() {
129 jsr166 1.11 CopyOnWriteArrayList l1 = populatedArray(SIZE);
130     CopyOnWriteArrayList l2 = (CopyOnWriteArrayList)(l1.clone());
131 dl 1.4 assertEquals(l1, l2);
132 jsr166 1.11 l1.clear();
133 dl 1.4 assertFalse(l1.equals(l2));
134     }
135    
136 dl 1.1 /**
137 jsr166 1.18 * contains is true for added elements
138 dl 1.1 */
139 dl 1.4 public void testContains() {
140 jsr166 1.11 CopyOnWriteArrayList full = populatedArray(3);
141     assertTrue(full.contains(one));
142     assertFalse(full.contains(five));
143 dl 1.1 }
144    
145 dl 1.4 /**
146 dl 1.7 * adding at an index places it in the indicated index
147 dl 1.4 */
148 dl 1.1 public void testAddIndex() {
149 jsr166 1.11 CopyOnWriteArrayList full = populatedArray(3);
150 dl 1.3 full.add(0, m1);
151 dl 1.1 assertEquals(4, full.size());
152 dl 1.3 assertEquals(m1, full.get(0));
153     assertEquals(zero, full.get(1));
154 dl 1.1
155 dl 1.3 full.add(2, m2);
156 dl 1.1 assertEquals(5, full.size());
157 dl 1.3 assertEquals(m2, full.get(2));
158     assertEquals(two, full.get(4));
159 dl 1.1 }
160    
161 dl 1.4 /**
162 dl 1.5 * lists with same elements are equal and have same hashCode
163 dl 1.4 */
164 dl 1.1 public void testEquals() {
165 jsr166 1.11 CopyOnWriteArrayList a = populatedArray(3);
166     CopyOnWriteArrayList b = populatedArray(3);
167 dl 1.1 assertTrue(a.equals(b));
168     assertTrue(b.equals(a));
169     assertEquals(a.hashCode(), b.hashCode());
170 dl 1.3 a.add(m1);
171 dl 1.1 assertFalse(a.equals(b));
172     assertFalse(b.equals(a));
173 dl 1.3 b.add(m1);
174 dl 1.1 assertTrue(a.equals(b));
175     assertTrue(b.equals(a));
176     assertEquals(a.hashCode(), b.hashCode());
177     }
178    
179     /**
180 jsr166 1.18 * containsAll returns true for collection with subset of elements
181 dl 1.1 */
182 dl 1.4 public void testContainsAll() {
183 jsr166 1.11 CopyOnWriteArrayList full = populatedArray(3);
184     Vector v = new Vector();
185     v.add(one);
186     v.add(two);
187     assertTrue(full.containsAll(v));
188     v.add(six);
189     assertFalse(full.containsAll(v));
190 dl 1.1 }
191    
192     /**
193 jsr166 1.18 * get returns the value at the given index
194 dl 1.1 */
195 dl 1.4 public void testGet() {
196 jsr166 1.11 CopyOnWriteArrayList full = populatedArray(3);
197 jsr166 1.14 assertEquals(0, full.get(0));
198 dl 1.1 }
199    
200     /**
201 jsr166 1.18 * indexOf gives the index for the given object
202 dl 1.1 */
203 dl 1.4 public void testIndexOf() {
204 jsr166 1.11 CopyOnWriteArrayList full = populatedArray(3);
205     assertEquals(1, full.indexOf(one));
206     assertEquals(-1, full.indexOf("puppies"));
207 dl 1.1 }
208    
209     /**
210 jsr166 1.18 * indexOf gives the index based on the given index
211     * at which to start searching
212 dl 1.1 */
213 dl 1.4 public void testIndexOf2() {
214 jsr166 1.11 CopyOnWriteArrayList full = populatedArray(3);
215     assertEquals(1, full.indexOf(one, 0));
216     assertEquals(-1, full.indexOf(one, 2));
217 dl 1.1 }
218    
219     /**
220 jsr166 1.18 * isEmpty returns true when empty, else false
221 dl 1.1 */
222 dl 1.4 public void testIsEmpty() {
223 jsr166 1.11 CopyOnWriteArrayList empty = new CopyOnWriteArrayList();
224     CopyOnWriteArrayList full = populatedArray(SIZE);
225     assertTrue(empty.isEmpty());
226     assertFalse(full.isEmpty());
227 dl 1.1 }
228    
229     /**
230 jsr166 1.18 * iterator() returns an iterator containing the elements of the list
231 dl 1.1 */
232 dl 1.4 public void testIterator() {
233 jsr166 1.11 CopyOnWriteArrayList full = populatedArray(SIZE);
234     Iterator i = full.iterator();
235     int j;
236     for (j = 0; i.hasNext(); j++)
237 jsr166 1.14 assertEquals(j, i.next());
238 jsr166 1.11 assertEquals(SIZE, j);
239 dl 1.1 }
240    
241 dl 1.4 /**
242 dl 1.5 * iterator.remove throws UnsupportedOperationException
243 dl 1.4 */
244 jsr166 1.17 public void testIteratorRemove() {
245 jsr166 1.11 CopyOnWriteArrayList full = populatedArray(SIZE);
246 dl 1.1 Iterator it = full.iterator();
247     it.next();
248     try {
249     it.remove();
250 dl 1.4 shouldThrow();
251 jsr166 1.12 } catch (UnsupportedOperationException success) {}
252 dl 1.1 }
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 jsr166 1.20 assertTrue(s.contains(String.valueOf(i)));
262 dl 1.1 }
263 jsr166 1.8 }
264 dl 1.1
265     /**
266 jsr166 1.18 * 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 jsr166 1.18 * lastIndexOf returns the index from the given starting point
278 dl 1.1 */
279 jsr166 1.21 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 jsr166 1.18 * 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 jsr166 1.14 assertEquals(j, i.next());
296 jsr166 1.11 assertEquals(SIZE, j);
297 dl 1.1 }
298    
299     /**
300 jsr166 1.18 * 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 jsr166 1.14 assertEquals(j+1, i.next());
308 jsr166 1.11 assertEquals(2, j);
309 dl 1.1 }
310    
311     /**
312 jsr166 1.18 * 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 jsr166 1.15 assertEquals(2, full.remove(2));
317 jsr166 1.11 assertEquals(2, full.size());
318 dl 1.1 }
319    
320     /**
321 jsr166 1.18 * 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 jsr166 1.18 * 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 jsr166 1.15 assertEquals(2, full.set(2, four));
338 jsr166 1.14 assertEquals(4, full.get(2));
339 dl 1.1 }
340    
341     /**
342 jsr166 1.18 * 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 jsr166 1.18 * 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 jsr166 1.14 assertEquals(0, o[0]);
359     assertEquals(1, o[1]);
360     assertEquals(2, o[2]);
361 dl 1.1 }
362    
363     /**
364 jsr166 1.18 * 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.25 final int size = 3;
369     CopyOnWriteArrayList<Integer> full = populatedArray(size);
370     Integer[] ints = new Integer[size];
371     assertSame(ints, full.toArray(ints));
372     Iterator<Integer> it = full.iterator();
373     for (int i = 0; i < size; i++)
374     assertSame(ints[i], it.next());
375     assertFalse(it.hasNext());
376 dl 1.1 }
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 jsr166 1.24 assertEquals(3, s.size());
395 dl 1.3 s.set(2, m1);
396 dl 1.1 assertEquals(a.get(4), m1);
397 jsr166 1.11 s.clear();
398 jsr166 1.24 assertEquals(7, a.size());
399 dl 1.1 }
400    
401     // Exception tests
402    
403     /**
404 jsr166 1.18 * toArray throws an ArrayStoreException when the given array
405     * can not store the objects inside the list
406 dl 1.1 */
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.13 } catch (ArrayStoreException success) {}
415 dl 1.1 }
416    
417     /**
418 jsr166 1.18 * 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.13 } catch (IndexOutOfBoundsException success) {}
426 dl 1.1 }
427 jsr166 1.8
428 dl 1.1 /**
429 jsr166 1.18 * 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.13 } catch (IndexOutOfBoundsException success) {}
439 dl 1.1 }
440    
441     /**
442 jsr166 1.18 * 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.13 } catch (IndexOutOfBoundsException success) {}
450 dl 1.1 }
451 jsr166 1.8
452 dl 1.1 /**
453 jsr166 1.18 * 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.13 } catch (IndexOutOfBoundsException success) {}
463 dl 1.1 }
464    
465     /**
466 jsr166 1.18 * 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.13 } catch (IndexOutOfBoundsException success) {}
474 dl 1.1 }
475 jsr166 1.8
476 dl 1.1 /**
477 jsr166 1.18 * 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.13 } catch (IndexOutOfBoundsException success) {}
487 dl 1.1 }
488    
489     /**
490 jsr166 1.18 * 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.13 } catch (IndexOutOfBoundsException success) {}
498 dl 1.1 }
499    
500     /**
501 jsr166 1.18 * 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.13 } catch (IndexOutOfBoundsException success) {}
511 dl 1.1 }
512 jsr166 1.8
513 dl 1.1 /**
514 jsr166 1.18 * 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.13 } catch (IndexOutOfBoundsException success) {}
522 dl 1.1 }
523 jsr166 1.8
524 dl 1.1 /**
525 jsr166 1.18 * 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.13 } catch (IndexOutOfBoundsException success) {}
535 dl 1.1 }
536    
537     /**
538 jsr166 1.18 * 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.13 } catch (IndexOutOfBoundsException success) {}
546 dl 1.1 }
547    
548     /**
549 jsr166 1.18 * 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.13 } catch (IndexOutOfBoundsException success) {}
559 dl 1.1 }
560    
561     /**
562 jsr166 1.18 * 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 dl 1.4 shouldThrow();
569 jsr166 1.13 } catch (IndexOutOfBoundsException success) {}
570 dl 1.1 }
571    
572     /**
573 jsr166 1.18 * subList throws an IndexOutOfBoundsException on a too high index
574 dl 1.1 */
575 dl 1.4 public void testSubList2_IndexOutOfBoundsException() {
576     try {
577 dl 1.1 CopyOnWriteArrayList c = new CopyOnWriteArrayList();
578     c.add("asdasd");
579     c.subList(1,100);
580 dl 1.4 shouldThrow();
581 jsr166 1.13 } catch (IndexOutOfBoundsException success) {}
582 dl 1.1 }
583    
584     /**
585 jsr166 1.18 * subList throws IndexOutOfBoundsException when the second index
586     * is lower then the first
587 dl 1.1 */
588 dl 1.4 public void testSubList3_IndexOutOfBoundsException() {
589     try {
590 dl 1.1 CopyOnWriteArrayList c = new CopyOnWriteArrayList();
591     c.subList(3,1);
592 dl 1.4 shouldThrow();
593 jsr166 1.13 } catch (IndexOutOfBoundsException success) {}
594 dl 1.2 }
595    
596 dl 1.4 /**
597 jsr166 1.16 * a deserialized serialized list is equal
598 dl 1.4 */
599 jsr166 1.12 public void testSerialization() throws Exception {
600 jsr166 1.22 List x = populatedArray(SIZE);
601     List y = serialClone(x);
602 dl 1.2
603 jsr166 1.22 assertTrue(x != y);
604     assertEquals(x.size(), y.size());
605     assertEquals(x.toString(), y.toString());
606     assertTrue(Arrays.equals(x.toArray(), y.toArray()));
607     assertEquals(x, y);
608     assertEquals(y, x);
609     while (!x.isEmpty()) {
610     assertFalse(y.isEmpty());
611     assertEquals(x.remove(0), y.remove(0));
612     }
613     assertTrue(y.isEmpty());
614 dl 1.1 }
615 jsr166 1.8
616 dl 1.1 }