25 |
|
* Create a queue of given size containing consecutive |
26 |
|
* Integers 0 ... n. |
27 |
|
*/ |
28 |
< |
private ConcurrentLinkedQueue populatedQueue(int n) { |
29 |
< |
ConcurrentLinkedQueue q = new ConcurrentLinkedQueue(); |
28 |
> |
private ConcurrentLinkedQueue<Integer> populatedQueue(int n) { |
29 |
> |
ConcurrentLinkedQueue<Integer> q = new ConcurrentLinkedQueue<Integer>(); |
30 |
|
assertTrue(q.isEmpty()); |
31 |
|
for (int i = 0; i < n; ++i) |
32 |
|
assertTrue(q.offer(new Integer(i))); |
369 |
|
} |
370 |
|
|
371 |
|
/** |
372 |
< |
* toArray contains all elements |
372 |
> |
* toArray contains all elements in FIFO order |
373 |
|
*/ |
374 |
|
public void testToArray() { |
375 |
|
ConcurrentLinkedQueue q = populatedQueue(SIZE); |
376 |
|
Object[] o = q.toArray(); |
377 |
– |
Arrays.sort(o); |
377 |
|
for (int i = 0; i < o.length; i++) |
378 |
< |
assertEquals(o[i], q.poll()); |
378 |
> |
assertSame(o[i], q.poll()); |
379 |
|
} |
380 |
|
|
381 |
|
/** |
382 |
< |
* toArray(a) contains all elements |
382 |
> |
* toArray(a) contains all elements in FIFO order |
383 |
|
*/ |
384 |
|
public void testToArray2() { |
385 |
< |
ConcurrentLinkedQueue q = populatedQueue(SIZE); |
385 |
> |
ConcurrentLinkedQueue<Integer> q = populatedQueue(SIZE); |
386 |
|
Integer[] ints = new Integer[SIZE]; |
387 |
< |
ints = (Integer[])q.toArray(ints); |
388 |
< |
Arrays.sort(ints); |
387 |
> |
Integer[] array = q.toArray(ints); |
388 |
> |
assertSame(ints, array); |
389 |
|
for (int i = 0; i < ints.length; i++) |
390 |
< |
assertEquals(ints[i], q.poll()); |
390 |
> |
assertSame(ints[i], q.poll()); |
391 |
|
} |
392 |
|
|
393 |
|
/** |
394 |
< |
* toArray(null) throws NPE |
394 |
> |
* toArray(null) throws NullPointerException |
395 |
|
*/ |
396 |
< |
public void testToArray_BadArg() { |
396 |
> |
public void testToArray_NullArg() { |
397 |
|
ConcurrentLinkedQueue q = populatedQueue(SIZE); |
398 |
|
try { |
399 |
< |
Object o[] = q.toArray(null); |
399 |
> |
q.toArray(null); |
400 |
|
shouldThrow(); |
401 |
|
} catch (NullPointerException success) {} |
402 |
|
} |
403 |
|
|
404 |
|
/** |
405 |
< |
* toArray with incompatible array type throws ArrayStoreException |
405 |
> |
* toArray(incompatible array type) throws ArrayStoreException |
406 |
|
*/ |
407 |
|
public void testToArray1_BadArg() { |
408 |
|
ConcurrentLinkedQueue q = populatedQueue(SIZE); |
409 |
|
try { |
410 |
< |
Object o[] = q.toArray(new String[10]); |
410 |
> |
q.toArray(new String[10]); |
411 |
|
shouldThrow(); |
412 |
|
} catch (ArrayStoreException success) {} |
413 |
|
} |