182 |
|
() -> c.iterator().forEachRemaining(null), |
183 |
|
() -> c.spliterator().forEachRemaining(null), |
184 |
|
() -> c.spliterator().tryAdvance(null), |
185 |
< |
() -> c.toArray(null)); |
185 |
> |
() -> c.toArray((Object[])null)); |
186 |
|
|
187 |
|
if (!impl.permitsNulls()) { |
188 |
|
assertThrows( |
210 |
|
BlockingQueue q = (BlockingQueue) c; |
211 |
|
assertThrows( |
212 |
|
NullPointerException.class, |
213 |
< |
() -> { |
214 |
< |
try { q.offer(null, 1L, HOURS); } |
215 |
< |
catch (InterruptedException ex) { |
216 |
< |
throw new AssertionError(ex); |
217 |
< |
}}, |
218 |
< |
() -> { |
219 |
< |
try { q.put(null); } |
220 |
< |
catch (InterruptedException ex) { |
221 |
< |
throw new AssertionError(ex); |
222 |
< |
}}); |
213 |
> |
() -> q.offer(null, 1L, HOURS), |
214 |
> |
() -> q.put(null)); |
215 |
|
} |
216 |
|
if (c instanceof BlockingDeque) { |
217 |
|
BlockingDeque q = (BlockingDeque) c; |
218 |
|
assertThrows( |
219 |
|
NullPointerException.class, |
220 |
< |
() -> { |
221 |
< |
try { q.offerFirst(null, 1L, HOURS); } |
222 |
< |
catch (InterruptedException ex) { |
223 |
< |
throw new AssertionError(ex); |
232 |
< |
}}, |
233 |
< |
() -> { |
234 |
< |
try { q.offerLast(null, 1L, HOURS); } |
235 |
< |
catch (InterruptedException ex) { |
236 |
< |
throw new AssertionError(ex); |
237 |
< |
}}, |
238 |
< |
() -> { |
239 |
< |
try { q.putFirst(null); } |
240 |
< |
catch (InterruptedException ex) { |
241 |
< |
throw new AssertionError(ex); |
242 |
< |
}}, |
243 |
< |
() -> { |
244 |
< |
try { q.putLast(null); } |
245 |
< |
catch (InterruptedException ex) { |
246 |
< |
throw new AssertionError(ex); |
247 |
< |
}}); |
220 |
> |
() -> q.offerFirst(null, 1L, HOURS), |
221 |
> |
() -> q.offerLast(null, 1L, HOURS), |
222 |
> |
() -> q.putFirst(null), |
223 |
> |
() -> q.putLast(null)); |
224 |
|
} |
225 |
|
} |
226 |
|
|
413 |
|
if (rnd.nextBoolean()) assertTrue(it.hasNext()); |
414 |
|
it.next(); |
415 |
|
} |
440 |
– |
Consumer alwaysThrows = e -> { throw new AssertionError(); }; |
416 |
|
// TODO: many more removal methods |
417 |
|
if (rnd.nextBoolean()) { |
418 |
|
for (Iterator z = c.iterator(); z.hasNext(); ) { |
564 |
|
public void testRemoveAfterForEachRemaining() { |
565 |
|
Collection c = impl.emptyCollection(); |
566 |
|
ThreadLocalRandom rnd = ThreadLocalRandom.current(); |
567 |
+ |
ArrayList copy = new ArrayList(); |
568 |
+ |
boolean ordered = c.spliterator().hasCharacteristics(Spliterator.ORDERED); |
569 |
|
testCollection: { |
570 |
|
int n = 3 + rnd.nextInt(2); |
571 |
< |
for (int i = 0; i < n; i++) c.add(impl.makeElement(i)); |
571 |
> |
for (int i = 0; i < n; i++) { |
572 |
> |
Object x = impl.makeElement(i); |
573 |
> |
c.add(x); |
574 |
> |
copy.add(x); |
575 |
> |
} |
576 |
|
Iterator it = c.iterator(); |
577 |
< |
assertTrue(it.hasNext()); |
578 |
< |
assertEquals(impl.makeElement(0), it.next()); |
579 |
< |
assertTrue(it.hasNext()); |
580 |
< |
assertEquals(impl.makeElement(1), it.next()); |
581 |
< |
it.forEachRemaining(e -> assertTrue(c.contains(e))); |
577 |
> |
if (ordered) { |
578 |
> |
if (rnd.nextBoolean()) assertTrue(it.hasNext()); |
579 |
> |
assertEquals(impl.makeElement(0), it.next()); |
580 |
> |
if (rnd.nextBoolean()) assertTrue(it.hasNext()); |
581 |
> |
assertEquals(impl.makeElement(1), it.next()); |
582 |
> |
} else { |
583 |
> |
if (rnd.nextBoolean()) assertTrue(it.hasNext()); |
584 |
> |
assertTrue(copy.contains(it.next())); |
585 |
> |
if (rnd.nextBoolean()) assertTrue(it.hasNext()); |
586 |
> |
assertTrue(copy.contains(it.next())); |
587 |
> |
} |
588 |
> |
if (rnd.nextBoolean()) assertTrue(it.hasNext()); |
589 |
> |
it.forEachRemaining( |
590 |
> |
e -> { |
591 |
> |
assertTrue(c.contains(e)); |
592 |
> |
assertTrue(copy.contains(e));}); |
593 |
|
if (testImplementationDetails) { |
594 |
|
if (c instanceof java.util.concurrent.ArrayBlockingQueue) { |
595 |
|
assertIteratorExhausted(it); |
599 |
|
break testCollection; |
600 |
|
} |
601 |
|
assertEquals(n - 1, c.size()); |
602 |
< |
for (int i = 0; i < n - 1; i++) |
603 |
< |
assertTrue(c.contains(impl.makeElement(i))); |
604 |
< |
assertFalse(c.contains(impl.makeElement(n - 1))); |
602 |
> |
if (ordered) { |
603 |
> |
for (int i = 0; i < n - 1; i++) |
604 |
> |
assertTrue(c.contains(impl.makeElement(i))); |
605 |
> |
assertFalse(c.contains(impl.makeElement(n - 1))); |
606 |
> |
} |
607 |
|
} |
608 |
|
} |
609 |
|
} |
610 |
|
if (c instanceof Deque) { |
611 |
|
Deque d = (Deque) impl.emptyCollection(); |
612 |
+ |
assertTrue(ordered); |
613 |
|
int n = 3 + rnd.nextInt(2); |
614 |
|
for (int i = 0; i < n; i++) d.add(impl.makeElement(i)); |
615 |
|
Iterator it = d.descendingIterator(); |
633 |
|
*/ |
634 |
|
public void testStreamForEach() throws Throwable { |
635 |
|
final Collection c = impl.emptyCollection(); |
641 |
– |
final AtomicLong count = new AtomicLong(0L); |
636 |
|
final Object x = impl.makeElement(1); |
637 |
|
final Object y = impl.makeElement(2); |
638 |
|
final ArrayList found = new ArrayList(); |
690 |
|
*/ |
691 |
|
public void testForEach() throws Throwable { |
692 |
|
final Collection c = impl.emptyCollection(); |
699 |
– |
final AtomicLong count = new AtomicLong(0L); |
693 |
|
final Object x = impl.makeElement(1); |
694 |
|
final Object y = impl.makeElement(2); |
695 |
|
final ArrayList found = new ArrayList(); |
925 |
|
} catch (java.io.NotSerializableException acceptable) {} |
926 |
|
} |
927 |
|
|
928 |
+ |
/** |
929 |
+ |
* TODO: move out of limbo |
930 |
+ |
* 8203662: remove increment of modCount from ArrayList and Vector replaceAll() |
931 |
+ |
*/ |
932 |
+ |
public void DISABLED_testReplaceAllIsNotStructuralModification() { |
933 |
+ |
Collection c = impl.emptyCollection(); |
934 |
+ |
if (!(c instanceof List)) |
935 |
+ |
return; |
936 |
+ |
List list = (List) c; |
937 |
+ |
ThreadLocalRandom rnd = ThreadLocalRandom.current(); |
938 |
+ |
for (int n = rnd.nextInt(2, 10); n--> 0; ) |
939 |
+ |
list.add(impl.makeElement(rnd.nextInt())); |
940 |
+ |
ArrayList copy = new ArrayList(list); |
941 |
+ |
int size = list.size(), half = size / 2; |
942 |
+ |
Iterator it = list.iterator(); |
943 |
+ |
for (int i = 0; i < half; i++) |
944 |
+ |
assertEquals(it.next(), copy.get(i)); |
945 |
+ |
list.replaceAll(n -> n); |
946 |
+ |
// ConcurrentModificationException must not be thrown here. |
947 |
+ |
for (int i = half; i < size; i++) |
948 |
+ |
assertEquals(it.next(), copy.get(i)); |
949 |
+ |
} |
950 |
+ |
|
951 |
|
// public void testCollection8DebugFail() { |
952 |
|
// fail(impl.klazz().getSimpleName()); |
953 |
|
// } |