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() { |
108 |
|
*/ |
109 |
|
public void testConstructor5() { |
110 |
|
Integer[] ints = new Integer[SIZE]; |
111 |
< |
for (int i = 0; i < SIZE-1; ++i) |
111 |
> |
for (int i = 0; i < SIZE - 1; ++i) |
112 |
|
ints[i] = new Integer(i); |
113 |
|
Collection<Integer> elements = Arrays.asList(ints); |
114 |
|
try { |
148 |
|
* remainingCapacity decreases on add, increases on remove |
149 |
|
*/ |
150 |
|
public void testRemainingCapacity() { |
151 |
< |
LinkedBlockingQueue q = populatedQueue(SIZE); |
151 |
> |
BlockingQueue q = populatedQueue(SIZE); |
152 |
|
for (int i = 0; i < SIZE; ++i) { |
153 |
|
assertEquals(i, q.remainingCapacity()); |
154 |
< |
assertEquals(SIZE-i, q.size()); |
155 |
< |
q.remove(); |
154 |
> |
assertEquals(SIZE, q.size() + q.remainingCapacity()); |
155 |
> |
assertEquals(i, q.remove()); |
156 |
|
} |
157 |
|
for (int i = 0; i < SIZE; ++i) { |
158 |
< |
assertEquals(SIZE-i, q.remainingCapacity()); |
159 |
< |
assertEquals(i, q.size()); |
160 |
< |
q.add(new Integer(i)); |
158 |
> |
assertEquals(SIZE - i, q.remainingCapacity()); |
159 |
> |
assertEquals(SIZE, q.size() + q.remainingCapacity()); |
160 |
> |
assertTrue(q.add(i)); |
161 |
|
} |
162 |
|
} |
163 |
|
|
202 |
|
public void testAddAll3() { |
203 |
|
LinkedBlockingQueue q = new LinkedBlockingQueue(SIZE); |
204 |
|
Integer[] ints = new Integer[SIZE]; |
205 |
< |
for (int i = 0; i < SIZE-1; ++i) |
205 |
> |
for (int i = 0; i < SIZE - 1; ++i) |
206 |
|
ints[i] = new Integer(i); |
207 |
|
Collection<Integer> elements = Arrays.asList(ints); |
208 |
|
try { |
247 |
|
public void testPut() throws InterruptedException { |
248 |
|
LinkedBlockingQueue q = new LinkedBlockingQueue(SIZE); |
249 |
|
for (int i = 0; i < SIZE; ++i) { |
250 |
< |
Integer I = new Integer(i); |
251 |
< |
q.put(I); |
252 |
< |
assertTrue(q.contains(I)); |
250 |
> |
Integer x = new Integer(i); |
251 |
> |
q.put(x); |
252 |
> |
assertTrue(q.contains(x)); |
253 |
|
} |
254 |
|
assertEquals(0, q.remainingCapacity()); |
255 |
|
} |
574 |
|
assertTrue(changed); |
575 |
|
|
576 |
|
assertTrue(q.containsAll(p)); |
577 |
< |
assertEquals(SIZE-i, q.size()); |
577 |
> |
assertEquals(SIZE - i, q.size()); |
578 |
|
p.remove(); |
579 |
|
} |
580 |
|
} |
587 |
|
LinkedBlockingQueue q = populatedQueue(SIZE); |
588 |
|
LinkedBlockingQueue p = populatedQueue(i); |
589 |
|
assertTrue(q.removeAll(p)); |
590 |
< |
assertEquals(SIZE-i, q.size()); |
590 |
> |
assertEquals(SIZE - i, q.size()); |
591 |
|
for (int j = 0; j < i; ++j) { |
592 |
< |
Integer I = (Integer)(p.remove()); |
593 |
< |
assertFalse(q.contains(I)); |
592 |
> |
Integer x = (Integer)(p.remove()); |
593 |
> |
assertFalse(q.contains(x)); |
594 |
|
} |
595 |
|
} |
596 |
|
} |
634 |
|
public void testIterator() throws InterruptedException { |
635 |
|
LinkedBlockingQueue q = populatedQueue(SIZE); |
636 |
|
Iterator it = q.iterator(); |
637 |
< |
while (it.hasNext()) { |
637 |
> |
int i; |
638 |
> |
for (i = 0; it.hasNext(); i++) |
639 |
> |
assertTrue(q.contains(it.next())); |
640 |
> |
assertEquals(i, SIZE); |
641 |
> |
assertIteratorExhausted(it); |
642 |
> |
|
643 |
> |
it = q.iterator(); |
644 |
> |
for (i = 0; it.hasNext(); i++) |
645 |
|
assertEquals(it.next(), q.take()); |
646 |
< |
} |
646 |
> |
assertEquals(i, SIZE); |
647 |
> |
assertIteratorExhausted(it); |
648 |
> |
} |
649 |
> |
|
650 |
> |
/** |
651 |
> |
* iterator of empty collection has no elements |
652 |
> |
*/ |
653 |
> |
public void testEmptyIterator() { |
654 |
> |
assertIteratorExhausted(new LinkedBlockingQueue().iterator()); |
655 |
|
} |
656 |
|
|
657 |
|
/** |
814 |
|
final LinkedBlockingQueue q = populatedQueue(SIZE); |
815 |
|
Thread t = new Thread(new CheckedRunnable() { |
816 |
|
public void realRun() throws InterruptedException { |
817 |
< |
q.put(new Integer(SIZE+1)); |
817 |
> |
q.put(new Integer(SIZE + 1)); |
818 |
|
}}); |
819 |
|
|
820 |
|
t.start(); |
839 |
|
q.drainTo(l, i); |
840 |
|
int k = (i < SIZE) ? i : SIZE; |
841 |
|
assertEquals(k, l.size()); |
842 |
< |
assertEquals(SIZE-k, q.size()); |
842 |
> |
assertEquals(SIZE - k, q.size()); |
843 |
|
for (int j = 0; j < k; ++j) |
844 |
|
assertEquals(l.get(j), new Integer(j)); |
845 |
< |
while (q.poll() != null) ; |
845 |
> |
do {} while (q.poll() != null); |
846 |
|
} |
847 |
|
} |
848 |
|
|