41 |
|
* Create a queue of given size containing consecutive |
42 |
|
* Integers 0 ... n. |
43 |
|
*/ |
44 |
< |
private LinkedBlockingQueue populatedQueue(int n) { |
45 |
< |
LinkedBlockingQueue q = new LinkedBlockingQueue(n); |
44 |
> |
private LinkedBlockingQueue<Integer> populatedQueue(int n) { |
45 |
> |
LinkedBlockingQueue<Integer> q = |
46 |
> |
new LinkedBlockingQueue<Integer>(n); |
47 |
|
assertTrue(q.isEmpty()); |
48 |
|
for (int i = 0; i < n; i++) |
49 |
|
assertTrue(q.offer(new Integer(i))); |
508 |
|
public void testRemoveElement() { |
509 |
|
LinkedBlockingQueue q = populatedQueue(SIZE); |
510 |
|
for (int i = 1; i < SIZE; i+=2) { |
511 |
< |
assertTrue(q.remove(new Integer(i))); |
511 |
> |
assertTrue(q.contains(i)); |
512 |
> |
assertTrue(q.remove(i)); |
513 |
> |
assertFalse(q.contains(i)); |
514 |
> |
assertTrue(q.contains(i-1)); |
515 |
|
} |
516 |
|
for (int i = 0; i < SIZE; i+=2) { |
517 |
< |
assertTrue(q.remove(new Integer(i))); |
518 |
< |
assertFalse(q.remove(new Integer(i+1))); |
517 |
> |
assertTrue(q.contains(i)); |
518 |
> |
assertTrue(q.remove(i)); |
519 |
> |
assertFalse(q.contains(i)); |
520 |
> |
assertFalse(q.remove(i+1)); |
521 |
> |
assertFalse(q.contains(i+1)); |
522 |
|
} |
523 |
|
assertTrue(q.isEmpty()); |
524 |
|
} |
627 |
|
* toArray(a) contains all elements in FIFO order |
628 |
|
*/ |
629 |
|
public void testToArray2() throws InterruptedException { |
630 |
< |
LinkedBlockingQueue q = populatedQueue(SIZE); |
630 |
> |
LinkedBlockingQueue<Integer> q = populatedQueue(SIZE); |
631 |
|
Integer[] ints = new Integer[SIZE]; |
632 |
< |
assertSame(ints, q.toArray(ints)); |
632 |
> |
Integer[] array = q.toArray(ints); |
633 |
> |
assertSame(ints, array); |
634 |
|
for (int i = 0; i < ints.length; i++) |
635 |
|
assertSame(ints[i], q.poll()); |
636 |
|
} |