1 |
|
/* |
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 |
4 |
> |
* http://creativecommons.org/publicdomain/zero/1.0/ |
5 |
|
* Other contributors include Andrew Wright, Jeffrey Hayes, |
6 |
|
* Pat Fisher, Mike Judd. |
7 |
|
*/ |
8 |
|
|
9 |
– |
|
9 |
|
import junit.framework.*; |
10 |
< |
import java.util.*; |
11 |
< |
import java.util.concurrent.*; |
12 |
< |
import java.util.concurrent.locks.*; |
13 |
< |
import java.io.*; |
10 |
> |
import java.util.AbstractQueue; |
11 |
> |
import java.util.Arrays; |
12 |
> |
import java.util.Iterator; |
13 |
> |
import java.util.NoSuchElementException; |
14 |
|
|
15 |
|
public class AbstractQueueTest extends JSR166TestCase { |
16 |
|
public static void main(String[] args) { |
17 |
< |
junit.textui.TestRunner.run (suite()); |
17 |
> |
junit.textui.TestRunner.run(suite()); |
18 |
|
} |
19 |
|
public static Test suite() { |
20 |
|
return new TestSuite(AbstractQueueTest.class); |
58 |
|
try { |
59 |
|
q.add(one); |
60 |
|
shouldThrow(); |
61 |
< |
} catch (IllegalStateException success) { |
63 |
< |
} |
61 |
> |
} catch (IllegalStateException success) {} |
62 |
|
} |
63 |
|
|
64 |
|
/** |
69 |
|
try { |
70 |
|
q.add(null); |
71 |
|
shouldThrow(); |
72 |
< |
} catch (NullPointerException success) { |
75 |
< |
} |
72 |
> |
} catch (NullPointerException success) {} |
73 |
|
} |
74 |
|
|
75 |
|
/** |
88 |
|
try { |
89 |
|
q.remove(); |
90 |
|
shouldThrow(); |
91 |
< |
} catch (NoSuchElementException success) { |
95 |
< |
} |
91 |
> |
} catch (NoSuchElementException success) {} |
92 |
|
} |
93 |
|
|
98 |
– |
|
94 |
|
/** |
95 |
|
* element returns normally if peek succeeds |
96 |
|
*/ |
107 |
|
try { |
108 |
|
q.element(); |
109 |
|
shouldThrow(); |
110 |
< |
} catch (NoSuchElementException success) { |
116 |
< |
} |
110 |
> |
} catch (NoSuchElementException success) {} |
111 |
|
} |
112 |
|
|
113 |
|
/** |
114 |
< |
* addAll(null) throws NPE |
114 |
> |
* addAll(null) throws NPE |
115 |
|
*/ |
116 |
|
public void testAddAll1() { |
117 |
|
try { |
118 |
|
Succeed q = new Succeed(); |
119 |
|
q.addAll(null); |
120 |
|
shouldThrow(); |
121 |
< |
} |
128 |
< |
catch (NullPointerException success) {} |
121 |
> |
} catch (NullPointerException success) {} |
122 |
|
} |
123 |
|
|
124 |
|
/** |
129 |
|
Succeed q = new Succeed(); |
130 |
|
q.addAll(q); |
131 |
|
shouldThrow(); |
132 |
< |
} |
140 |
< |
catch (IllegalArgumentException success) {} |
132 |
> |
} catch (IllegalArgumentException success) {} |
133 |
|
} |
134 |
|
|
143 |
– |
|
135 |
|
/** |
136 |
< |
* addAll of a collection with null elements throws NPE |
136 |
> |
* addAll of a collection with null elements throws NPE |
137 |
|
*/ |
138 |
|
public void testAddAll2() { |
139 |
|
try { |
141 |
|
Integer[] ints = new Integer[SIZE]; |
142 |
|
q.addAll(Arrays.asList(ints)); |
143 |
|
shouldThrow(); |
144 |
< |
} |
154 |
< |
catch (NullPointerException success) {} |
144 |
> |
} catch (NullPointerException success) {} |
145 |
|
} |
146 |
+ |
|
147 |
|
/** |
148 |
|
* addAll of a collection with any null elements throws NPE after |
149 |
|
* possibly adding some elements |
156 |
|
ints[i] = new Integer(i); |
157 |
|
q.addAll(Arrays.asList(ints)); |
158 |
|
shouldThrow(); |
159 |
< |
} |
169 |
< |
catch (NullPointerException success) {} |
159 |
> |
} catch (NullPointerException success) {} |
160 |
|
} |
161 |
+ |
|
162 |
|
/** |
163 |
|
* addAll throws ISE if an add fails |
164 |
|
*/ |
170 |
|
ints[i] = new Integer(i); |
171 |
|
q.addAll(Arrays.asList(ints)); |
172 |
|
shouldThrow(); |
173 |
< |
} |
183 |
< |
catch (IllegalStateException success) {} |
173 |
> |
} catch (IllegalStateException success) {} |
174 |
|
} |
175 |
|
|
176 |
|
} |