26 |
|
* Create a deque of given size containing consecutive |
27 |
|
* Integers 0 ... n. |
28 |
|
*/ |
29 |
< |
private ArrayDeque populatedDeque(int n) { |
30 |
< |
ArrayDeque q = new ArrayDeque(); |
29 |
> |
private ArrayDeque<Integer> populatedDeque(int n) { |
30 |
> |
ArrayDeque<Integer> q = new ArrayDeque<Integer>(); |
31 |
|
assertTrue(q.isEmpty()); |
32 |
|
for (int i = 0; i < n; ++i) |
33 |
|
assertTrue(q.offerLast(new Integer(i))); |
620 |
|
} |
621 |
|
|
622 |
|
/** |
623 |
< |
* toArray() contains all elements |
623 |
> |
* toArray() contains all elements in FIFO order |
624 |
|
*/ |
625 |
|
public void testToArray() { |
626 |
|
ArrayDeque q = populatedDeque(SIZE); |
627 |
|
Object[] o = q.toArray(); |
628 |
– |
Arrays.sort(o); |
628 |
|
for (int i = 0; i < o.length; i++) |
629 |
< |
assertEquals(o[i], q.pollFirst()); |
629 |
> |
assertSame(o[i], q.pollFirst()); |
630 |
|
} |
631 |
|
|
632 |
|
/** |
633 |
< |
* toArray(a) contains all elements |
633 |
> |
* toArray(a) contains all elements in FIFO order |
634 |
|
*/ |
635 |
|
public void testToArray2() { |
636 |
< |
ArrayDeque q = populatedDeque(SIZE); |
636 |
> |
ArrayDeque<Integer> q = populatedDeque(SIZE); |
637 |
|
Integer[] ints = new Integer[SIZE]; |
638 |
< |
ints = (Integer[])q.toArray(ints); |
639 |
< |
Arrays.sort(ints); |
638 |
> |
Integer[] array = q.toArray(ints); |
639 |
> |
assertSame(ints, array); |
640 |
|
for (int i = 0; i < ints.length; i++) |
641 |
< |
assertEquals(ints[i], q.pollFirst()); |
641 |
> |
assertSame(ints[i], q.remove()); |
642 |
|
} |
643 |
|
|
644 |
|
/** |
645 |
< |
* toArray(null) throws NPE |
645 |
> |
* toArray(null) throws NullPointerException |
646 |
|
*/ |
647 |
< |
public void testToArray_BadArg() { |
647 |
> |
public void testToArray_NullArg() { |
648 |
|
ArrayDeque l = new ArrayDeque(); |
649 |
|
l.add(new Object()); |
650 |
|
try { |
651 |
< |
Object o[] = l.toArray(null); |
651 |
> |
l.toArray(null); |
652 |
|
shouldThrow(); |
653 |
|
} catch (NullPointerException success) {} |
654 |
|
} |
655 |
|
|
656 |
|
/** |
657 |
< |
* toArray with incompatible array type throws CCE |
657 |
> |
* toArray(incompatible array type) throws ArrayStoreException |
658 |
|
*/ |
659 |
|
public void testToArray1_BadArg() { |
660 |
|
ArrayDeque l = new ArrayDeque(); |
661 |
|
l.add(new Integer(5)); |
662 |
|
try { |
663 |
< |
Object o[] = l.toArray(new String[10]); |
663 |
> |
l.toArray(new String[10]); |
664 |
|
shouldThrow(); |
665 |
|
} catch (ArrayStoreException success) {} |
666 |
|
} |