6 |
|
* Pat Fisher, Mike Judd. |
7 |
|
*/ |
8 |
|
|
9 |
– |
import junit.framework.*; |
9 |
|
import java.util.Arrays; |
10 |
|
import java.util.Collection; |
11 |
|
import java.util.Iterator; |
13 |
|
import java.util.Queue; |
14 |
|
import java.util.concurrent.ConcurrentLinkedQueue; |
15 |
|
|
16 |
+ |
import junit.framework.Test; |
17 |
+ |
import junit.framework.TestSuite; |
18 |
+ |
|
19 |
|
public class ConcurrentLinkedQueueTest extends JSR166TestCase { |
20 |
|
|
21 |
|
public static void main(String[] args) { |
27 |
|
} |
28 |
|
|
29 |
|
/** |
30 |
< |
* Creates a queue of given size containing consecutive |
30 |
> |
* Returns a new queue of given size containing consecutive |
31 |
|
* Integers 0 ... n. |
32 |
|
*/ |
33 |
|
private ConcurrentLinkedQueue<Integer> populatedQueue(int n) { |
287 |
|
*/ |
288 |
|
public void testRemoveElement() { |
289 |
|
ConcurrentLinkedQueue q = populatedQueue(SIZE); |
290 |
< |
for (int i = 1; i < SIZE; i+=2) { |
290 |
> |
for (int i = 1; i < SIZE; i += 2) { |
291 |
|
assertTrue(q.contains(i)); |
292 |
|
assertTrue(q.remove(i)); |
293 |
|
assertFalse(q.contains(i)); |
294 |
|
assertTrue(q.contains(i-1)); |
295 |
|
} |
296 |
< |
for (int i = 0; i < SIZE; i+=2) { |
296 |
> |
for (int i = 0; i < SIZE; i += 2) { |
297 |
|
assertTrue(q.contains(i)); |
298 |
|
assertTrue(q.remove(i)); |
299 |
|
assertFalse(q.contains(i)); |
372 |
|
assertTrue(q.removeAll(p)); |
373 |
|
assertEquals(SIZE-i, q.size()); |
374 |
|
for (int j = 0; j < i; ++j) { |
375 |
< |
Integer I = (Integer)(p.remove()); |
376 |
< |
assertFalse(q.contains(I)); |
375 |
> |
Integer x = (Integer)(p.remove()); |
376 |
> |
assertFalse(q.contains(x)); |
377 |
|
} |
378 |
|
} |
379 |
|
} |
505 |
|
Queue x = populatedQueue(SIZE); |
506 |
|
Queue y = serialClone(x); |
507 |
|
|
508 |
< |
assertTrue(x != y); |
508 |
> |
assertNotSame(x, y); |
509 |
|
assertEquals(x.size(), y.size()); |
510 |
|
assertEquals(x.toString(), y.toString()); |
511 |
|
assertTrue(Arrays.equals(x.toArray(), y.toArray())); |
516 |
|
assertTrue(y.isEmpty()); |
517 |
|
} |
518 |
|
|
519 |
+ |
/** |
520 |
+ |
* remove(null), contains(null) always return false |
521 |
+ |
*/ |
522 |
+ |
public void testNeverContainsNull() { |
523 |
+ |
Collection<?>[] qs = { |
524 |
+ |
new ConcurrentLinkedQueue<Object>(), |
525 |
+ |
populatedQueue(2), |
526 |
+ |
}; |
527 |
+ |
|
528 |
+ |
for (Collection<?> q : qs) { |
529 |
+ |
assertFalse(q.contains(null)); |
530 |
+ |
assertFalse(q.remove(null)); |
531 |
+ |
} |
532 |
+ |
} |
533 |
|
} |