2 |
|
* 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 |
< |
* Other contributors include Andrew Wright, Jeffrey Hayes, |
6 |
< |
* Pat Fisher, Mike Judd. |
5 |
> |
* Other contributors include Andrew Wright, Jeffrey Hayes, |
6 |
> |
* Pat Fisher, Mike Judd. |
7 |
|
*/ |
8 |
|
|
9 |
|
import junit.framework.*; |
12 |
|
import java.io.*; |
13 |
|
|
14 |
|
public class CopyOnWriteArrayListTest extends JSR166TestCase{ |
15 |
< |
|
15 |
> |
|
16 |
|
public static void main(String[] args) { |
17 |
< |
junit.textui.TestRunner.run (suite()); |
17 |
> |
junit.textui.TestRunner.run (suite()); |
18 |
|
} |
19 |
|
|
20 |
|
public static Test suite() { |
24 |
|
static CopyOnWriteArrayList populatedArray(int n){ |
25 |
|
CopyOnWriteArrayList a = new CopyOnWriteArrayList(); |
26 |
|
assertTrue(a.isEmpty()); |
27 |
< |
for (int i = 0; i < n; ++i) |
27 |
> |
for (int i = 0; i < n; ++i) |
28 |
|
a.add(new Integer(i)); |
29 |
|
assertFalse(a.isEmpty()); |
30 |
|
assertEquals(n, a.size()); |
48 |
|
for (int i = 0; i < SIZE-1; ++i) |
49 |
|
ints[i] = new Integer(i); |
50 |
|
CopyOnWriteArrayList a = new CopyOnWriteArrayList(ints); |
51 |
< |
for (int i = 0; i < SIZE; ++i) |
51 |
> |
for (int i = 0; i < SIZE; ++i) |
52 |
|
assertEquals(ints[i], a.get(i)); |
53 |
|
} |
54 |
|
|
60 |
|
for (int i = 0; i < SIZE-1; ++i) |
61 |
|
ints[i] = new Integer(i); |
62 |
|
CopyOnWriteArrayList a = new CopyOnWriteArrayList(Arrays.asList(ints)); |
63 |
< |
for (int i = 0; i < SIZE; ++i) |
63 |
> |
for (int i = 0; i < SIZE; ++i) |
64 |
|
assertEquals(ints[i], a.get(i)); |
65 |
|
} |
66 |
< |
|
66 |
> |
|
67 |
|
|
68 |
|
/** |
69 |
|
* addAll adds each element from the given collection |
174 |
|
assertEquals(a.hashCode(), b.hashCode()); |
175 |
|
} |
176 |
|
|
177 |
< |
|
177 |
> |
|
178 |
|
/** |
179 |
|
* containsAll returns true for collection with subset of elements |
180 |
|
*/ |
226 |
|
} |
227 |
|
|
228 |
|
/** |
229 |
< |
* iterator() returns an iterator containing the elements of the list |
229 |
> |
* iterator() returns an iterator containing the elements of the list |
230 |
|
*/ |
231 |
|
public void testIterator() { |
232 |
|
CopyOnWriteArrayList full = populatedArray(SIZE); |
260 |
|
for (int i = 0; i < 3; ++i) { |
261 |
|
assertTrue(s.indexOf(String.valueOf(i)) >= 0); |
262 |
|
} |
263 |
< |
} |
263 |
> |
} |
264 |
|
|
265 |
|
/** |
266 |
|
* lastIndexOf returns the index for the given object |
424 |
|
shouldThrow(); |
425 |
|
} catch(IndexOutOfBoundsException e){} |
426 |
|
} |
427 |
< |
|
427 |
> |
|
428 |
|
/** |
429 |
|
* get throws an IndexOutOfBoundsException on a too high index |
430 |
|
*/ |
448 |
|
shouldThrow(); |
449 |
|
} catch(IndexOutOfBoundsException e){} |
450 |
|
} |
451 |
< |
|
451 |
> |
|
452 |
|
/** |
453 |
|
* set throws an IndexOutOfBoundsException on a too high index |
454 |
|
*/ |
472 |
|
shouldThrow(); |
473 |
|
} catch(IndexOutOfBoundsException e){} |
474 |
|
} |
475 |
< |
|
475 |
> |
|
476 |
|
/** |
477 |
|
* add throws an IndexOutOfBoundsException on a too high index |
478 |
|
*/ |
509 |
|
shouldThrow(); |
510 |
|
} catch(IndexOutOfBoundsException e){} |
511 |
|
} |
512 |
< |
|
512 |
> |
|
513 |
|
/** |
514 |
|
* addAll throws an IndexOutOfBoundsException on a negative index |
515 |
|
*/ |
520 |
|
shouldThrow(); |
521 |
|
} catch(IndexOutOfBoundsException e){} |
522 |
|
} |
523 |
< |
|
523 |
> |
|
524 |
|
/** |
525 |
|
* addAll throws an IndexOutOfBoundsException on a too high index |
526 |
|
*/ |
584 |
|
|
585 |
|
/** |
586 |
|
* subList throws IndexOutOfBoundsException when the second index |
587 |
< |
* is lower then the first |
587 |
> |
* is lower then the first |
588 |
|
*/ |
589 |
|
public void testSubList3_IndexOutOfBoundsException() { |
590 |
|
try { |
617 |
|
unexpectedException(); |
618 |
|
} |
619 |
|
} |
620 |
< |
|
620 |
> |
|
621 |
|
} |