13 |
|
|
14 |
|
public class PriorityBlockingQueueTest extends JSR166TestCase { |
15 |
|
public static void main(String[] args) { |
16 |
< |
junit.textui.TestRunner.run (suite()); |
16 |
> |
junit.textui.TestRunner.run (suite()); |
17 |
|
} |
18 |
|
public static Test suite() { |
19 |
< |
return new TestSuite(PriorityBlockingQueueTest.class); |
19 |
> |
return new TestSuite(PriorityBlockingQueueTest.class); |
20 |
|
} |
21 |
|
|
22 |
|
private static final int NOCAP = Integer.MAX_VALUE; |
39 |
|
private PriorityBlockingQueue populatedQueue(int n) { |
40 |
|
PriorityBlockingQueue q = new PriorityBlockingQueue(n); |
41 |
|
assertTrue(q.isEmpty()); |
42 |
< |
for (int i = n-1; i >= 0; i-=2) |
43 |
< |
assertTrue(q.offer(new Integer(i))); |
44 |
< |
for (int i = (n & 1); i < n; i+=2) |
45 |
< |
assertTrue(q.offer(new Integer(i))); |
42 |
> |
for (int i = n-1; i >= 0; i-=2) |
43 |
> |
assertTrue(q.offer(new Integer(i))); |
44 |
> |
for (int i = (n & 1); i < n; i+=2) |
45 |
> |
assertTrue(q.offer(new Integer(i))); |
46 |
|
assertFalse(q.isEmpty()); |
47 |
|
assertEquals(NOCAP, q.remainingCapacity()); |
48 |
< |
assertEquals(n, q.size()); |
48 |
> |
assertEquals(n, q.size()); |
49 |
|
return q; |
50 |
|
} |
51 |
|
|
164 |
|
* offer(null) throws NPE |
165 |
|
*/ |
166 |
|
public void testOfferNull() { |
167 |
< |
try { |
167 |
> |
try { |
168 |
|
PriorityBlockingQueue q = new PriorityBlockingQueue(1); |
169 |
|
q.offer(null); |
170 |
|
shouldThrow(); |
175 |
|
* add(null) throws NPE |
176 |
|
*/ |
177 |
|
public void testAddNull() { |
178 |
< |
try { |
178 |
> |
try { |
179 |
|
PriorityBlockingQueue q = new PriorityBlockingQueue(1); |
180 |
|
q.add(null); |
181 |
|
shouldThrow(); |
282 |
|
* put(null) throws NPE |
283 |
|
*/ |
284 |
|
public void testPutNull() { |
285 |
< |
try { |
285 |
> |
try { |
286 |
|
PriorityBlockingQueue q = new PriorityBlockingQueue(SIZE); |
287 |
|
q.put(null); |
288 |
|
shouldThrow(); |
398 |
|
for (int i = 0; i < SIZE; ++i) { |
399 |
|
assertEquals(i, ((Integer)q.poll()).intValue()); |
400 |
|
} |
401 |
< |
assertNull(q.poll()); |
401 |
> |
assertNull(q.poll()); |
402 |
|
} |
403 |
|
|
404 |
|
/** |
481 |
|
assertTrue(q.peek() == null || |
482 |
|
i != ((Integer)q.peek()).intValue()); |
483 |
|
} |
484 |
< |
assertNull(q.peek()); |
484 |
> |
assertNull(q.peek()); |
485 |
|
} |
486 |
|
|
487 |
|
/** |
609 |
|
*/ |
610 |
|
public void testToArray() throws InterruptedException { |
611 |
|
PriorityBlockingQueue q = populatedQueue(SIZE); |
612 |
< |
Object[] o = q.toArray(); |
612 |
> |
Object[] o = q.toArray(); |
613 |
|
Arrays.sort(o); |
614 |
< |
for (int i = 0; i < o.length; i++) |
615 |
< |
assertEquals(o[i], q.take()); |
614 |
> |
for (int i = 0; i < o.length; i++) |
615 |
> |
assertEquals(o[i], q.take()); |
616 |
|
} |
617 |
|
|
618 |
|
/** |
620 |
|
*/ |
621 |
|
public void testToArray2() throws InterruptedException { |
622 |
|
PriorityBlockingQueue q = populatedQueue(SIZE); |
623 |
< |
Integer[] ints = new Integer[SIZE]; |
624 |
< |
ints = (Integer[])q.toArray(ints); |
623 |
> |
Integer[] ints = new Integer[SIZE]; |
624 |
> |
ints = (Integer[])q.toArray(ints); |
625 |
|
Arrays.sort(ints); |
626 |
|
for (int i = 0; i < ints.length; i++) |
627 |
|
assertEquals(ints[i], q.take()); |
631 |
|
* toArray(null) throws NPE |
632 |
|
*/ |
633 |
|
public void testToArray_BadArg() { |
634 |
< |
try { |
634 |
> |
try { |
635 |
|
PriorityBlockingQueue q = populatedQueue(SIZE); |
636 |
< |
Object o[] = q.toArray(null); |
637 |
< |
shouldThrow(); |
638 |
< |
} catch (NullPointerException success) {} |
636 |
> |
Object o[] = q.toArray(null); |
637 |
> |
shouldThrow(); |
638 |
> |
} catch (NullPointerException success) {} |
639 |
|
} |
640 |
|
|
641 |
|
/** |
642 |
|
* toArray with incompatible array type throws CCE |
643 |
|
*/ |
644 |
|
public void testToArray1_BadArg() { |
645 |
< |
try { |
645 |
> |
try { |
646 |
|
PriorityBlockingQueue q = populatedQueue(SIZE); |
647 |
< |
Object o[] = q.toArray(new String[10] ); |
648 |
< |
shouldThrow(); |
649 |
< |
} catch (ArrayStoreException success) {} |
647 |
> |
Object o[] = q.toArray(new String[10] ); |
648 |
> |
shouldThrow(); |
649 |
> |
} catch (ArrayStoreException success) {} |
650 |
|
} |
651 |
|
|
652 |
|
/** |
655 |
|
public void testIterator() { |
656 |
|
PriorityBlockingQueue q = populatedQueue(SIZE); |
657 |
|
int i = 0; |
658 |
< |
Iterator it = q.iterator(); |
658 |
> |
Iterator it = q.iterator(); |
659 |
|
while (it.hasNext()) { |
660 |
|
assertTrue(q.contains(it.next())); |
661 |
|
++i; |