98 |
|
*/ |
99 |
|
public void testConstructor6() { |
100 |
|
Item[] items = defaultItems; |
101 |
< |
ConcurrentLinkedDeque<Item> q = new ConcurrentLinkedDeque<Item>(Arrays.asList(items)); |
101 |
> |
ConcurrentLinkedDeque<Item> q = new ConcurrentLinkedDeque<>(Arrays.asList(items)); |
102 |
|
for (int i = 0; i < SIZE; ++i) |
103 |
|
mustEqual(items[i], q.poll()); |
104 |
|
} |
107 |
|
* isEmpty is true before add, false after |
108 |
|
*/ |
109 |
|
public void testEmpty() { |
110 |
< |
ConcurrentLinkedDeque<Item> q = new ConcurrentLinkedDeque<Item>(); |
110 |
> |
ConcurrentLinkedDeque<Item> q = new ConcurrentLinkedDeque<>(); |
111 |
|
assertTrue(q.isEmpty()); |
112 |
|
q.add(one); |
113 |
|
assertFalse(q.isEmpty()); |
136 |
|
* push(null) throws NPE |
137 |
|
*/ |
138 |
|
public void testPushNull() { |
139 |
< |
ConcurrentLinkedDeque<Item> q = new ConcurrentLinkedDeque<Item>(); |
139 |
> |
ConcurrentLinkedDeque<Item> q = new ConcurrentLinkedDeque<>(); |
140 |
|
try { |
141 |
|
q.push(null); |
142 |
|
shouldThrow(); |
171 |
|
* offer(null) throws NPE |
172 |
|
*/ |
173 |
|
public void testOfferNull() { |
174 |
< |
ConcurrentLinkedDeque<Item> q = new ConcurrentLinkedDeque<Item>(); |
174 |
> |
ConcurrentLinkedDeque<Item> q = new ConcurrentLinkedDeque<>(); |
175 |
|
try { |
176 |
|
q.offer(null); |
177 |
|
shouldThrow(); |
182 |
|
* offerFirst(null) throws NPE |
183 |
|
*/ |
184 |
|
public void testOfferFirstNull() { |
185 |
< |
ConcurrentLinkedDeque<Item> q = new ConcurrentLinkedDeque<Item>(); |
185 |
> |
ConcurrentLinkedDeque<Item> q = new ConcurrentLinkedDeque<>(); |
186 |
|
try { |
187 |
|
q.offerFirst(null); |
188 |
|
shouldThrow(); |
193 |
|
* offerLast(null) throws NPE |
194 |
|
*/ |
195 |
|
public void testOfferLastNull() { |
196 |
< |
ConcurrentLinkedDeque<Item> q = new ConcurrentLinkedDeque<Item>(); |
196 |
> |
ConcurrentLinkedDeque<Item> q = new ConcurrentLinkedDeque<>(); |
197 |
|
try { |
198 |
|
q.offerLast(null); |
199 |
|
shouldThrow(); |
204 |
|
* offer(x) succeeds |
205 |
|
*/ |
206 |
|
public void testOffer() { |
207 |
< |
ConcurrentLinkedDeque<Item> q = new ConcurrentLinkedDeque<Item>(); |
207 |
> |
ConcurrentLinkedDeque<Item> q = new ConcurrentLinkedDeque<>(); |
208 |
|
assertTrue(q.offer(zero)); |
209 |
|
assertTrue(q.offer(one)); |
210 |
|
assertSame(zero, q.peekFirst()); |
215 |
|
* offerFirst(x) succeeds |
216 |
|
*/ |
217 |
|
public void testOfferFirst() { |
218 |
< |
ConcurrentLinkedDeque<Item> q = new ConcurrentLinkedDeque<Item>(); |
218 |
> |
ConcurrentLinkedDeque<Item> q = new ConcurrentLinkedDeque<>(); |
219 |
|
assertTrue(q.offerFirst(zero)); |
220 |
|
assertTrue(q.offerFirst(one)); |
221 |
|
assertSame(one, q.peekFirst()); |
226 |
|
* offerLast(x) succeeds |
227 |
|
*/ |
228 |
|
public void testOfferLast() { |
229 |
< |
ConcurrentLinkedDeque<Item> q = new ConcurrentLinkedDeque<Item>(); |
229 |
> |
ConcurrentLinkedDeque<Item> q = new ConcurrentLinkedDeque<>(); |
230 |
|
assertTrue(q.offerLast(zero)); |
231 |
|
assertTrue(q.offerLast(one)); |
232 |
|
assertSame(zero, q.peekFirst()); |
237 |
|
* add(null) throws NPE |
238 |
|
*/ |
239 |
|
public void testAddNull() { |
240 |
< |
ConcurrentLinkedDeque<Item> q = new ConcurrentLinkedDeque<Item>(); |
240 |
> |
ConcurrentLinkedDeque<Item> q = new ConcurrentLinkedDeque<>(); |
241 |
|
try { |
242 |
|
q.add(null); |
243 |
|
shouldThrow(); |
248 |
|
* addFirst(null) throws NPE |
249 |
|
*/ |
250 |
|
public void testAddFirstNull() { |
251 |
< |
ConcurrentLinkedDeque<Item> q = new ConcurrentLinkedDeque<Item>(); |
251 |
> |
ConcurrentLinkedDeque<Item> q = new ConcurrentLinkedDeque<>(); |
252 |
|
try { |
253 |
|
q.addFirst(null); |
254 |
|
shouldThrow(); |
259 |
|
* addLast(null) throws NPE |
260 |
|
*/ |
261 |
|
public void testAddLastNull() { |
262 |
< |
ConcurrentLinkedDeque<Item> q = new ConcurrentLinkedDeque<Item>(); |
262 |
> |
ConcurrentLinkedDeque<Item> q = new ConcurrentLinkedDeque<>(); |
263 |
|
try { |
264 |
|
q.addLast(null); |
265 |
|
shouldThrow(); |
270 |
|
* add(x) succeeds |
271 |
|
*/ |
272 |
|
public void testAdd() { |
273 |
< |
ConcurrentLinkedDeque<Item> q = new ConcurrentLinkedDeque<Item>(); |
273 |
> |
ConcurrentLinkedDeque<Item> q = new ConcurrentLinkedDeque<>(); |
274 |
|
assertTrue(q.add(zero)); |
275 |
|
assertTrue(q.add(one)); |
276 |
|
assertSame(zero, q.peekFirst()); |
281 |
|
* addFirst(x) succeeds |
282 |
|
*/ |
283 |
|
public void testAddFirst() { |
284 |
< |
ConcurrentLinkedDeque<Item> q = new ConcurrentLinkedDeque<Item>(); |
284 |
> |
ConcurrentLinkedDeque<Item> q = new ConcurrentLinkedDeque<>(); |
285 |
|
q.addFirst(zero); |
286 |
|
q.addFirst(one); |
287 |
|
assertSame(one, q.peekFirst()); |
292 |
|
* addLast(x) succeeds |
293 |
|
*/ |
294 |
|
public void testAddLast() { |
295 |
< |
ConcurrentLinkedDeque<Item> q = new ConcurrentLinkedDeque<Item>(); |
295 |
> |
ConcurrentLinkedDeque<Item> q = new ConcurrentLinkedDeque<>(); |
296 |
|
q.addLast(zero); |
297 |
|
q.addLast(one); |
298 |
|
assertSame(zero, q.peekFirst()); |
303 |
|
* addAll(null) throws NPE |
304 |
|
*/ |
305 |
|
public void testAddAll1() { |
306 |
< |
ConcurrentLinkedDeque<Item> q = new ConcurrentLinkedDeque<Item>(); |
306 |
> |
ConcurrentLinkedDeque<Item> q = new ConcurrentLinkedDeque<>(); |
307 |
|
try { |
308 |
|
q.addAll(null); |
309 |
|
shouldThrow(); |
325 |
|
* addAll of a collection with null elements throws NPE |
326 |
|
*/ |
327 |
|
public void testAddAll2() { |
328 |
< |
ConcurrentLinkedDeque<Item> q = new ConcurrentLinkedDeque<Item>(); |
328 |
> |
ConcurrentLinkedDeque<Item> q = new ConcurrentLinkedDeque<>(); |
329 |
|
try { |
330 |
|
q.addAll(Arrays.asList(new Item[SIZE])); |
331 |
|
shouldThrow(); |
337 |
|
* possibly adding some elements |
338 |
|
*/ |
339 |
|
public void testAddAll3() { |
340 |
< |
ConcurrentLinkedDeque<Item> q = new ConcurrentLinkedDeque<Item>(); |
340 |
> |
ConcurrentLinkedDeque<Item> q = new ConcurrentLinkedDeque<>(); |
341 |
|
Item[] items = new Item[2]; items[0] = zero; |
342 |
|
try { |
343 |
|
q.addAll(Arrays.asList(items)); |
351 |
|
public void testAddAll5() { |
352 |
|
Item[] empty = new Item[0]; |
353 |
|
Item[] items = defaultItems; |
354 |
< |
ConcurrentLinkedDeque<Item> q = new ConcurrentLinkedDeque<Item>(); |
354 |
> |
ConcurrentLinkedDeque<Item> q = new ConcurrentLinkedDeque<>(); |
355 |
|
assertFalse(q.addAll(Arrays.asList(empty))); |
356 |
|
assertTrue(q.addAll(Arrays.asList(items))); |
357 |
|
for (int i = 0; i < SIZE; ++i) |
605 |
|
*/ |
606 |
|
public void testContainsAll() { |
607 |
|
ConcurrentLinkedDeque<Item> q = populatedDeque(SIZE); |
608 |
< |
ConcurrentLinkedDeque<Item> p = new ConcurrentLinkedDeque<Item>(); |
608 |
> |
ConcurrentLinkedDeque<Item> p = new ConcurrentLinkedDeque<>(); |
609 |
|
for (int i = 0; i < SIZE; ++i) { |
610 |
|
assertTrue(q.containsAll(p)); |
611 |
|
assertFalse(p.containsAll(q)); |
712 |
|
* iterator of empty collection has no elements |
713 |
|
*/ |
714 |
|
public void testEmptyIterator() { |
715 |
< |
Deque<Item> c = new ConcurrentLinkedDeque<Item>(); |
715 |
> |
Deque<Item> c = new ConcurrentLinkedDeque<>(); |
716 |
|
assertIteratorExhausted(c.iterator()); |
717 |
|
assertIteratorExhausted(c.descendingIterator()); |
718 |
|
} |
721 |
|
* Iterator ordering is FIFO |
722 |
|
*/ |
723 |
|
public void testIteratorOrdering() { |
724 |
< |
final ConcurrentLinkedDeque<Item> q = new ConcurrentLinkedDeque<Item>(); |
724 |
> |
final ConcurrentLinkedDeque<Item> q = new ConcurrentLinkedDeque<>(); |
725 |
|
q.add(one); |
726 |
|
q.add(two); |
727 |
|
q.add(three); |
738 |
|
* Modifications do not cause iterators to fail |
739 |
|
*/ |
740 |
|
public void testWeaklyConsistentIteration() { |
741 |
< |
final ConcurrentLinkedDeque<Item> q = new ConcurrentLinkedDeque<Item>(); |
741 |
> |
final ConcurrentLinkedDeque<Item> q = new ConcurrentLinkedDeque<>(); |
742 |
|
q.add(one); |
743 |
|
q.add(two); |
744 |
|
q.add(three); |
755 |
|
* iterator.remove() removes current element |
756 |
|
*/ |
757 |
|
public void testIteratorRemove() { |
758 |
< |
final ConcurrentLinkedDeque<Item> q = new ConcurrentLinkedDeque<Item>(); |
758 |
> |
final ConcurrentLinkedDeque<Item> q = new ConcurrentLinkedDeque<>(); |
759 |
|
final Random rng = new Random(); |
760 |
|
for (int iters = 0; iters < 100; ++iters) { |
761 |
|
int max = rng.nextInt(5) + 2; |
802 |
|
* Descending iterator ordering is reverse FIFO |
803 |
|
*/ |
804 |
|
public void testDescendingIteratorOrdering() { |
805 |
< |
final ConcurrentLinkedDeque<Item> q = new ConcurrentLinkedDeque<Item>(); |
805 |
> |
final ConcurrentLinkedDeque<Item> q = new ConcurrentLinkedDeque<>(); |
806 |
|
for (int iters = 0; iters < 100; ++iters) { |
807 |
|
mustAdd(q, three); |
808 |
|
mustAdd(q, two); |
823 |
|
* descendingIterator.remove() removes current element |
824 |
|
*/ |
825 |
|
public void testDescendingIteratorRemove() { |
826 |
< |
final ConcurrentLinkedDeque<Item> q = new ConcurrentLinkedDeque<Item>(); |
826 |
> |
final ConcurrentLinkedDeque<Item> q = new ConcurrentLinkedDeque<>(); |
827 |
|
final Random rng = new Random(); |
828 |
|
for (int iters = 0; iters < 100; ++iters) { |
829 |
|
int max = rng.nextInt(5) + 2; |
882 |
|
*/ |
883 |
|
public void testNeverContainsNull() { |
884 |
|
Deque<?>[] qs = { |
885 |
< |
new ConcurrentLinkedDeque<Object>(), |
885 |
> |
new ConcurrentLinkedDeque<>(), |
886 |
|
populatedDeque(2), |
887 |
|
}; |
888 |
|
|