ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/jsr166/jsr166/src/test/tck/Collection8Test.java
(Generate patch)

Comparing jsr166/src/test/tck/Collection8Test.java (file contents):
Revision 1.28 by jsr166, Fri Nov 18 17:23:29 2016 UTC vs.
Revision 1.30 by jsr166, Wed Nov 23 00:25:16 2016 UTC

# Line 545 | Line 545 | public class Collection8Test extends JSR
545          final AtomicBoolean done = new AtomicBoolean(false);
546          final Object one = impl.makeElement(1);
547          final Object two = impl.makeElement(2);
548 +        final Object[] emptyArray =
549 +            (Object[]) java.lang.reflect.Array.newInstance(one.getClass(), 0);
550          final List<Future<?>> futures;
551          final Phaser threadsStarted = new Phaser(1); // register this thread
552          final Runnable[] frobbers = {
# Line 564 | Line 566 | public class Collection8Test extends JSR
566                  for (Object x : c) assertTrue(x == one || x == two);
567              },
568              () -> {
569 +                for (Object x : c.toArray()) assertTrue(x == one || x == two);
570 +            },
571 +            () -> {
572 +                for (Object x : c.toArray(emptyArray)) assertTrue(x == one || x == two);
573 +            },
574 +            () -> {
575                  assertTrue(c.add(one));
576                  assertTrue(c.contains(one));
577                  assertTrue(c.remove(one));
# Line 598 | Line 606 | public class Collection8Test extends JSR
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   //     }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines