231 |
|
*/ |
232 |
|
public void testAdd() { |
233 |
|
ArrayBlockingQueue q = new ArrayBlockingQueue(SIZE); |
234 |
< |
for (int i = 0; i < SIZE; ++i) { |
235 |
< |
assertTrue(q.add(new Integer(i))); |
236 |
< |
} |
234 |
> |
for (int i = 0; i < SIZE; i++) assertTrue(q.add((Integer) i)); |
235 |
|
assertEquals(0, q.remainingCapacity()); |
236 |
|
try { |
237 |
< |
q.add(new Integer(SIZE)); |
237 |
> |
q.add((Integer) SIZE); |
238 |
|
shouldThrow(); |
239 |
|
} catch (IllegalStateException success) {} |
240 |
|
} |
268 |
|
/** |
269 |
|
* addAll throws ISE if not enough room |
270 |
|
*/ |
271 |
< |
public void testAddAll4() { |
272 |
< |
ArrayBlockingQueue q = new ArrayBlockingQueue(1); |
273 |
< |
Integer[] ints = new Integer[SIZE]; |
274 |
< |
for (int i = 0; i < SIZE; ++i) |
275 |
< |
ints[i] = new Integer(i); |
271 |
> |
public void testAddAll_insufficientSpace() { |
272 |
> |
int size = ThreadLocalRandom.current().nextInt(SIZE); |
273 |
> |
ArrayBlockingQueue q = populatedQueue(0, size, size, false); |
274 |
> |
// Just fits: |
275 |
> |
q.addAll(populatedQueue(size, size, 2 * size, false)); |
276 |
> |
assertEquals(0, q.remainingCapacity()); |
277 |
> |
assertEquals(size, q.size()); |
278 |
> |
assertEquals(0, q.peek()); |
279 |
|
try { |
280 |
< |
q.addAll(Arrays.asList(ints)); |
280 |
> |
q = populatedQueue(0, size, size, false); |
281 |
> |
q.addAll(Collections.nCopies(size + 1, 42)); |
282 |
|
shouldThrow(); |
283 |
|
} catch (IllegalStateException success) {} |
284 |
|
} |