53 |
|
} |
54 |
|
|
55 |
|
/** |
56 |
< |
* Constructor throws IAE if capacity argument nonpositive |
56 |
> |
* Constructor throws IAE if capacity argument nonpositive |
57 |
|
*/ |
58 |
|
public void testConstructor2() { |
59 |
|
try { |
60 |
|
PriorityQueue q = new PriorityQueue(0); |
61 |
|
shouldThrow(); |
62 |
< |
} |
63 |
< |
catch (IllegalArgumentException success) {} |
62 |
> |
} catch (IllegalArgumentException success) {} |
63 |
|
} |
64 |
|
|
65 |
|
/** |
69 |
|
try { |
70 |
|
PriorityQueue q = new PriorityQueue((Collection)null); |
71 |
|
shouldThrow(); |
72 |
< |
} |
74 |
< |
catch (NullPointerException success) {} |
72 |
> |
} catch (NullPointerException success) {} |
73 |
|
} |
74 |
|
|
75 |
|
/** |
80 |
|
Integer[] ints = new Integer[SIZE]; |
81 |
|
PriorityQueue q = new PriorityQueue(Arrays.asList(ints)); |
82 |
|
shouldThrow(); |
83 |
< |
} |
86 |
< |
catch (NullPointerException success) {} |
83 |
> |
} catch (NullPointerException success) {} |
84 |
|
} |
85 |
|
|
86 |
|
/** |
93 |
|
ints[i] = new Integer(i); |
94 |
|
PriorityQueue q = new PriorityQueue(Arrays.asList(ints)); |
95 |
|
shouldThrow(); |
96 |
< |
} |
100 |
< |
catch (NullPointerException success) {} |
96 |
> |
} catch (NullPointerException success) {} |
97 |
|
} |
98 |
|
|
99 |
|
/** |
166 |
|
PriorityQueue q = new PriorityQueue(1); |
167 |
|
q.offer(null); |
168 |
|
shouldThrow(); |
169 |
< |
} catch (NullPointerException success) { } |
169 |
> |
} catch (NullPointerException success) {} |
170 |
|
} |
171 |
|
|
172 |
|
/** |
177 |
|
PriorityQueue q = new PriorityQueue(1); |
178 |
|
q.add(null); |
179 |
|
shouldThrow(); |
180 |
< |
} catch (NullPointerException success) { } |
180 |
> |
} catch (NullPointerException success) {} |
181 |
|
} |
182 |
|
|
183 |
|
/** |
199 |
|
q.offer(new Object()); |
200 |
|
q.offer(new Object()); |
201 |
|
shouldThrow(); |
202 |
< |
} |
207 |
< |
catch (ClassCastException success) {} |
202 |
> |
} catch (ClassCastException success) {} |
203 |
|
} |
204 |
|
|
205 |
|
/** |
221 |
|
PriorityQueue q = new PriorityQueue(1); |
222 |
|
q.addAll(null); |
223 |
|
shouldThrow(); |
224 |
< |
} |
230 |
< |
catch (NullPointerException success) {} |
224 |
> |
} catch (NullPointerException success) {} |
225 |
|
} |
226 |
|
/** |
227 |
|
* addAll of a collection with null elements throws NPE |
232 |
|
Integer[] ints = new Integer[SIZE]; |
233 |
|
q.addAll(Arrays.asList(ints)); |
234 |
|
shouldThrow(); |
235 |
< |
} |
242 |
< |
catch (NullPointerException success) {} |
235 |
> |
} catch (NullPointerException success) {} |
236 |
|
} |
237 |
|
/** |
238 |
|
* addAll of a collection with any null elements throws NPE after |
246 |
|
ints[i] = new Integer(i); |
247 |
|
q.addAll(Arrays.asList(ints)); |
248 |
|
shouldThrow(); |
249 |
< |
} |
257 |
< |
catch (NullPointerException success) {} |
249 |
> |
} catch (NullPointerException success) {} |
250 |
|
} |
251 |
|
|
252 |
|
/** |
304 |
|
try { |
305 |
|
q.element(); |
306 |
|
shouldThrow(); |
307 |
< |
} |
316 |
< |
catch (NoSuchElementException success) {} |
307 |
> |
} catch (NoSuchElementException success) {} |
308 |
|
} |
309 |
|
|
310 |
|
/** |
318 |
|
try { |
319 |
|
q.remove(); |
320 |
|
shouldThrow(); |
321 |
< |
} catch (NoSuchElementException success) { |
331 |
< |
} |
321 |
> |
} catch (NoSuchElementException success) {} |
322 |
|
} |
323 |
|
|
324 |
|
/** |
482 |
|
/** |
483 |
|
* A deserialized serialized queue has same elements |
484 |
|
*/ |
485 |
< |
public void testSerialization() { |
485 |
> |
public void testSerialization() throws Exception { |
486 |
|
PriorityQueue q = populatedQueue(SIZE); |
487 |
< |
try { |
488 |
< |
ByteArrayOutputStream bout = new ByteArrayOutputStream(10000); |
489 |
< |
ObjectOutputStream out = new ObjectOutputStream(new BufferedOutputStream(bout)); |
490 |
< |
out.writeObject(q); |
491 |
< |
out.close(); |
492 |
< |
|
493 |
< |
ByteArrayInputStream bin = new ByteArrayInputStream(bout.toByteArray()); |
494 |
< |
ObjectInputStream in = new ObjectInputStream(new BufferedInputStream(bin)); |
495 |
< |
PriorityQueue r = (PriorityQueue)in.readObject(); |
496 |
< |
assertEquals(q.size(), r.size()); |
497 |
< |
while (!q.isEmpty()) |
508 |
< |
assertEquals(q.remove(), r.remove()); |
509 |
< |
} catch (Exception e) { |
510 |
< |
unexpectedException(); |
511 |
< |
} |
487 |
> |
ByteArrayOutputStream bout = new ByteArrayOutputStream(10000); |
488 |
> |
ObjectOutputStream out = new ObjectOutputStream(new BufferedOutputStream(bout)); |
489 |
> |
out.writeObject(q); |
490 |
> |
out.close(); |
491 |
> |
|
492 |
> |
ByteArrayInputStream bin = new ByteArrayInputStream(bout.toByteArray()); |
493 |
> |
ObjectInputStream in = new ObjectInputStream(new BufferedInputStream(bin)); |
494 |
> |
PriorityQueue r = (PriorityQueue)in.readObject(); |
495 |
> |
assertEquals(q.size(), r.size()); |
496 |
> |
while (!q.isEmpty()) |
497 |
> |
assertEquals(q.remove(), r.remove()); |
498 |
|
} |
499 |
|
} |