606 |
|
assertNull(future.get(0L, MILLISECONDS)); |
607 |
|
} |
608 |
|
|
609 |
+ |
/** |
610 |
+ |
* Spliterators are either IMMUTABLE or truly late-binding or, if |
611 |
+ |
* concurrent, use the same "late-binding style" of returning |
612 |
+ |
* elements added between creation and first use. |
613 |
+ |
*/ |
614 |
+ |
public void testLateBindingStyle() { |
615 |
+ |
if (!testImplementationDetails) return; |
616 |
+ |
// Immutable (snapshot) spliterators are exempt |
617 |
+ |
if (impl.emptyCollection().spliterator() |
618 |
+ |
.hasCharacteristics(Spliterator.IMMUTABLE)) |
619 |
+ |
return; |
620 |
+ |
final Object one = impl.makeElement(1); |
621 |
+ |
{ |
622 |
+ |
final Collection c = impl.emptyCollection(); |
623 |
+ |
final Spliterator split = c.spliterator(); |
624 |
+ |
c.add(one); |
625 |
+ |
assertTrue(split.tryAdvance(e -> { assertSame(e, one); })); |
626 |
+ |
assertFalse(split.tryAdvance(e -> { throw new AssertionError(); })); |
627 |
+ |
assertTrue(c.contains(one)); |
628 |
+ |
} |
629 |
+ |
{ |
630 |
+ |
final AtomicLong count = new AtomicLong(0); |
631 |
+ |
final Collection c = impl.emptyCollection(); |
632 |
+ |
final Spliterator split = c.spliterator(); |
633 |
+ |
c.add(one); |
634 |
+ |
split.forEachRemaining( |
635 |
+ |
e -> { assertSame(e, one); count.getAndIncrement(); }); |
636 |
+ |
assertEquals(1L, count.get()); |
637 |
+ |
assertFalse(split.tryAdvance(e -> { throw new AssertionError(); })); |
638 |
+ |
assertTrue(c.contains(one)); |
639 |
+ |
} |
640 |
+ |
} |
641 |
+ |
|
642 |
|
// public void testCollection8DebugFail() { |
643 |
|
// fail(impl.klazz().getSimpleName()); |
644 |
|
// } |