108 |
|
ints[i] = i; |
109 |
|
Collection<Integer> elements = Arrays.asList(ints); |
110 |
|
try { |
111 |
< |
new ArrayBlockingQueue(SIZE, false, Arrays.asList(ints)); |
111 |
> |
new ArrayBlockingQueue(SIZE, false, elements); |
112 |
|
shouldThrow(); |
113 |
|
} catch (NullPointerException success) {} |
114 |
|
} |
159 |
|
* remainingCapacity decreases on add, increases on remove |
160 |
|
*/ |
161 |
|
public void testRemainingCapacity() { |
162 |
< |
ArrayBlockingQueue q = populatedQueue(SIZE); |
162 |
> |
BlockingQueue q = populatedQueue(SIZE); |
163 |
|
for (int i = 0; i < SIZE; ++i) { |
164 |
|
assertEquals(i, q.remainingCapacity()); |
165 |
< |
assertEquals(SIZE-i, q.size()); |
166 |
< |
q.remove(); |
165 |
> |
assertEquals(SIZE, q.size() + q.remainingCapacity()); |
166 |
> |
assertEquals(i, q.remove()); |
167 |
|
} |
168 |
|
for (int i = 0; i < SIZE; ++i) { |
169 |
|
assertEquals(SIZE-i, q.remainingCapacity()); |
170 |
< |
assertEquals(i, q.size()); |
171 |
< |
q.add(new Integer(i)); |
170 |
> |
assertEquals(SIZE, q.size() + q.remainingCapacity()); |
171 |
> |
assertTrue(q.add(i)); |
172 |
|
} |
173 |
|
} |
174 |
|
|
185 |
|
* add succeeds if not full; throws ISE if full |
186 |
|
*/ |
187 |
|
public void testAdd() { |
188 |
+ |
ArrayBlockingQueue q = new ArrayBlockingQueue(SIZE); |
189 |
+ |
for (int i = 0; i < SIZE; ++i) { |
190 |
+ |
assertTrue(q.add(new Integer(i))); |
191 |
+ |
} |
192 |
+ |
assertEquals(0, q.remainingCapacity()); |
193 |
|
try { |
189 |
– |
ArrayBlockingQueue q = new ArrayBlockingQueue(SIZE); |
190 |
– |
for (int i = 0; i < SIZE; ++i) { |
191 |
– |
assertTrue(q.add(new Integer(i))); |
192 |
– |
} |
193 |
– |
assertEquals(0, q.remainingCapacity()); |
194 |
|
q.add(new Integer(SIZE)); |
195 |
|
shouldThrow(); |
196 |
|
} catch (IllegalStateException success) {} |
200 |
|
* addAll(this) throws IAE |
201 |
|
*/ |
202 |
|
public void testAddAllSelf() { |
203 |
+ |
ArrayBlockingQueue q = populatedQueue(SIZE); |
204 |
|
try { |
204 |
– |
ArrayBlockingQueue q = populatedQueue(SIZE); |
205 |
|
q.addAll(q); |
206 |
|
shouldThrow(); |
207 |
|
} catch (IllegalArgumentException success) {} |
212 |
|
* possibly adding some elements |
213 |
|
*/ |
214 |
|
public void testAddAll3() { |
215 |
+ |
ArrayBlockingQueue q = new ArrayBlockingQueue(SIZE); |
216 |
+ |
Integer[] ints = new Integer[SIZE]; |
217 |
+ |
for (int i = 0; i < SIZE-1; ++i) |
218 |
+ |
ints[i] = new Integer(i); |
219 |
|
try { |
216 |
– |
ArrayBlockingQueue q = new ArrayBlockingQueue(SIZE); |
217 |
– |
Integer[] ints = new Integer[SIZE]; |
218 |
– |
for (int i = 0; i < SIZE-1; ++i) |
219 |
– |
ints[i] = new Integer(i); |
220 |
|
q.addAll(Arrays.asList(ints)); |
221 |
|
shouldThrow(); |
222 |
|
} catch (NullPointerException success) {} |
226 |
|
* addAll throws ISE if not enough room |
227 |
|
*/ |
228 |
|
public void testAddAll4() { |
229 |
+ |
ArrayBlockingQueue q = new ArrayBlockingQueue(1); |
230 |
+ |
Integer[] ints = new Integer[SIZE]; |
231 |
+ |
for (int i = 0; i < SIZE; ++i) |
232 |
+ |
ints[i] = new Integer(i); |
233 |
|
try { |
230 |
– |
ArrayBlockingQueue q = new ArrayBlockingQueue(1); |
231 |
– |
Integer[] ints = new Integer[SIZE]; |
232 |
– |
for (int i = 0; i < SIZE; ++i) |
233 |
– |
ints[i] = new Integer(i); |
234 |
|
q.addAll(Arrays.asList(ints)); |
235 |
|
shouldThrow(); |
236 |
|
} catch (IllegalStateException success) {} |
698 |
|
public void testIterator() throws InterruptedException { |
699 |
|
ArrayBlockingQueue q = populatedQueue(SIZE); |
700 |
|
Iterator it = q.iterator(); |
701 |
< |
while (it.hasNext()) { |
701 |
> |
int i; |
702 |
> |
for (i = 0; it.hasNext(); i++) |
703 |
> |
assertTrue(q.contains(it.next())); |
704 |
> |
assertEquals(i, SIZE); |
705 |
> |
assertIteratorExhausted(it); |
706 |
> |
|
707 |
> |
it = q.iterator(); |
708 |
> |
for (i = 0; it.hasNext(); i++) |
709 |
|
assertEquals(it.next(), q.take()); |
710 |
< |
} |
710 |
> |
assertEquals(i, SIZE); |
711 |
> |
assertIteratorExhausted(it); |
712 |
> |
} |
713 |
> |
|
714 |
> |
/** |
715 |
> |
* iterator of empty collection has no elements |
716 |
> |
*/ |
717 |
> |
public void testEmptyIterator() { |
718 |
> |
assertIteratorExhausted(new ArrayBlockingQueue(SIZE).iterator()); |
719 |
|
} |
720 |
|
|
721 |
|
/** |