41 |
|
* Create a queue of given size containing consecutive |
42 |
|
* Integers 0 ... n. |
43 |
|
*/ |
44 |
< |
private ArrayBlockingQueue populatedQueue(int n) { |
45 |
< |
ArrayBlockingQueue q = new ArrayBlockingQueue(n); |
44 |
> |
private ArrayBlockingQueue<Integer> populatedQueue(int n) { |
45 |
> |
ArrayBlockingQueue<Integer> q = new ArrayBlockingQueue<Integer>(n); |
46 |
|
assertTrue(q.isEmpty()); |
47 |
|
for (int i = 0; i < n; i++) |
48 |
|
assertTrue(q.offer(new Integer(i))); |
607 |
|
} |
608 |
|
|
609 |
|
/** |
610 |
< |
* toArray contains all elements |
610 |
> |
* toArray contains all elements in FIFO order |
611 |
|
*/ |
612 |
< |
public void testToArray() throws InterruptedException { |
612 |
> |
public void testToArray() { |
613 |
|
ArrayBlockingQueue q = populatedQueue(SIZE); |
614 |
|
Object[] o = q.toArray(); |
615 |
|
for (int i = 0; i < o.length; i++) |
616 |
< |
assertEquals(o[i], q.take()); |
616 |
> |
assertSame(o[i], q.poll()); |
617 |
|
} |
618 |
|
|
619 |
|
/** |
620 |
< |
* toArray(a) contains all elements |
620 |
> |
* toArray(a) contains all elements in FIFO order |
621 |
|
*/ |
622 |
< |
public void testToArray2() throws InterruptedException { |
623 |
< |
ArrayBlockingQueue q = populatedQueue(SIZE); |
622 |
> |
public void testToArray2() { |
623 |
> |
ArrayBlockingQueue<Integer> q = populatedQueue(SIZE); |
624 |
|
Integer[] ints = new Integer[SIZE]; |
625 |
< |
ints = (Integer[])q.toArray(ints); |
625 |
> |
Integer[] array = q.toArray(ints); |
626 |
> |
assertSame(ints, array); |
627 |
|
for (int i = 0; i < ints.length; i++) |
628 |
< |
assertEquals(ints[i], q.take()); |
628 |
> |
assertSame(ints[i], q.poll()); |
629 |
|
} |
630 |
|
|
631 |
|
/** |