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.31 by jsr166, Wed Nov 23 02:20:56 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 +        if (impl.klazz() == ArrayList.class) return; // for jdk8
617 +        // Immutable (snapshot) spliterators are exempt
618 +        if (impl.emptyCollection().spliterator()
619 +            .hasCharacteristics(Spliterator.IMMUTABLE))
620 +            return;
621 +        final Object one = impl.makeElement(1);
622 +        {
623 +            final Collection c = impl.emptyCollection();
624 +            final Spliterator split = c.spliterator();
625 +            c.add(one);
626 +            assertTrue(split.tryAdvance(e -> { assertSame(e, one); }));
627 +            assertFalse(split.tryAdvance(e -> { throw new AssertionError(); }));
628 +            assertTrue(c.contains(one));
629 +        }
630 +        {
631 +            final AtomicLong count = new AtomicLong(0);
632 +            final Collection c = impl.emptyCollection();
633 +            final Spliterator split = c.spliterator();
634 +            c.add(one);
635 +            split.forEachRemaining(
636 +                e -> { assertSame(e, one); count.getAndIncrement(); });
637 +            assertEquals(1L, count.get());
638 +            assertFalse(split.tryAdvance(e -> { throw new AssertionError(); }));
639 +            assertTrue(c.contains(one));
640 +        }
641 +    }
642 +
643   //     public void testCollection8DebugFail() {
644   //         fail(impl.klazz().getSimpleName());
645   //     }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines