24 |
|
|
25 |
|
@SuppressWarnings({"unchecked", "rawtypes"}) |
26 |
|
public class LinkedTransferQueueTest extends JSR166TestCase { |
27 |
+ |
static class Implementation implements CollectionImplementation { |
28 |
+ |
public Class<?> klazz() { return LinkedTransferQueue.class; } |
29 |
+ |
public Collection emptyCollection() { return new LinkedTransferQueue(); } |
30 |
+ |
public Object makeElement(int i) { return i; } |
31 |
+ |
public boolean isConcurrent() { return true; } |
32 |
+ |
public boolean permitsNulls() { return false; } |
33 |
+ |
} |
34 |
|
|
35 |
|
public static class Generic extends BlockingQueueTest { |
36 |
|
protected BlockingQueue emptyCollection() { |
39 |
|
} |
40 |
|
|
41 |
|
public static void main(String[] args) { |
42 |
< |
junit.textui.TestRunner.run(suite()); |
42 |
> |
main(suite(), args); |
43 |
|
} |
44 |
|
|
45 |
|
public static Test suite() { |
46 |
|
return newTestSuite(LinkedTransferQueueTest.class, |
47 |
< |
new Generic().testSuite()); |
47 |
> |
new Generic().testSuite(), |
48 |
> |
CollectionTest.testSuite(new Implementation())); |
49 |
|
} |
50 |
|
|
51 |
|
/** |
86 |
|
*/ |
87 |
|
public void testConstructor4() { |
88 |
|
Integer[] ints = new Integer[SIZE]; |
89 |
< |
for (int i = 0; i < SIZE-1; ++i) |
89 |
> |
for (int i = 0; i < SIZE - 1; ++i) |
90 |
|
ints[i] = i; |
91 |
|
Collection<Integer> elements = Arrays.asList(ints); |
92 |
|
try { |
123 |
|
* remainingCapacity() always returns Integer.MAX_VALUE |
124 |
|
*/ |
125 |
|
public void testRemainingCapacity() { |
126 |
< |
LinkedTransferQueue<Integer> q = populatedQueue(SIZE); |
126 |
> |
BlockingQueue q = populatedQueue(SIZE); |
127 |
|
for (int i = 0; i < SIZE; ++i) { |
128 |
|
assertEquals(Integer.MAX_VALUE, q.remainingCapacity()); |
129 |
|
assertEquals(SIZE - i, q.size()); |
130 |
< |
q.remove(); |
130 |
> |
assertEquals(i, q.remove()); |
131 |
|
} |
132 |
|
for (int i = 0; i < SIZE; ++i) { |
133 |
|
assertEquals(Integer.MAX_VALUE, q.remainingCapacity()); |
134 |
|
assertEquals(i, q.size()); |
135 |
< |
q.add(i); |
135 |
> |
assertTrue(q.add(i)); |
136 |
|
} |
137 |
|
} |
138 |
|
|
140 |
|
* addAll(this) throws IllegalArgumentException |
141 |
|
*/ |
142 |
|
public void testAddAllSelf() { |
143 |
+ |
LinkedTransferQueue q = populatedQueue(SIZE); |
144 |
|
try { |
136 |
– |
LinkedTransferQueue q = populatedQueue(SIZE); |
145 |
|
q.addAll(q); |
146 |
|
shouldThrow(); |
147 |
|
} catch (IllegalArgumentException success) {} |
152 |
|
* NullPointerException after possibly adding some elements |
153 |
|
*/ |
154 |
|
public void testAddAll3() { |
155 |
+ |
LinkedTransferQueue q = new LinkedTransferQueue(); |
156 |
+ |
Integer[] ints = new Integer[SIZE]; |
157 |
+ |
for (int i = 0; i < SIZE - 1; ++i) |
158 |
+ |
ints[i] = i; |
159 |
|
try { |
148 |
– |
LinkedTransferQueue q = new LinkedTransferQueue(); |
149 |
– |
Integer[] ints = new Integer[SIZE]; |
150 |
– |
for (int i = 0; i < SIZE - 1; ++i) { |
151 |
– |
ints[i] = i; |
152 |
– |
} |
160 |
|
q.addAll(Arrays.asList(ints)); |
161 |
|
shouldThrow(); |
162 |
|
} catch (NullPointerException success) {} |
507 |
|
public void testIterator() throws InterruptedException { |
508 |
|
LinkedTransferQueue q = populatedQueue(SIZE); |
509 |
|
Iterator it = q.iterator(); |
510 |
< |
int i = 0; |
511 |
< |
while (it.hasNext()) { |
512 |
< |
assertEquals(it.next(), i++); |
506 |
< |
} |
510 |
> |
int i; |
511 |
> |
for (i = 0; it.hasNext(); i++) |
512 |
> |
assertTrue(q.contains(it.next())); |
513 |
|
assertEquals(i, SIZE); |
514 |
+ |
assertIteratorExhausted(it); |
515 |
+ |
|
516 |
+ |
it = q.iterator(); |
517 |
+ |
for (i = 0; it.hasNext(); i++) |
518 |
+ |
assertEquals(it.next(), q.take()); |
519 |
+ |
assertEquals(i, SIZE); |
520 |
+ |
assertIteratorExhausted(it); |
521 |
+ |
} |
522 |
+ |
|
523 |
+ |
/** |
524 |
+ |
* iterator of empty collection has no elements |
525 |
+ |
*/ |
526 |
+ |
public void testEmptyIterator() { |
527 |
+ |
assertIteratorExhausted(new LinkedTransferQueue().iterator()); |
528 |
|
} |
529 |
|
|
530 |
|
/** |
717 |
|
assertEquals(SIZE - k, q.size()); |
718 |
|
for (int j = 0; j < k; ++j) |
719 |
|
assertEquals(j, l.get(j)); |
720 |
< |
while (q.poll() != null) |
701 |
< |
; |
720 |
> |
do {} while (q.poll() != null); |
721 |
|
} |
722 |
|
} |
723 |
|
|
869 |
|
* tryTransfer(null) throws NullPointerException |
870 |
|
*/ |
871 |
|
public void testTryTransfer1() { |
872 |
+ |
final LinkedTransferQueue q = new LinkedTransferQueue(); |
873 |
|
try { |
854 |
– |
final LinkedTransferQueue q = new LinkedTransferQueue(); |
874 |
|
q.tryTransfer(null); |
875 |
|
shouldThrow(); |
876 |
|
} catch (NullPointerException success) {} |