21 |
|
public class ConcurrentLinkedDequeTest extends JSR166TestCase { |
22 |
|
|
23 |
|
public static void main(String[] args) { |
24 |
< |
junit.textui.TestRunner.run(suite()); |
24 |
> |
main(suite(), args); |
25 |
|
} |
26 |
|
|
27 |
|
public static Test suite() { |
55 |
|
*/ |
56 |
|
public void testConstructor3() { |
57 |
|
try { |
58 |
< |
ConcurrentLinkedDeque q = new ConcurrentLinkedDeque((Collection)null); |
58 |
> |
new ConcurrentLinkedDeque((Collection)null); |
59 |
|
shouldThrow(); |
60 |
|
} catch (NullPointerException success) {} |
61 |
|
} |
65 |
|
*/ |
66 |
|
public void testConstructor4() { |
67 |
|
try { |
68 |
< |
Integer[] ints = new Integer[SIZE]; |
69 |
< |
ConcurrentLinkedDeque q = new ConcurrentLinkedDeque(Arrays.asList(ints)); |
68 |
> |
new ConcurrentLinkedDeque(Arrays.asList(new Integer[SIZE])); |
69 |
|
shouldThrow(); |
70 |
|
} catch (NullPointerException success) {} |
71 |
|
} |
74 |
|
* Initializing from Collection with some null elements throws NPE |
75 |
|
*/ |
76 |
|
public void testConstructor5() { |
77 |
+ |
Integer[] ints = new Integer[SIZE]; |
78 |
+ |
for (int i = 0; i < SIZE-1; ++i) |
79 |
+ |
ints[i] = new Integer(i); |
80 |
|
try { |
81 |
< |
Integer[] ints = new Integer[SIZE]; |
80 |
< |
for (int i = 0; i < SIZE-1; ++i) |
81 |
< |
ints[i] = new Integer(i); |
82 |
< |
ConcurrentLinkedDeque q = new ConcurrentLinkedDeque(Arrays.asList(ints)); |
81 |
> |
new ConcurrentLinkedDeque(Arrays.asList(ints)); |
82 |
|
shouldThrow(); |
83 |
|
} catch (NullPointerException success) {} |
84 |
|
} |
128 |
|
* push(null) throws NPE |
129 |
|
*/ |
130 |
|
public void testPushNull() { |
131 |
+ |
ConcurrentLinkedDeque q = new ConcurrentLinkedDeque(); |
132 |
|
try { |
133 |
– |
ConcurrentLinkedDeque q = new ConcurrentLinkedDeque(); |
133 |
|
q.push(null); |
134 |
|
shouldThrow(); |
135 |
|
} catch (NullPointerException success) {} |
163 |
|
* offer(null) throws NPE |
164 |
|
*/ |
165 |
|
public void testOfferNull() { |
166 |
+ |
ConcurrentLinkedDeque q = new ConcurrentLinkedDeque(); |
167 |
|
try { |
168 |
– |
ConcurrentLinkedDeque q = new ConcurrentLinkedDeque(); |
168 |
|
q.offer(null); |
169 |
|
shouldThrow(); |
170 |
|
} catch (NullPointerException success) {} |
174 |
|
* offerFirst(null) throws NPE |
175 |
|
*/ |
176 |
|
public void testOfferFirstNull() { |
177 |
+ |
ConcurrentLinkedDeque q = new ConcurrentLinkedDeque(); |
178 |
|
try { |
179 |
– |
ConcurrentLinkedDeque q = new ConcurrentLinkedDeque(); |
179 |
|
q.offerFirst(null); |
180 |
|
shouldThrow(); |
181 |
|
} catch (NullPointerException success) {} |
185 |
|
* offerLast(null) throws NPE |
186 |
|
*/ |
187 |
|
public void testOfferLastNull() { |
188 |
+ |
ConcurrentLinkedDeque q = new ConcurrentLinkedDeque(); |
189 |
|
try { |
190 |
– |
ConcurrentLinkedDeque q = new ConcurrentLinkedDeque(); |
190 |
|
q.offerLast(null); |
191 |
|
shouldThrow(); |
192 |
|
} catch (NullPointerException success) {} |
229 |
|
* add(null) throws NPE |
230 |
|
*/ |
231 |
|
public void testAddNull() { |
232 |
+ |
ConcurrentLinkedDeque q = new ConcurrentLinkedDeque(); |
233 |
|
try { |
234 |
– |
ConcurrentLinkedDeque q = new ConcurrentLinkedDeque(); |
234 |
|
q.add(null); |
235 |
|
shouldThrow(); |
236 |
|
} catch (NullPointerException success) {} |
240 |
|
* addFirst(null) throws NPE |
241 |
|
*/ |
242 |
|
public void testAddFirstNull() { |
243 |
+ |
ConcurrentLinkedDeque q = new ConcurrentLinkedDeque(); |
244 |
|
try { |
245 |
– |
ConcurrentLinkedDeque q = new ConcurrentLinkedDeque(); |
245 |
|
q.addFirst(null); |
246 |
|
shouldThrow(); |
247 |
|
} catch (NullPointerException success) {} |
251 |
|
* addLast(null) throws NPE |
252 |
|
*/ |
253 |
|
public void testAddLastNull() { |
254 |
+ |
ConcurrentLinkedDeque q = new ConcurrentLinkedDeque(); |
255 |
|
try { |
256 |
– |
ConcurrentLinkedDeque q = new ConcurrentLinkedDeque(); |
256 |
|
q.addLast(null); |
257 |
|
shouldThrow(); |
258 |
|
} catch (NullPointerException success) {} |
295 |
|
* addAll(null) throws NPE |
296 |
|
*/ |
297 |
|
public void testAddAll1() { |
298 |
+ |
ConcurrentLinkedDeque q = new ConcurrentLinkedDeque(); |
299 |
|
try { |
300 |
– |
ConcurrentLinkedDeque q = new ConcurrentLinkedDeque(); |
300 |
|
q.addAll(null); |
301 |
|
shouldThrow(); |
302 |
|
} catch (NullPointerException success) {} |
306 |
|
* addAll(this) throws IAE |
307 |
|
*/ |
308 |
|
public void testAddAllSelf() { |
309 |
+ |
ConcurrentLinkedDeque q = populatedDeque(SIZE); |
310 |
|
try { |
311 |
– |
ConcurrentLinkedDeque q = populatedDeque(SIZE); |
311 |
|
q.addAll(q); |
312 |
|
shouldThrow(); |
313 |
|
} catch (IllegalArgumentException success) {} |
317 |
|
* addAll of a collection with null elements throws NPE |
318 |
|
*/ |
319 |
|
public void testAddAll2() { |
320 |
+ |
ConcurrentLinkedDeque q = new ConcurrentLinkedDeque(); |
321 |
|
try { |
322 |
< |
ConcurrentLinkedDeque q = new ConcurrentLinkedDeque(); |
323 |
< |
Integer[] ints = new Integer[SIZE]; |
324 |
< |
q.addAll(Arrays.asList(ints)); |
322 |
> |
q.addAll(Arrays.asList(new Integer[SIZE])); |
323 |
|
shouldThrow(); |
324 |
|
} catch (NullPointerException success) {} |
325 |
|
} |
329 |
|
* possibly adding some elements |
330 |
|
*/ |
331 |
|
public void testAddAll3() { |
332 |
+ |
ConcurrentLinkedDeque q = new ConcurrentLinkedDeque(); |
333 |
+ |
Integer[] ints = new Integer[SIZE]; |
334 |
+ |
for (int i = 0; i < SIZE-1; ++i) |
335 |
+ |
ints[i] = new Integer(i); |
336 |
|
try { |
335 |
– |
ConcurrentLinkedDeque q = new ConcurrentLinkedDeque(); |
336 |
– |
Integer[] ints = new Integer[SIZE]; |
337 |
– |
for (int i = 0; i < SIZE-1; ++i) |
338 |
– |
ints[i] = new Integer(i); |
337 |
|
q.addAll(Arrays.asList(ints)); |
338 |
|
shouldThrow(); |
339 |
|
} catch (NullPointerException success) {} |
435 |
|
*/ |
436 |
|
public void testRemoveElement() { |
437 |
|
ConcurrentLinkedDeque q = populatedDeque(SIZE); |
438 |
< |
for (int i = 1; i < SIZE; i+=2) { |
438 |
> |
for (int i = 1; i < SIZE; i += 2) { |
439 |
|
assertTrue(q.contains(i)); |
440 |
|
assertTrue(q.remove(i)); |
441 |
|
assertFalse(q.contains(i)); |
442 |
|
assertTrue(q.contains(i-1)); |
443 |
|
} |
444 |
< |
for (int i = 0; i < SIZE; i+=2) { |
444 |
> |
for (int i = 0; i < SIZE; i += 2) { |
445 |
|
assertTrue(q.contains(i)); |
446 |
|
assertTrue(q.remove(i)); |
447 |
|
assertFalse(q.contains(i)); |
545 |
|
*/ |
546 |
|
public void testRemoveFirstOccurrence() { |
547 |
|
ConcurrentLinkedDeque q = populatedDeque(SIZE); |
548 |
< |
for (int i = 1; i < SIZE; i+=2) { |
548 |
> |
for (int i = 1; i < SIZE; i += 2) { |
549 |
|
assertTrue(q.removeFirstOccurrence(new Integer(i))); |
550 |
|
} |
551 |
< |
for (int i = 0; i < SIZE; i+=2) { |
551 |
> |
for (int i = 0; i < SIZE; i += 2) { |
552 |
|
assertTrue(q.removeFirstOccurrence(new Integer(i))); |
553 |
|
assertFalse(q.removeFirstOccurrence(new Integer(i+1))); |
554 |
|
} |
560 |
|
*/ |
561 |
|
public void testRemoveLastOccurrence() { |
562 |
|
ConcurrentLinkedDeque q = populatedDeque(SIZE); |
563 |
< |
for (int i = 1; i < SIZE; i+=2) { |
563 |
> |
for (int i = 1; i < SIZE; i += 2) { |
564 |
|
assertTrue(q.removeLastOccurrence(new Integer(i))); |
565 |
|
} |
566 |
< |
for (int i = 0; i < SIZE; i+=2) { |
566 |
> |
for (int i = 0; i < SIZE; i += 2) { |
567 |
|
assertTrue(q.removeLastOccurrence(new Integer(i))); |
568 |
|
assertFalse(q.removeLastOccurrence(new Integer(i+1))); |
569 |
|
} |
639 |
|
assertTrue(q.removeAll(p)); |
640 |
|
assertEquals(SIZE-i, q.size()); |
641 |
|
for (int j = 0; j < i; ++j) { |
642 |
< |
Integer I = (Integer)(p.remove()); |
643 |
< |
assertFalse(q.contains(I)); |
642 |
> |
Integer x = (Integer)(p.remove()); |
643 |
> |
assertFalse(q.contains(x)); |
644 |
|
} |
645 |
|
} |
646 |
|
} |
694 |
|
*/ |
695 |
|
public void testIterator() { |
696 |
|
ConcurrentLinkedDeque q = populatedDeque(SIZE); |
699 |
– |
int i = 0; |
697 |
|
Iterator it = q.iterator(); |
698 |
< |
while (it.hasNext()) { |
698 |
> |
int i; |
699 |
> |
for (i = 0; it.hasNext(); i++) |
700 |
|
assertTrue(q.contains(it.next())); |
703 |
– |
++i; |
704 |
– |
} |
701 |
|
assertEquals(i, SIZE); |
702 |
+ |
assertIteratorExhausted(it); |
703 |
+ |
} |
704 |
+ |
|
705 |
+ |
/** |
706 |
+ |
* iterator of empty collection has no elements |
707 |
+ |
*/ |
708 |
+ |
public void testEmptyIterator() { |
709 |
+ |
Deque c = new ConcurrentLinkedDeque(); |
710 |
+ |
assertIteratorExhausted(c.iterator()); |
711 |
+ |
assertIteratorExhausted(c.descendingIterator()); |
712 |
|
} |
713 |
|
|
714 |
|
/** |