49 |
|
impl); |
50 |
|
} |
51 |
|
|
52 |
+ |
Object bomb() { |
53 |
+ |
return new Object() { |
54 |
+ |
public boolean equals(Object x) { throw new AssertionError(); } |
55 |
+ |
public int hashCode() { throw new AssertionError(); } |
56 |
+ |
}; |
57 |
+ |
} |
58 |
+ |
|
59 |
|
/** Checks properties of empty collections. */ |
60 |
|
public void testEmptyMeansEmpty() { |
61 |
|
Collection c = impl.emptyCollection(); |
62 |
+ |
emptyMeansEmpty(c); |
63 |
+ |
|
64 |
+ |
if (c instanceof java.io.Serializable) |
65 |
+ |
emptyMeansEmpty(serialClone(c)); |
66 |
+ |
|
67 |
+ |
Collection clone = cloneableClone(c); |
68 |
+ |
if (clone != null) |
69 |
+ |
emptyMeansEmpty(clone); |
70 |
+ |
} |
71 |
+ |
|
72 |
+ |
void emptyMeansEmpty(Collection c) { |
73 |
|
assertTrue(c.isEmpty()); |
74 |
|
assertEquals(0, c.size()); |
75 |
|
assertEquals("[]", c.toString()); |
99 |
|
c.iterator().forEachRemaining(alwaysThrows); |
100 |
|
c.spliterator().forEachRemaining(alwaysThrows); |
101 |
|
assertFalse(c.spliterator().tryAdvance(alwaysThrows)); |
102 |
< |
if (Queue.class.isAssignableFrom(impl.klazz())) { |
102 |
> |
if (c.spliterator().hasCharacteristics(Spliterator.SIZED)) |
103 |
> |
assertEquals(0, c.spliterator().estimateSize()); |
104 |
> |
assertFalse(c.contains(bomb())); |
105 |
> |
assertFalse(c.remove(bomb())); |
106 |
> |
if (c instanceof Queue) { |
107 |
|
Queue q = (Queue) c; |
108 |
|
assertNull(q.peek()); |
109 |
|
assertNull(q.poll()); |
110 |
|
} |
111 |
< |
if (Deque.class.isAssignableFrom(impl.klazz())) { |
111 |
> |
if (c instanceof Deque) { |
112 |
|
Deque d = (Deque) c; |
113 |
|
assertNull(d.peekFirst()); |
114 |
|
assertNull(d.peekLast()); |
115 |
|
assertNull(d.pollFirst()); |
116 |
|
assertNull(d.pollLast()); |
117 |
|
assertIteratorExhausted(d.descendingIterator()); |
118 |
+ |
d.descendingIterator().forEachRemaining(alwaysThrows); |
119 |
+ |
assertFalse(d.removeFirstOccurrence(bomb())); |
120 |
+ |
assertFalse(d.removeLastOccurrence(bomb())); |
121 |
|
} |
122 |
|
} |
123 |
|
|
130 |
|
() -> c.retainAll(null), |
131 |
|
() -> c.removeAll(null), |
132 |
|
() -> c.removeIf(null), |
133 |
+ |
() -> c.forEach(null), |
134 |
+ |
() -> c.iterator().forEachRemaining(null), |
135 |
+ |
() -> c.spliterator().forEachRemaining(null), |
136 |
+ |
() -> c.spliterator().tryAdvance(null), |
137 |
|
() -> c.toArray(null)); |
138 |
|
|
139 |
|
if (!impl.permitsNulls()) { |
157 |
|
() -> d.addLast(null), |
158 |
|
() -> d.offerFirst(null), |
159 |
|
() -> d.offerLast(null), |
160 |
< |
() -> d.push(null)); |
160 |
> |
() -> d.push(null), |
161 |
> |
() -> d.descendingIterator().forEachRemaining(null)); |
162 |
|
} |
163 |
|
} |
164 |
|
|
207 |
|
} |
208 |
|
}; |
209 |
|
try { |
210 |
< |
boolean modified = c.removeIf(randomPredicate); |
211 |
< |
if (!modified) { |
212 |
< |
assertNull(threwAt.get()); |
213 |
< |
assertEquals(n, rejects.size()); |
214 |
< |
assertEquals(0, accepts.size()); |
215 |
< |
} |
216 |
< |
} catch (ArithmeticException ok) {} |
217 |
< |
survivors.removeAll(accepts); |
218 |
< |
if (n - accepts.size() != c.size()) { |
210 |
> |
assertFalse(survivors.contains(null)); |
211 |
> |
try { |
212 |
> |
boolean modified = c.removeIf(randomPredicate); |
213 |
> |
if (!modified) { |
214 |
> |
assertNull(threwAt.get()); |
215 |
> |
assertEquals(n, rejects.size()); |
216 |
> |
assertEquals(0, accepts.size()); |
217 |
> |
} |
218 |
> |
} catch (ArithmeticException ok) {} |
219 |
> |
survivors.removeAll(accepts); |
220 |
> |
assertEquals(n - accepts.size(), c.size()); |
221 |
> |
assertTrue(c.containsAll(survivors)); |
222 |
> |
assertTrue(survivors.containsAll(rejects)); |
223 |
> |
for (Object x : accepts) assertFalse(c.contains(x)); |
224 |
> |
if (threwAt.get() == null) |
225 |
> |
assertEquals(accepts.size() + rejects.size(), n); |
226 |
> |
} catch (Throwable ex) { |
227 |
|
System.err.println(impl.klazz()); |
228 |
< |
System.err.println(c); |
229 |
< |
System.err.println(accepts); |
230 |
< |
System.err.println(rejects); |
231 |
< |
System.err.println(survivors); |
232 |
< |
System.err.println(threwAt.get()); |
233 |
< |
} |
234 |
< |
assertEquals(n - accepts.size(), c.size()); |
235 |
< |
assertTrue(c.containsAll(survivors)); |
198 |
< |
assertTrue(survivors.containsAll(rejects)); |
199 |
< |
for (Object x : accepts) assertFalse(c.contains(x)); |
200 |
< |
if (threwAt.get() == null) |
201 |
< |
assertEquals(accepts.size() + rejects.size(), n); |
228 |
> |
System.err.printf("c=%s%n", c); |
229 |
> |
System.err.printf("n=%d%n", n); |
230 |
> |
System.err.printf("accepts=%s%n", accepts); |
231 |
> |
System.err.printf("rejects=%s%n", rejects); |
232 |
> |
System.err.printf("survivors=%s%n", survivors); |
233 |
> |
System.err.printf("threw=%s%n", threwAt.get()); |
234 |
> |
throw ex; |
235 |
> |
} |
236 |
|
} |
237 |
|
|
238 |
|
/** |