7 |
|
*/ |
8 |
|
|
9 |
|
import junit.framework.*; |
10 |
< |
import java.util.*; |
11 |
< |
import java.util.concurrent.*; |
10 |
> |
import java.util.Arrays; |
11 |
> |
import java.util.ArrayList; |
12 |
> |
import java.util.Collection; |
13 |
> |
import java.util.Comparator; |
14 |
> |
import java.util.Iterator; |
15 |
> |
import java.util.NoSuchElementException; |
16 |
> |
import java.util.concurrent.PriorityBlockingQueue; |
17 |
> |
import java.util.concurrent.BlockingQueue; |
18 |
> |
import java.util.concurrent.CountDownLatch; |
19 |
> |
import java.util.concurrent.Executors; |
20 |
> |
import java.util.concurrent.ExecutorService; |
21 |
|
import static java.util.concurrent.TimeUnit.MILLISECONDS; |
22 |
|
import java.io.*; |
23 |
|
|
84 |
|
*/ |
85 |
|
public void testConstructor2() { |
86 |
|
try { |
87 |
< |
PriorityBlockingQueue q = new PriorityBlockingQueue(0); |
87 |
> |
new PriorityBlockingQueue(0); |
88 |
|
shouldThrow(); |
89 |
|
} catch (IllegalArgumentException success) {} |
90 |
|
} |
94 |
|
*/ |
95 |
|
public void testConstructor3() { |
96 |
|
try { |
97 |
< |
PriorityBlockingQueue q = new PriorityBlockingQueue(null); |
97 |
> |
new PriorityBlockingQueue(null); |
98 |
|
shouldThrow(); |
99 |
|
} catch (NullPointerException success) {} |
100 |
|
} |
103 |
|
* Initializing from Collection of null elements throws NPE |
104 |
|
*/ |
105 |
|
public void testConstructor4() { |
106 |
+ |
Collection<Integer> elements = Arrays.asList(new Integer[SIZE]); |
107 |
|
try { |
108 |
< |
Integer[] ints = new Integer[SIZE]; |
99 |
< |
PriorityBlockingQueue q = new PriorityBlockingQueue(Arrays.asList(ints)); |
108 |
> |
new PriorityBlockingQueue(elements); |
109 |
|
shouldThrow(); |
110 |
|
} catch (NullPointerException success) {} |
111 |
|
} |
114 |
|
* Initializing from Collection with some null elements throws NPE |
115 |
|
*/ |
116 |
|
public void testConstructor5() { |
117 |
+ |
Integer[] ints = new Integer[SIZE]; |
118 |
+ |
for (int i = 0; i < SIZE-1; ++i) |
119 |
+ |
ints[i] = i; |
120 |
+ |
Collection<Integer> elements = Arrays.asList(ints); |
121 |
|
try { |
122 |
< |
Integer[] ints = new Integer[SIZE]; |
110 |
< |
for (int i = 0; i < SIZE-1; ++i) |
111 |
< |
ints[i] = new Integer(i); |
112 |
< |
PriorityBlockingQueue q = new PriorityBlockingQueue(Arrays.asList(ints)); |
122 |
> |
new PriorityBlockingQueue(elements); |
123 |
|
shouldThrow(); |
124 |
|
} catch (NullPointerException success) {} |
125 |
|
} |
130 |
|
public void testConstructor6() { |
131 |
|
Integer[] ints = new Integer[SIZE]; |
132 |
|
for (int i = 0; i < SIZE; ++i) |
133 |
< |
ints[i] = new Integer(i); |
133 |
> |
ints[i] = i; |
134 |
|
PriorityBlockingQueue q = new PriorityBlockingQueue(Arrays.asList(ints)); |
135 |
|
for (int i = 0; i < SIZE; ++i) |
136 |
|
assertEquals(ints[i], q.poll()); |
185 |
|
} |
186 |
|
|
187 |
|
/** |
178 |
– |
* offer(null) throws NPE |
179 |
– |
*/ |
180 |
– |
public void testOfferNull() { |
181 |
– |
try { |
182 |
– |
PriorityBlockingQueue q = new PriorityBlockingQueue(1); |
183 |
– |
q.offer(null); |
184 |
– |
shouldThrow(); |
185 |
– |
} catch (NullPointerException success) {} |
186 |
– |
} |
187 |
– |
|
188 |
– |
/** |
189 |
– |
* add(null) throws NPE |
190 |
– |
*/ |
191 |
– |
public void testAddNull() { |
192 |
– |
try { |
193 |
– |
PriorityBlockingQueue q = new PriorityBlockingQueue(1); |
194 |
– |
q.add(null); |
195 |
– |
shouldThrow(); |
196 |
– |
} catch (NullPointerException success) {} |
197 |
– |
} |
198 |
– |
|
199 |
– |
/** |
188 |
|
* Offer of comparable element succeeds |
189 |
|
*/ |
190 |
|
public void testOffer() { |
218 |
|
} |
219 |
|
|
220 |
|
/** |
233 |
– |
* addAll(null) throws NPE |
234 |
– |
*/ |
235 |
– |
public void testAddAll1() { |
236 |
– |
try { |
237 |
– |
PriorityBlockingQueue q = new PriorityBlockingQueue(1); |
238 |
– |
q.addAll(null); |
239 |
– |
shouldThrow(); |
240 |
– |
} catch (NullPointerException success) {} |
241 |
– |
} |
242 |
– |
|
243 |
– |
/** |
221 |
|
* addAll(this) throws IAE |
222 |
|
*/ |
223 |
|
public void testAddAllSelf() { |
229 |
|
} |
230 |
|
|
231 |
|
/** |
255 |
– |
* addAll of a collection with null elements throws NPE |
256 |
– |
*/ |
257 |
– |
public void testAddAll2() { |
258 |
– |
try { |
259 |
– |
PriorityBlockingQueue q = new PriorityBlockingQueue(SIZE); |
260 |
– |
Integer[] ints = new Integer[SIZE]; |
261 |
– |
q.addAll(Arrays.asList(ints)); |
262 |
– |
shouldThrow(); |
263 |
– |
} catch (NullPointerException success) {} |
264 |
– |
} |
265 |
– |
|
266 |
– |
/** |
232 |
|
* addAll of a collection with any null elements throws NPE after |
233 |
|
* possibly adding some elements |
234 |
|
*/ |
259 |
|
} |
260 |
|
|
261 |
|
/** |
297 |
– |
* put(null) throws NPE |
298 |
– |
*/ |
299 |
– |
public void testPutNull() { |
300 |
– |
try { |
301 |
– |
PriorityBlockingQueue q = new PriorityBlockingQueue(SIZE); |
302 |
– |
q.put(null); |
303 |
– |
shouldThrow(); |
304 |
– |
} catch (NullPointerException success) {} |
305 |
– |
} |
306 |
– |
|
307 |
– |
/** |
262 |
|
* all elements successfully put are contained |
263 |
|
*/ |
264 |
|
public void testPut() { |
580 |
|
} |
581 |
|
|
582 |
|
/** |
629 |
– |
* toArray(null) throws NullPointerException |
630 |
– |
*/ |
631 |
– |
public void testToArray_NullArg() { |
632 |
– |
PriorityBlockingQueue q = populatedQueue(SIZE); |
633 |
– |
try { |
634 |
– |
q.toArray(null); |
635 |
– |
shouldThrow(); |
636 |
– |
} catch (NullPointerException success) {} |
637 |
– |
} |
638 |
– |
|
639 |
– |
/** |
583 |
|
* toArray(incompatible array type) throws ArrayStoreException |
584 |
|
*/ |
585 |
|
public void testToArray1_BadArg() { |
677 |
|
} |
678 |
|
|
679 |
|
/** |
737 |
– |
* drainTo(null) throws NPE |
738 |
– |
*/ |
739 |
– |
public void testDrainToNull() { |
740 |
– |
PriorityBlockingQueue q = populatedQueue(SIZE); |
741 |
– |
try { |
742 |
– |
q.drainTo(null); |
743 |
– |
shouldThrow(); |
744 |
– |
} catch (NullPointerException success) {} |
745 |
– |
} |
746 |
– |
|
747 |
– |
/** |
748 |
– |
* drainTo(this) throws IAE |
749 |
– |
*/ |
750 |
– |
public void testDrainToSelf() { |
751 |
– |
PriorityBlockingQueue q = populatedQueue(SIZE); |
752 |
– |
try { |
753 |
– |
q.drainTo(q); |
754 |
– |
shouldThrow(); |
755 |
– |
} catch (IllegalArgumentException success) {} |
756 |
– |
} |
757 |
– |
|
758 |
– |
/** |
680 |
|
* drainTo(c) empties queue into another collection c |
681 |
|
*/ |
682 |
|
public void testDrainTo() { |
721 |
|
} |
722 |
|
|
723 |
|
/** |
803 |
– |
* drainTo(null, n) throws NPE |
804 |
– |
*/ |
805 |
– |
public void testDrainToNullN() { |
806 |
– |
PriorityBlockingQueue q = populatedQueue(SIZE); |
807 |
– |
try { |
808 |
– |
q.drainTo(null, 0); |
809 |
– |
shouldThrow(); |
810 |
– |
} catch (NullPointerException success) {} |
811 |
– |
} |
812 |
– |
|
813 |
– |
/** |
814 |
– |
* drainTo(this, n) throws IAE |
815 |
– |
*/ |
816 |
– |
public void testDrainToSelfN() { |
817 |
– |
PriorityBlockingQueue q = populatedQueue(SIZE); |
818 |
– |
try { |
819 |
– |
q.drainTo(q, 0); |
820 |
– |
shouldThrow(); |
821 |
– |
} catch (IllegalArgumentException success) {} |
822 |
– |
} |
823 |
– |
|
824 |
– |
/** |
724 |
|
* drainTo(c, n) empties first min(n, size) elements of queue into c |
725 |
|
*/ |
726 |
|
public void testDrainToN() { |