14 |
|
public class ConcurrentLinkedQueueTest extends JSR166TestCase { |
15 |
|
|
16 |
|
public static void main(String[] args) { |
17 |
< |
junit.textui.TestRunner.run (suite()); |
17 |
> |
junit.textui.TestRunner.run (suite()); |
18 |
|
} |
19 |
|
|
20 |
|
public static Test suite() { |
21 |
< |
return new TestSuite(ConcurrentLinkedQueueTest.class); |
21 |
> |
return new TestSuite(ConcurrentLinkedQueueTest.class); |
22 |
|
} |
23 |
|
|
24 |
|
/** |
28 |
|
private ConcurrentLinkedQueue populatedQueue(int n) { |
29 |
|
ConcurrentLinkedQueue q = new ConcurrentLinkedQueue(); |
30 |
|
assertTrue(q.isEmpty()); |
31 |
< |
for (int i = 0; i < n; ++i) |
32 |
< |
assertTrue(q.offer(new Integer(i))); |
31 |
> |
for (int i = 0; i < n; ++i) |
32 |
> |
assertTrue(q.offer(new Integer(i))); |
33 |
|
assertFalse(q.isEmpty()); |
34 |
< |
assertEquals(n, q.size()); |
34 |
> |
assertEquals(n, q.size()); |
35 |
|
return q; |
36 |
|
} |
37 |
|
|
127 |
|
* offer(null) throws NPE |
128 |
|
*/ |
129 |
|
public void testOfferNull() { |
130 |
< |
try { |
130 |
> |
try { |
131 |
|
ConcurrentLinkedQueue q = new ConcurrentLinkedQueue(); |
132 |
|
q.offer(null); |
133 |
|
shouldThrow(); |
138 |
|
* add(null) throws NPE |
139 |
|
*/ |
140 |
|
public void testAddNull() { |
141 |
< |
try { |
141 |
> |
try { |
142 |
|
ConcurrentLinkedQueue q = new ConcurrentLinkedQueue(); |
143 |
|
q.add(null); |
144 |
|
shouldThrow(); |
244 |
|
for (int i = 0; i < SIZE; ++i) { |
245 |
|
assertEquals(i, ((Integer)q.poll()).intValue()); |
246 |
|
} |
247 |
< |
assertNull(q.poll()); |
247 |
> |
assertNull(q.poll()); |
248 |
|
} |
249 |
|
|
250 |
|
/** |
258 |
|
assertTrue(q.peek() == null || |
259 |
|
i != ((Integer)q.peek()).intValue()); |
260 |
|
} |
261 |
< |
assertNull(q.peek()); |
261 |
> |
assertNull(q.peek()); |
262 |
|
} |
263 |
|
|
264 |
|
/** |
289 |
|
q.remove(); |
290 |
|
shouldThrow(); |
291 |
|
} catch (NoSuchElementException success) { |
292 |
< |
} |
292 |
> |
} |
293 |
|
} |
294 |
|
|
295 |
|
/** |
387 |
|
*/ |
388 |
|
public void testToArray() { |
389 |
|
ConcurrentLinkedQueue q = populatedQueue(SIZE); |
390 |
< |
Object[] o = q.toArray(); |
390 |
> |
Object[] o = q.toArray(); |
391 |
|
Arrays.sort(o); |
392 |
< |
for (int i = 0; i < o.length; i++) |
393 |
< |
assertEquals(o[i], q.poll()); |
392 |
> |
for (int i = 0; i < o.length; i++) |
393 |
> |
assertEquals(o[i], q.poll()); |
394 |
|
} |
395 |
|
|
396 |
|
/** |
398 |
|
*/ |
399 |
|
public void testToArray2() { |
400 |
|
ConcurrentLinkedQueue q = populatedQueue(SIZE); |
401 |
< |
Integer[] ints = new Integer[SIZE]; |
402 |
< |
ints = (Integer[])q.toArray(ints); |
401 |
> |
Integer[] ints = new Integer[SIZE]; |
402 |
> |
ints = (Integer[])q.toArray(ints); |
403 |
|
Arrays.sort(ints); |
404 |
|
for (int i = 0; i < ints.length; i++) |
405 |
|
assertEquals(ints[i], q.poll()); |
409 |
|
* toArray(null) throws NPE |
410 |
|
*/ |
411 |
|
public void testToArray_BadArg() { |
412 |
< |
try { |
412 |
> |
try { |
413 |
|
ConcurrentLinkedQueue q = populatedQueue(SIZE); |
414 |
< |
Object o[] = q.toArray(null); |
415 |
< |
shouldThrow(); |
416 |
< |
} catch (NullPointerException success) {} |
414 |
> |
Object o[] = q.toArray(null); |
415 |
> |
shouldThrow(); |
416 |
> |
} catch (NullPointerException success) {} |
417 |
|
} |
418 |
|
|
419 |
|
/** |
420 |
|
* toArray with incompatible array type throws ArrayStoreException |
421 |
|
*/ |
422 |
|
public void testToArray1_BadArg() { |
423 |
< |
try { |
423 |
> |
try { |
424 |
|
ConcurrentLinkedQueue q = populatedQueue(SIZE); |
425 |
< |
Object o[] = q.toArray(new String[10] ); |
426 |
< |
shouldThrow(); |
427 |
< |
} catch (ArrayStoreException success) {} |
425 |
> |
Object o[] = q.toArray(new String[10] ); |
426 |
> |
shouldThrow(); |
427 |
> |
} catch (ArrayStoreException success) {} |
428 |
|
} |
429 |
|
|
430 |
|
/** |
433 |
|
public void testIterator() { |
434 |
|
ConcurrentLinkedQueue q = populatedQueue(SIZE); |
435 |
|
int i = 0; |
436 |
< |
Iterator it = q.iterator(); |
436 |
> |
Iterator it = q.iterator(); |
437 |
|
while (it.hasNext()) { |
438 |
|
assertTrue(q.contains(it.next())); |
439 |
|
++i; |