37 |
|
} |
38 |
|
|
39 |
|
public static void main(String[] args) { |
40 |
< |
junit.textui.TestRunner.run(suite()); |
40 |
> |
main(suite(), args); |
41 |
|
} |
42 |
|
|
43 |
|
public static Test suite() { |
407 |
|
* remainingCapacity decreases on add, increases on remove |
408 |
|
*/ |
409 |
|
public void testRemainingCapacity() { |
410 |
< |
LinkedBlockingDeque q = populatedDeque(SIZE); |
410 |
> |
BlockingQueue q = populatedDeque(SIZE); |
411 |
|
for (int i = 0; i < SIZE; ++i) { |
412 |
|
assertEquals(i, q.remainingCapacity()); |
413 |
< |
assertEquals(SIZE-i, q.size()); |
414 |
< |
q.remove(); |
413 |
> |
assertEquals(SIZE, q.size() + q.remainingCapacity()); |
414 |
> |
assertEquals(i, q.remove()); |
415 |
|
} |
416 |
|
for (int i = 0; i < SIZE; ++i) { |
417 |
|
assertEquals(SIZE-i, q.remainingCapacity()); |
418 |
< |
assertEquals(i, q.size()); |
419 |
< |
q.add(new Integer(i)); |
418 |
> |
assertEquals(SIZE, q.size() + q.remainingCapacity()); |
419 |
> |
assertTrue(q.add(i)); |
420 |
|
} |
421 |
|
} |
422 |
|
|
424 |
|
* push(null) throws NPE |
425 |
|
*/ |
426 |
|
public void testPushNull() { |
427 |
+ |
LinkedBlockingDeque q = new LinkedBlockingDeque(1); |
428 |
|
try { |
428 |
– |
LinkedBlockingDeque q = new LinkedBlockingDeque(1); |
429 |
|
q.push(null); |
430 |
|
shouldThrow(); |
431 |
|
} catch (NullPointerException success) {} |
435 |
|
* push succeeds if not full; throws ISE if full |
436 |
|
*/ |
437 |
|
public void testPush() { |
438 |
+ |
LinkedBlockingDeque q = new LinkedBlockingDeque(SIZE); |
439 |
+ |
for (int i = 0; i < SIZE; ++i) { |
440 |
+ |
Integer x = new Integer(i); |
441 |
+ |
q.push(x); |
442 |
+ |
assertEquals(x, q.peek()); |
443 |
+ |
} |
444 |
+ |
assertEquals(0, q.remainingCapacity()); |
445 |
|
try { |
439 |
– |
LinkedBlockingDeque q = new LinkedBlockingDeque(SIZE); |
440 |
– |
for (int i = 0; i < SIZE; ++i) { |
441 |
– |
Integer x = new Integer(i); |
442 |
– |
q.push(x); |
443 |
– |
assertEquals(x, q.peek()); |
444 |
– |
} |
445 |
– |
assertEquals(0, q.remainingCapacity()); |
446 |
|
q.push(new Integer(SIZE)); |
447 |
|
shouldThrow(); |
448 |
|
} catch (IllegalStateException success) {} |
1518 |
|
public void testIterator() throws InterruptedException { |
1519 |
|
LinkedBlockingDeque q = populatedDeque(SIZE); |
1520 |
|
Iterator it = q.iterator(); |
1521 |
< |
while (it.hasNext()) { |
1521 |
> |
int i; |
1522 |
> |
for (i = 0; it.hasNext(); i++) |
1523 |
> |
assertTrue(q.contains(it.next())); |
1524 |
> |
assertEquals(i, SIZE); |
1525 |
> |
assertIteratorExhausted(it); |
1526 |
> |
|
1527 |
> |
it = q.iterator(); |
1528 |
> |
for (i = 0; it.hasNext(); i++) |
1529 |
|
assertEquals(it.next(), q.take()); |
1530 |
< |
} |
1530 |
> |
assertEquals(i, SIZE); |
1531 |
> |
assertIteratorExhausted(it); |
1532 |
> |
} |
1533 |
> |
|
1534 |
> |
/** |
1535 |
> |
* iterator of empty collection has no elements |
1536 |
> |
*/ |
1537 |
> |
public void testEmptyIterator() { |
1538 |
> |
Deque c = new LinkedBlockingDeque(); |
1539 |
> |
assertIteratorExhausted(c.iterator()); |
1540 |
> |
assertIteratorExhausted(c.descendingIterator()); |
1541 |
|
} |
1542 |
|
|
1543 |
|
/** |