16 |
|
|
17 |
|
public class AbstractQueueTest extends JSR166TestCase { |
18 |
|
public static void main(String[] args) { |
19 |
< |
junit.textui.TestRunner.run(suite()); |
19 |
> |
main(suite(), args); |
20 |
|
} |
21 |
|
public static Test suite() { |
22 |
|
return new TestSuite(AbstractQueueTest.class); |
23 |
|
} |
24 |
|
|
25 |
< |
static class Succeed extends AbstractQueue<Integer> { |
26 |
< |
public boolean offer(Integer x) { |
25 |
> |
static class Succeed extends AbstractQueue<Item> { |
26 |
> |
public boolean offer(Item x) { |
27 |
|
if (x == null) throw new NullPointerException(); |
28 |
|
return true; |
29 |
|
} |
30 |
< |
public Integer peek() { return one; } |
31 |
< |
public Integer poll() { return one; } |
30 |
> |
public Item peek() { return one; } |
31 |
> |
public Item poll() { return one; } |
32 |
|
public int size() { return 0; } |
33 |
< |
public Iterator iterator() { return null; } // not needed |
33 |
> |
public Iterator<Item> iterator() { return null; } // not needed |
34 |
|
} |
35 |
|
|
36 |
< |
static class Fail extends AbstractQueue<Integer> { |
37 |
< |
public boolean offer(Integer x) { |
36 |
> |
static class Fail extends AbstractQueue<Item> { |
37 |
> |
public boolean offer(Item x) { |
38 |
|
if (x == null) throw new NullPointerException(); |
39 |
|
return false; |
40 |
|
} |
41 |
< |
public Integer peek() { return null; } |
42 |
< |
public Integer poll() { return null; } |
41 |
> |
public Item peek() { return null; } |
42 |
> |
public Item poll() { return null; } |
43 |
|
public int size() { return 0; } |
44 |
< |
public Iterator iterator() { return null; } // not needed |
44 |
> |
public Iterator<Item> iterator() { return null; } // not needed |
45 |
|
} |
46 |
|
|
47 |
|
/** |
53 |
|
} |
54 |
|
|
55 |
|
/** |
56 |
< |
* add throws ISE true if offer fails |
56 |
> |
* add throws IllegalStateException if offer fails |
57 |
|
*/ |
58 |
|
public void testAddF() { |
59 |
|
Fail q = new Fail(); |
64 |
|
} |
65 |
|
|
66 |
|
/** |
67 |
< |
* add throws NPE if offer does |
67 |
> |
* add throws NullPointerException if offer does |
68 |
|
*/ |
69 |
|
public void testAddNPE() { |
70 |
|
Succeed q = new Succeed(); |
79 |
|
*/ |
80 |
|
public void testRemoveS() { |
81 |
|
Succeed q = new Succeed(); |
82 |
< |
q.remove(); |
82 |
> |
assertSame(one, q.remove()); |
83 |
|
} |
84 |
|
|
85 |
|
/** |
98 |
|
*/ |
99 |
|
public void testElementS() { |
100 |
|
Succeed q = new Succeed(); |
101 |
< |
q.element(); |
101 |
> |
assertSame(one, q.element()); |
102 |
|
} |
103 |
|
|
104 |
|
/** |
113 |
|
} |
114 |
|
|
115 |
|
/** |
116 |
< |
* addAll(null) throws NPE |
116 |
> |
* addAll(null) throws NullPointerException |
117 |
|
*/ |
118 |
|
public void testAddAll1() { |
119 |
+ |
Succeed q = new Succeed(); |
120 |
|
try { |
120 |
– |
Succeed q = new Succeed(); |
121 |
|
q.addAll(null); |
122 |
|
shouldThrow(); |
123 |
|
} catch (NullPointerException success) {} |
124 |
|
} |
125 |
|
|
126 |
|
/** |
127 |
< |
* addAll(this) throws IAE |
127 |
> |
* addAll(this) throws IllegalArgumentException |
128 |
|
*/ |
129 |
|
public void testAddAllSelf() { |
130 |
+ |
Succeed q = new Succeed(); |
131 |
|
try { |
131 |
– |
Succeed q = new Succeed(); |
132 |
|
q.addAll(q); |
133 |
|
shouldThrow(); |
134 |
|
} catch (IllegalArgumentException success) {} |
135 |
|
} |
136 |
|
|
137 |
|
/** |
138 |
< |
* addAll of a collection with null elements throws NPE |
138 |
> |
* addAll of a collection with null elements throws NullPointerException |
139 |
|
*/ |
140 |
|
public void testAddAll2() { |
141 |
+ |
Succeed q = new Succeed(); |
142 |
+ |
Item[] items = new Item[SIZE]; |
143 |
|
try { |
144 |
< |
Succeed q = new Succeed(); |
143 |
< |
Integer[] ints = new Integer[SIZE]; |
144 |
< |
q.addAll(Arrays.asList(ints)); |
144 |
> |
q.addAll(Arrays.asList(items)); |
145 |
|
shouldThrow(); |
146 |
|
} catch (NullPointerException success) {} |
147 |
|
} |
151 |
|
* possibly adding some elements |
152 |
|
*/ |
153 |
|
public void testAddAll3() { |
154 |
+ |
Succeed q = new Succeed(); |
155 |
+ |
Item[] items = new Item[SIZE]; |
156 |
+ |
for (int i = 0; i < SIZE - 1; ++i) |
157 |
+ |
items[i] = itemFor(i); |
158 |
|
try { |
159 |
< |
Succeed q = new Succeed(); |
156 |
< |
Integer[] ints = new Integer[SIZE]; |
157 |
< |
for (int i = 0; i < SIZE-1; ++i) |
158 |
< |
ints[i] = new Integer(i); |
159 |
< |
q.addAll(Arrays.asList(ints)); |
159 |
> |
q.addAll(Arrays.asList(items)); |
160 |
|
shouldThrow(); |
161 |
|
} catch (NullPointerException success) {} |
162 |
|
} |
163 |
|
|
164 |
|
/** |
165 |
< |
* addAll throws ISE if an add fails |
165 |
> |
* addAll throws IllegalStateException if an add fails |
166 |
|
*/ |
167 |
|
public void testAddAll4() { |
168 |
+ |
Fail q = new Fail(); |
169 |
+ |
Item[] items = seqItems(SIZE); |
170 |
|
try { |
171 |
< |
Fail q = new Fail(); |
170 |
< |
Integer[] ints = new Integer[SIZE]; |
171 |
< |
for (int i = 0; i < SIZE; ++i) |
172 |
< |
ints[i] = new Integer(i); |
173 |
< |
q.addAll(Arrays.asList(ints)); |
171 |
> |
q.addAll(Arrays.asList(items)); |
172 |
|
shouldThrow(); |
173 |
|
} catch (IllegalStateException success) {} |
174 |
|
} |