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 |
|
|
15 |
|
|
16 |
|
public class AbstractQueueTest extends JSR166TestCase { |
17 |
|
public static void main(String[] args) { |
18 |
< |
junit.textui.TestRunner.run (suite()); |
18 |
> |
junit.textui.TestRunner.run(suite()); |
19 |
|
} |
20 |
|
public static Test suite() { |
21 |
|
return new TestSuite(AbstractQueueTest.class); |
22 |
|
} |
23 |
|
|
24 |
|
static class Succeed extends AbstractQueue<Integer> { |
25 |
< |
public boolean offer(Integer x) { |
25 |
> |
public boolean offer(Integer x) { |
26 |
|
if (x == null) throw new NullPointerException(); |
27 |
< |
return true; |
27 |
> |
return true; |
28 |
|
} |
29 |
|
public Integer peek() { return one; } |
30 |
|
public Integer poll() { return one; } |
33 |
|
} |
34 |
|
|
35 |
|
static class Fail extends AbstractQueue<Integer> { |
36 |
< |
public boolean offer(Integer x) { |
36 |
> |
public boolean offer(Integer x) { |
37 |
|
if (x == null) throw new NullPointerException(); |
38 |
< |
return false; |
38 |
> |
return false; |
39 |
|
} |
40 |
|
public Integer peek() { return null; } |
41 |
|
public Integer poll() { return null; } |
59 |
|
try { |
60 |
|
q.add(one); |
61 |
|
shouldThrow(); |
62 |
< |
} catch (IllegalStateException success) { |
63 |
< |
} |
62 |
> |
} catch (IllegalStateException success) {} |
63 |
|
} |
64 |
|
|
65 |
|
/** |
70 |
|
try { |
71 |
|
q.add(null); |
72 |
|
shouldThrow(); |
73 |
< |
} catch (NullPointerException success) { |
75 |
< |
} |
73 |
> |
} catch (NullPointerException success) {} |
74 |
|
} |
75 |
|
|
76 |
|
/** |
89 |
|
try { |
90 |
|
q.remove(); |
91 |
|
shouldThrow(); |
92 |
< |
} catch (NoSuchElementException success) { |
95 |
< |
} |
92 |
> |
} catch (NoSuchElementException success) {} |
93 |
|
} |
94 |
|
|
95 |
|
|
109 |
|
try { |
110 |
|
q.element(); |
111 |
|
shouldThrow(); |
112 |
< |
} catch (NoSuchElementException success) { |
116 |
< |
} |
112 |
> |
} catch (NoSuchElementException success) {} |
113 |
|
} |
114 |
|
|
115 |
|
/** |
120 |
|
Succeed q = new Succeed(); |
121 |
|
q.addAll(null); |
122 |
|
shouldThrow(); |
123 |
< |
} |
128 |
< |
catch (NullPointerException success) {} |
123 |
> |
} catch (NullPointerException success) {} |
124 |
|
} |
125 |
|
|
126 |
|
/** |
131 |
|
Succeed q = new Succeed(); |
132 |
|
q.addAll(q); |
133 |
|
shouldThrow(); |
134 |
< |
} |
140 |
< |
catch (IllegalArgumentException success) {} |
134 |
> |
} catch (IllegalArgumentException success) {} |
135 |
|
} |
136 |
|
|
137 |
|
|
144 |
|
Integer[] ints = new Integer[SIZE]; |
145 |
|
q.addAll(Arrays.asList(ints)); |
146 |
|
shouldThrow(); |
147 |
< |
} |
154 |
< |
catch (NullPointerException success) {} |
147 |
> |
} catch (NullPointerException success) {} |
148 |
|
} |
149 |
+ |
|
150 |
|
/** |
151 |
|
* addAll of a collection with any null elements throws NPE after |
152 |
|
* possibly adding some elements |
159 |
|
ints[i] = new Integer(i); |
160 |
|
q.addAll(Arrays.asList(ints)); |
161 |
|
shouldThrow(); |
162 |
< |
} |
169 |
< |
catch (NullPointerException success) {} |
162 |
> |
} catch (NullPointerException success) {} |
163 |
|
} |
164 |
+ |
|
165 |
|
/** |
166 |
|
* addAll throws ISE if an add fails |
167 |
|
*/ |
173 |
|
ints[i] = new Integer(i); |
174 |
|
q.addAll(Arrays.asList(ints)); |
175 |
|
shouldThrow(); |
176 |
< |
} |
183 |
< |
catch (IllegalStateException success) {} |
176 |
> |
} catch (IllegalStateException success) {} |
177 |
|
} |
178 |
|
|
179 |
|
} |