17 |
|
import java.util.NoSuchElementException; |
18 |
|
import java.util.Queue; |
19 |
|
import java.util.Spliterator; |
20 |
+ |
import java.util.concurrent.BlockingDeque; |
21 |
+ |
import java.util.concurrent.BlockingQueue; |
22 |
|
import java.util.concurrent.CountDownLatch; |
23 |
|
import java.util.concurrent.Executors; |
24 |
|
import java.util.concurrent.ExecutorService; |
59 |
|
} |
60 |
|
|
61 |
|
/** Checks properties of empty collections. */ |
62 |
< |
public void testEmptyMeansEmpty() { |
62 |
> |
public void testEmptyMeansEmpty() throws InterruptedException { |
63 |
|
Collection c = impl.emptyCollection(); |
64 |
|
emptyMeansEmpty(c); |
65 |
|
|
71 |
|
emptyMeansEmpty(clone); |
72 |
|
} |
73 |
|
|
74 |
< |
void emptyMeansEmpty(Collection c) { |
74 |
> |
void emptyMeansEmpty(Collection c) throws InterruptedException { |
75 |
|
assertTrue(c.isEmpty()); |
76 |
|
assertEquals(0, c.size()); |
77 |
|
assertEquals("[]", c.toString()); |
121 |
|
assertFalse(d.removeFirstOccurrence(bomb())); |
122 |
|
assertFalse(d.removeLastOccurrence(bomb())); |
123 |
|
} |
124 |
+ |
if (c instanceof BlockingQueue) { |
125 |
+ |
BlockingQueue q = (BlockingQueue) c; |
126 |
+ |
assertNull(q.poll(0L, MILLISECONDS)); |
127 |
+ |
} |
128 |
+ |
if (c instanceof BlockingDeque) { |
129 |
+ |
BlockingDeque q = (BlockingDeque) c; |
130 |
+ |
assertNull(q.pollFirst(0L, MILLISECONDS)); |
131 |
+ |
assertNull(q.pollLast(0L, MILLISECONDS)); |
132 |
+ |
} |
133 |
|
} |
134 |
|
|
135 |
< |
public void testNullPointerExceptions() { |
135 |
> |
public void testNullPointerExceptions() throws InterruptedException { |
136 |
|
Collection c = impl.emptyCollection(); |
137 |
|
assertThrows( |
138 |
|
NullPointerException.class, |
152 |
|
NullPointerException.class, |
153 |
|
() -> c.add(null)); |
154 |
|
} |
155 |
< |
if (!impl.permitsNulls() |
145 |
< |
&& Queue.class.isAssignableFrom(impl.klazz())) { |
155 |
> |
if (!impl.permitsNulls() && c instanceof Queue) { |
156 |
|
Queue q = (Queue) c; |
157 |
|
assertThrows( |
158 |
|
NullPointerException.class, |
159 |
|
() -> q.offer(null)); |
160 |
|
} |
161 |
< |
if (!impl.permitsNulls() |
152 |
< |
&& Deque.class.isAssignableFrom(impl.klazz())) { |
161 |
> |
if (!impl.permitsNulls() && c instanceof Deque) { |
162 |
|
Deque d = (Deque) c; |
163 |
|
assertThrows( |
164 |
|
NullPointerException.class, |
169 |
|
() -> d.push(null), |
170 |
|
() -> d.descendingIterator().forEachRemaining(null)); |
171 |
|
} |
172 |
+ |
if (!impl.permitsNulls() && c instanceof BlockingQueue) { |
173 |
+ |
BlockingQueue q = (BlockingQueue) c; |
174 |
+ |
assertThrows( |
175 |
+ |
NullPointerException.class, |
176 |
+ |
() -> { |
177 |
+ |
try { q.offer(null, 1L, MILLISECONDS); } |
178 |
+ |
catch (InterruptedException ex) { |
179 |
+ |
throw new AssertionError(ex); |
180 |
+ |
}}); |
181 |
+ |
} |
182 |
+ |
if (!impl.permitsNulls() && c instanceof BlockingDeque) { |
183 |
+ |
BlockingDeque q = (BlockingDeque) c; |
184 |
+ |
assertThrows( |
185 |
+ |
NullPointerException.class, |
186 |
+ |
() -> { |
187 |
+ |
try { q.offerFirst(null, 1L, MILLISECONDS); } |
188 |
+ |
catch (InterruptedException ex) { |
189 |
+ |
throw new AssertionError(ex); |
190 |
+ |
}}, |
191 |
+ |
() -> { |
192 |
+ |
try { q.offerLast(null, 1L, MILLISECONDS); } |
193 |
+ |
catch (InterruptedException ex) { |
194 |
+ |
throw new AssertionError(ex); |
195 |
+ |
}}); |
196 |
+ |
} |
197 |
|
} |
198 |
|
|
199 |
|
public void testNoSuchElementExceptions() { |
202 |
|
NoSuchElementException.class, |
203 |
|
() -> c.iterator().next()); |
204 |
|
|
205 |
< |
if (Queue.class.isAssignableFrom(impl.klazz())) { |
205 |
> |
if (c instanceof Queue) { |
206 |
|
Queue q = (Queue) c; |
207 |
|
assertThrows( |
208 |
|
NoSuchElementException.class, |
209 |
|
() -> q.element(), |
210 |
|
() -> q.remove()); |
211 |
|
} |
212 |
< |
if (Deque.class.isAssignableFrom(impl.klazz())) { |
212 |
> |
if (c instanceof Deque) { |
213 |
|
Deque d = (Deque) c; |
214 |
|
assertThrows( |
215 |
|
NoSuchElementException.class, |