365 |
|
|
366 |
|
/** |
367 |
|
* Calling Iterator#remove() after Iterator#forEachRemaining |
368 |
< |
* should remove last element |
368 |
> |
* should (maybe) remove last element |
369 |
|
*/ |
370 |
|
public void testRemoveAfterForEachRemaining() { |
371 |
|
Collection c = impl.emptyCollection(); |
378 |
|
assertEquals(impl.makeElement(0), it.next()); |
379 |
|
assertTrue(it.hasNext()); |
380 |
|
assertEquals(impl.makeElement(1), it.next()); |
381 |
< |
it.forEachRemaining(e -> {}); |
382 |
< |
it.remove(); |
383 |
< |
assertEquals(n - 1, c.size()); |
384 |
< |
for (int i = 0; i < n - 1; i++) |
385 |
< |
assertTrue(c.contains(impl.makeElement(i))); |
386 |
< |
assertFalse(c.contains(impl.makeElement(n - 1))); |
381 |
> |
it.forEachRemaining(e -> assertTrue(c.contains(e))); |
382 |
> |
if (testImplementationDetails) { |
383 |
> |
if (c instanceof java.util.concurrent.ArrayBlockingQueue) { |
384 |
> |
assertIteratorExhausted(it); |
385 |
> |
} else { |
386 |
> |
it.remove(); |
387 |
> |
assertEquals(n - 1, c.size()); |
388 |
> |
for (int i = 0; i < n - 1; i++) |
389 |
> |
assertTrue(c.contains(impl.makeElement(i))); |
390 |
> |
assertFalse(c.contains(impl.makeElement(n - 1))); |
391 |
> |
} |
392 |
> |
} |
393 |
|
} |
394 |
|
if (c instanceof Deque) { |
395 |
|
Deque d = (Deque) impl.emptyCollection(); |
400 |
|
assertEquals(impl.makeElement(n - 1), it.next()); |
401 |
|
assertTrue(it.hasNext()); |
402 |
|
assertEquals(impl.makeElement(n - 2), it.next()); |
403 |
< |
it.forEachRemaining(e -> {}); |
404 |
< |
it.remove(); |
405 |
< |
assertEquals(n - 1, d.size()); |
406 |
< |
for (int i = 1; i < n; i++) |
407 |
< |
assertTrue(d.contains(impl.makeElement(i))); |
408 |
< |
assertFalse(d.contains(impl.makeElement(0))); |
403 |
> |
it.forEachRemaining(e -> assertTrue(c.contains(e))); |
404 |
> |
if (testImplementationDetails) { |
405 |
> |
it.remove(); |
406 |
> |
assertEquals(n - 1, d.size()); |
407 |
> |
for (int i = 1; i < n; i++) |
408 |
> |
assertTrue(d.contains(impl.makeElement(i))); |
409 |
> |
assertFalse(d.contains(impl.makeElement(0))); |
410 |
> |
} |
411 |
|
} |
412 |
|
} |
413 |
|
|
420 |
|
final Object x = impl.makeElement(1); |
421 |
|
final Object y = impl.makeElement(2); |
422 |
|
final ArrayList found = new ArrayList(); |
423 |
< |
Consumer<Object> spy = o -> { found.add(o); }; |
423 |
> |
Consumer<Object> spy = o -> found.add(o); |
424 |
|
c.stream().forEach(spy); |
425 |
|
assertTrue(found.isEmpty()); |
426 |
|
|
454 |
|
Runnable checkElt = () -> { |
455 |
|
threadsStarted.countDown(); |
456 |
|
while (!done.get()) |
457 |
< |
c.stream().forEach(x -> { assertSame(x, elt); }); }; |
457 |
> |
c.stream().forEach(x -> assertSame(x, elt)); }; |
458 |
|
Runnable addRemove = () -> { |
459 |
|
threadsStarted.countDown(); |
460 |
|
while (!done.get()) { |
478 |
|
final Object x = impl.makeElement(1); |
479 |
|
final Object y = impl.makeElement(2); |
480 |
|
final ArrayList found = new ArrayList(); |
481 |
< |
Consumer<Object> spy = o -> { found.add(o); }; |
481 |
> |
Consumer<Object> spy = o -> found.add(o); |
482 |
|
c.forEach(spy); |
483 |
|
assertTrue(found.isEmpty()); |
484 |
|
|
512 |
|
Runnable checkElt = () -> { |
513 |
|
threadsStarted.countDown(); |
514 |
|
while (!done.get()) |
515 |
< |
c.forEach(x -> { assertSame(x, elt); }); }; |
515 |
> |
c.forEach(x -> assertSame(x, elt)); }; |
516 |
|
Runnable addRemove = () -> { |
517 |
|
threadsStarted.countDown(); |
518 |
|
while (!done.get()) { |