61 |
|
} |
62 |
|
|
63 |
|
/** Checks properties of empty collections. */ |
64 |
< |
public void testEmptyMeansEmpty() throws InterruptedException { |
64 |
> |
public void testEmptyMeansEmpty() throws Throwable { |
65 |
|
Collection c = impl.emptyCollection(); |
66 |
|
emptyMeansEmpty(c); |
67 |
|
|
68 |
< |
if (c instanceof java.io.Serializable) |
69 |
< |
emptyMeansEmpty(serialClone(c)); |
68 |
> |
if (c instanceof java.io.Serializable) { |
69 |
> |
try { |
70 |
> |
emptyMeansEmpty(serialClonePossiblyFailing(c)); |
71 |
> |
} catch (java.io.NotSerializableException ex) { |
72 |
> |
// excusable when we have a serializable wrapper around |
73 |
> |
// a non-serializable collection, as can happen with: |
74 |
> |
// Vector.subList() => wrapped AbstractList$RandomAccessSubList |
75 |
> |
if (testImplementationDetails |
76 |
> |
&& (! c.getClass().getName().matches( |
77 |
> |
"java.util.Collections.*"))) |
78 |
> |
throw ex; |
79 |
> |
} |
80 |
> |
} |
81 |
|
|
82 |
|
Collection clone = cloneableClone(c); |
83 |
|
if (clone != null) |
252 |
|
|
253 |
|
public void testRemoveIf() { |
254 |
|
Collection c = impl.emptyCollection(); |
255 |
+ |
boolean ordered = |
256 |
+ |
c.spliterator().hasCharacteristics(Spliterator.ORDERED); |
257 |
|
ThreadLocalRandom rnd = ThreadLocalRandom.current(); |
258 |
|
int n = rnd.nextInt(6); |
259 |
|
for (int i = 0; i < n; i++) c.add(impl.makeElement(i)); |
285 |
|
assertEquals(modified, accepts.size() > 0); |
286 |
|
assertEquals(modified, rejects.size() != n); |
287 |
|
assertEquals(accepts.size() + rejects.size(), n); |
288 |
< |
assertEquals(rejects, Arrays.asList(c.toArray())); |
288 |
> |
if (ordered) { |
289 |
> |
assertEquals(rejects, |
290 |
> |
Arrays.asList(c.toArray())); |
291 |
> |
} else { |
292 |
> |
assertEquals(new HashSet(rejects), |
293 |
> |
new HashSet(Arrays.asList(c.toArray()))); |
294 |
> |
} |
295 |
|
} catch (ArithmeticException ok) { |
296 |
|
assertNotNull(threwAt.get()); |
297 |
|
assertTrue(c.contains(threwAt.get())); |
312 |
|
assertTrue(c.containsAll(rejects)); |
313 |
|
assertTrue(c.containsAll(survivors)); |
314 |
|
assertTrue(survivors.containsAll(rejects)); |
315 |
< |
assertEquals(n - accepts.size(), c.size()); |
316 |
< |
for (Object x : accepts) assertFalse(c.contains(x)); |
315 |
> |
if (threwAt.get() == null) { |
316 |
> |
assertEquals(n - accepts.size(), c.size()); |
317 |
> |
for (Object x : accepts) assertFalse(c.contains(x)); |
318 |
> |
} else { |
319 |
> |
// Two acceptable behaviors: entire removeIf call is one |
320 |
> |
// transaction, or each element processed is one transaction. |
321 |
> |
assertTrue(n == c.size() || n == c.size() + accepts.size()); |
322 |
> |
int k = 0; |
323 |
> |
for (Object x : accepts) if (c.contains(x)) k++; |
324 |
> |
assertTrue(k == accepts.size() || k == 0); |
325 |
> |
} |
326 |
|
} catch (Throwable ex) { |
327 |
|
System.err.println(impl.klazz()); |
328 |
< |
System.err.printf("c=%s%n", c); |
328 |
> |
// c is at risk of corruption if we got here, so be lenient |
329 |
> |
try { System.err.printf("c=%s%n", c); } |
330 |
> |
catch (Throwable t) { t.printStackTrace(); } |
331 |
|
System.err.printf("n=%d%n", n); |
332 |
|
System.err.printf("orig=%s%n", orig); |
333 |
|
System.err.printf("accepts=%s%n", accepts); |