358 |
|
*/ |
359 |
|
public void testToArray() { |
360 |
|
LinkedList q = populatedQueue(SIZE); |
361 |
< |
Object[] o = q.toArray(); |
362 |
< |
for (int i = 0; i < o.length; i++) |
363 |
< |
assertSame(o[i], q.poll()); |
361 |
> |
Object[] a = q.toArray(); |
362 |
> |
assertSame(Object[].class, a.getClass()); |
363 |
> |
for (Object o : a) |
364 |
> |
assertSame(o, q.poll()); |
365 |
> |
assertTrue(q.isEmpty()); |
366 |
|
} |
367 |
|
|
368 |
|
/** |
373 |
|
Integer[] ints = new Integer[SIZE]; |
374 |
|
Integer[] array = q.toArray(ints); |
375 |
|
assertSame(ints, array); |
376 |
< |
for (int i = 0; i < ints.length; i++) |
377 |
< |
assertSame(ints[i], q.poll()); |
376 |
> |
for (Integer o : ints) |
377 |
> |
assertSame(o, q.poll()); |
378 |
> |
assertTrue(q.isEmpty()); |
379 |
|
} |
380 |
|
|
381 |
|
/** |
385 |
|
LinkedList l = new LinkedList(); |
386 |
|
l.add(new Object()); |
387 |
|
try { |
388 |
< |
l.toArray(null); |
388 |
> |
l.toArray((Object[])null); |
389 |
|
shouldThrow(); |
390 |
|
} catch (NullPointerException success) {} |
391 |
|
} |