1 |
jsr166 |
1.1 |
/* |
2 |
|
|
* Written by Doug Lea and Martin Buchholz with assistance from |
3 |
|
|
* members of JCP JSR-166 Expert Group and released to the public |
4 |
|
|
* domain, as explained at |
5 |
|
|
* http://creativecommons.org/publicdomain/zero/1.0/ |
6 |
|
|
*/ |
7 |
|
|
|
8 |
|
|
import java.util.Vector; |
9 |
jsr166 |
1.2 |
import java.util.List; |
10 |
jsr166 |
1.1 |
|
11 |
|
|
import junit.framework.Test; |
12 |
|
|
|
13 |
|
|
public class VectorTest extends JSR166TestCase { |
14 |
|
|
public static void main(String[] args) { |
15 |
|
|
main(suite(), args); |
16 |
|
|
} |
17 |
|
|
|
18 |
|
|
public static Test suite() { |
19 |
|
|
class Implementation implements CollectionImplementation { |
20 |
|
|
public Class<?> klazz() { return Vector.class; } |
21 |
jsr166 |
1.2 |
public List emptyCollection() { return new Vector(); } |
22 |
jsr166 |
1.1 |
public Object makeElement(int i) { return i; } |
23 |
|
|
public boolean isConcurrent() { return false; } |
24 |
|
|
public boolean permitsNulls() { return true; } |
25 |
|
|
} |
26 |
jsr166 |
1.2 |
class SubListImplementation extends Implementation { |
27 |
|
|
public List emptyCollection() { |
28 |
|
|
return super.emptyCollection().subList(0, 0); |
29 |
|
|
} |
30 |
|
|
} |
31 |
|
|
return newTestSuite( |
32 |
jsr166 |
1.3 |
VectorTest.class, |
33 |
jsr166 |
1.2 |
CollectionTest.testSuite(new Implementation()), |
34 |
|
|
CollectionTest.testSuite(new SubListImplementation())); |
35 |
jsr166 |
1.1 |
} |
36 |
|
|
|
37 |
jsr166 |
1.3 |
/** |
38 |
|
|
* tests for setSize() |
39 |
|
|
*/ |
40 |
|
|
public void testSetSize() { |
41 |
jsr166 |
1.5 |
final Vector v = new Vector(); |
42 |
jsr166 |
1.3 |
for (int n : new int[] { 100, 5, 50 }) { |
43 |
|
|
v.setSize(n); |
44 |
|
|
assertEquals(n, v.size()); |
45 |
|
|
assertNull(v.get(0)); |
46 |
|
|
assertNull(v.get(n - 1)); |
47 |
jsr166 |
1.5 |
assertThrows( |
48 |
|
|
ArrayIndexOutOfBoundsException.class, |
49 |
|
|
new Runnable() { public void run() { v.setSize(-1); }}); |
50 |
jsr166 |
1.4 |
assertEquals(n, v.size()); |
51 |
|
|
assertNull(v.get(0)); |
52 |
|
|
assertNull(v.get(n - 1)); |
53 |
jsr166 |
1.3 |
} |
54 |
|
|
} |
55 |
|
|
|
56 |
jsr166 |
1.1 |
} |