35 |
|
} |
36 |
|
|
37 |
|
/** |
38 |
< |
* |
38 |
> |
* new queue is empty |
39 |
|
*/ |
40 |
|
public void testConstructor1() { |
41 |
|
assertEquals(0, new ConcurrentLinkedQueue().size()); |
42 |
|
} |
43 |
|
|
44 |
|
/** |
45 |
< |
* |
45 |
> |
* Initializing from null Collection throws NPE |
46 |
|
*/ |
47 |
|
public void testConstructor3() { |
48 |
|
try { |
53 |
|
} |
54 |
|
|
55 |
|
/** |
56 |
< |
* |
56 |
> |
* Initializing from Collection of null elements throws NPE |
57 |
|
*/ |
58 |
|
public void testConstructor4() { |
59 |
|
try { |
65 |
|
} |
66 |
|
|
67 |
|
/** |
68 |
< |
* |
68 |
> |
* Initializing from Collection with some null elements throws NPE |
69 |
|
*/ |
70 |
|
public void testConstructor5() { |
71 |
|
try { |
79 |
|
} |
80 |
|
|
81 |
|
/** |
82 |
< |
* |
82 |
> |
* Queue contains all elements of collection used to initialize |
83 |
|
*/ |
84 |
|
public void testConstructor6() { |
85 |
|
try { |
94 |
|
} |
95 |
|
|
96 |
|
/** |
97 |
< |
* |
97 |
> |
* isEmpty is true before add, false after |
98 |
|
*/ |
99 |
|
public void testEmpty() { |
100 |
|
ConcurrentLinkedQueue q = new ConcurrentLinkedQueue(); |
108 |
|
} |
109 |
|
|
110 |
|
/** |
111 |
< |
* |
111 |
> |
* size changes when elements added and removed |
112 |
|
*/ |
113 |
|
public void testSize() { |
114 |
|
ConcurrentLinkedQueue q = populatedQueue(SIZE); |
123 |
|
} |
124 |
|
|
125 |
|
/** |
126 |
< |
* |
126 |
> |
* offer(null) throws NPE |
127 |
|
*/ |
128 |
|
public void testOfferNull() { |
129 |
|
try { |
134 |
|
} |
135 |
|
|
136 |
|
/** |
137 |
< |
* |
137 |
> |
* add(null) throws NPE |
138 |
> |
*/ |
139 |
> |
public void testAddNull() { |
140 |
> |
try { |
141 |
> |
ConcurrentLinkedQueue q = new ConcurrentLinkedQueue(); |
142 |
> |
q.add(null); |
143 |
> |
shouldThrow(); |
144 |
> |
} catch (NullPointerException success) { } |
145 |
> |
} |
146 |
> |
|
147 |
> |
|
148 |
> |
/** |
149 |
> |
* Offer returns true |
150 |
|
*/ |
151 |
|
public void testOffer() { |
152 |
|
ConcurrentLinkedQueue q = new ConcurrentLinkedQueue(); |
155 |
|
} |
156 |
|
|
157 |
|
/** |
158 |
< |
* |
158 |
> |
* add returns true |
159 |
|
*/ |
160 |
|
public void testAdd() { |
161 |
|
ConcurrentLinkedQueue q = new ConcurrentLinkedQueue(); |
166 |
|
} |
167 |
|
|
168 |
|
/** |
169 |
< |
* |
169 |
> |
* addAll(null) throws NPE |
170 |
|
*/ |
171 |
|
public void testAddAll1() { |
172 |
|
try { |
176 |
|
} |
177 |
|
catch (NullPointerException success) {} |
178 |
|
} |
179 |
+ |
|
180 |
+ |
/** |
181 |
+ |
* addAll(this) throws IAE |
182 |
+ |
*/ |
183 |
+ |
public void testAddAllSelf() { |
184 |
+ |
try { |
185 |
+ |
ConcurrentLinkedQueue q = populatedQueue(SIZE); |
186 |
+ |
q.addAll(q); |
187 |
+ |
shouldThrow(); |
188 |
+ |
} |
189 |
+ |
catch (IllegalArgumentException success) {} |
190 |
+ |
} |
191 |
+ |
|
192 |
|
/** |
193 |
< |
* |
193 |
> |
* addAll of a collection with null elements throws NPE |
194 |
|
*/ |
195 |
|
public void testAddAll2() { |
196 |
|
try { |
202 |
|
catch (NullPointerException success) {} |
203 |
|
} |
204 |
|
/** |
205 |
< |
* |
205 |
> |
* addAll of a collection with any null elements throws NPE after |
206 |
> |
* possibly adding some elements |
207 |
|
*/ |
208 |
|
public void testAddAll3() { |
209 |
|
try { |
218 |
|
} |
219 |
|
|
220 |
|
/** |
221 |
< |
* |
221 |
> |
* Queue contains all elements, in traversal order, of successful addAll |
222 |
|
*/ |
223 |
|
public void testAddAll5() { |
224 |
|
try { |
236 |
|
} |
237 |
|
|
238 |
|
/** |
239 |
< |
* |
239 |
> |
* poll succeeds unless empty |
240 |
|
*/ |
241 |
|
public void testPoll() { |
242 |
|
ConcurrentLinkedQueue q = populatedQueue(SIZE); |
247 |
|
} |
248 |
|
|
249 |
|
/** |
250 |
< |
* |
250 |
> |
* peek returns next element, or null if empty |
251 |
|
*/ |
252 |
|
public void testPeek() { |
253 |
|
ConcurrentLinkedQueue q = populatedQueue(SIZE); |
261 |
|
} |
262 |
|
|
263 |
|
/** |
264 |
< |
* |
264 |
> |
* element returns next element, or throws NSEE if empty |
265 |
|
*/ |
266 |
|
public void testElement() { |
267 |
|
ConcurrentLinkedQueue q = populatedQueue(SIZE); |
277 |
|
} |
278 |
|
|
279 |
|
/** |
280 |
< |
* |
280 |
> |
* remove removes next element, or throws NSEE if empty |
281 |
|
*/ |
282 |
|
public void testRemove() { |
283 |
|
ConcurrentLinkedQueue q = populatedQueue(SIZE); |
292 |
|
} |
293 |
|
|
294 |
|
/** |
295 |
< |
* |
295 |
> |
* remove(x) removes x and returns true if present |
296 |
|
*/ |
297 |
|
public void testRemoveElement() { |
298 |
|
ConcurrentLinkedQueue q = populatedQueue(SIZE); |
307 |
|
} |
308 |
|
|
309 |
|
/** |
310 |
< |
* |
310 |
> |
* contains(x) reports true when elements added but not yet removed |
311 |
|
*/ |
312 |
|
public void testContains() { |
313 |
|
ConcurrentLinkedQueue q = populatedQueue(SIZE); |
319 |
|
} |
320 |
|
|
321 |
|
/** |
322 |
< |
* |
322 |
> |
* clear removes all elements |
323 |
|
*/ |
324 |
|
public void testClear() { |
325 |
|
ConcurrentLinkedQueue q = populatedQueue(SIZE); |
333 |
|
} |
334 |
|
|
335 |
|
/** |
336 |
< |
* |
336 |
> |
* containsAll(c) is true when c contains a subset of elements |
337 |
|
*/ |
338 |
|
public void testContainsAll() { |
339 |
|
ConcurrentLinkedQueue q = populatedQueue(SIZE); |
347 |
|
} |
348 |
|
|
349 |
|
/** |
350 |
< |
* |
350 |
> |
* retainAll(c) retains only those elements of c and reports true if change |
351 |
|
*/ |
352 |
|
public void testRetainAll() { |
353 |
|
ConcurrentLinkedQueue q = populatedQueue(SIZE); |
366 |
|
} |
367 |
|
|
368 |
|
/** |
369 |
< |
* |
369 |
> |
* removeAll(c) removes only those elements of c and reports true if changed |
370 |
|
*/ |
371 |
|
public void testRemoveAll() { |
372 |
|
for (int i = 1; i < SIZE; ++i) { |
382 |
|
} |
383 |
|
|
384 |
|
/** |
385 |
< |
* |
385 |
> |
* toArray contains all elements |
386 |
|
*/ |
387 |
|
public void testToArray() { |
388 |
|
ConcurrentLinkedQueue q = populatedQueue(SIZE); |
393 |
|
} |
394 |
|
|
395 |
|
/** |
396 |
< |
* |
396 |
> |
* toArray(a) contains all elements |
397 |
|
*/ |
398 |
|
public void testToArray2() { |
399 |
|
ConcurrentLinkedQueue q = populatedQueue(SIZE); |
403 |
|
for(int i = 0; i < ints.length; i++) |
404 |
|
assertEquals(ints[i], q.poll()); |
405 |
|
} |
406 |
+ |
|
407 |
+ |
/** |
408 |
+ |
* toArray(null) throws NPE |
409 |
+ |
*/ |
410 |
+ |
public void testToArray_BadArg() { |
411 |
+ |
try { |
412 |
+ |
ConcurrentLinkedQueue q = populatedQueue(SIZE); |
413 |
+ |
Object o[] = q.toArray(null); |
414 |
+ |
shouldThrow(); |
415 |
+ |
} catch(NullPointerException success){} |
416 |
+ |
} |
417 |
+ |
|
418 |
+ |
/** |
419 |
+ |
* toArray with incompatable array type throws CCE |
420 |
+ |
*/ |
421 |
+ |
public void testToArray1_BadArg() { |
422 |
+ |
try { |
423 |
+ |
ConcurrentLinkedQueue q = populatedQueue(SIZE); |
424 |
+ |
Object o[] = q.toArray(new String[10] ); |
425 |
+ |
shouldThrow(); |
426 |
+ |
} catch(ArrayStoreException success){} |
427 |
+ |
} |
428 |
|
|
429 |
|
/** |
430 |
< |
* |
430 |
> |
* iterator iterates through all elements |
431 |
|
*/ |
432 |
|
public void testIterator() { |
433 |
|
ConcurrentLinkedQueue q = populatedQueue(SIZE); |
441 |
|
} |
442 |
|
|
443 |
|
/** |
444 |
< |
* |
444 |
> |
* iterator ordering is FIFO |
445 |
|
*/ |
446 |
|
public void testIteratorOrdering() { |
447 |
|
final ConcurrentLinkedQueue q = new ConcurrentLinkedQueue(); |
459 |
|
} |
460 |
|
|
461 |
|
/** |
462 |
< |
* |
462 |
> |
* Modifications do not cause iterators to fail |
463 |
|
*/ |
464 |
|
public void testWeaklyConsistentIteration () { |
465 |
|
final ConcurrentLinkedQueue q = new ConcurrentLinkedQueue(); |
481 |
|
} |
482 |
|
|
483 |
|
/** |
484 |
< |
* |
484 |
> |
* iterator.remove removes current element |
485 |
|
*/ |
486 |
|
public void testIteratorRemove () { |
487 |
|
final ConcurrentLinkedQueue q = new ConcurrentLinkedQueue(); |
499 |
|
|
500 |
|
|
501 |
|
/** |
502 |
< |
* |
502 |
> |
* toString contains toStrings of elements |
503 |
|
*/ |
504 |
|
public void testToString() { |
505 |
|
ConcurrentLinkedQueue q = populatedQueue(SIZE); |
510 |
|
} |
511 |
|
|
512 |
|
/** |
513 |
< |
* |
513 |
> |
* A deserialized serialized queue has same elements in same order |
514 |
|
*/ |
515 |
|
public void testSerialization() { |
516 |
|
ConcurrentLinkedQueue q = populatedQueue(SIZE); |