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.48 by jsr166, Sat Mar 24 14:46:18 2018 UTC vs.
Revision 1.52 by jsr166, Sat May 5 18:29:53 2018 UTC

# Line 8 | Line 8
8   import static java.util.concurrent.TimeUnit.HOURS;
9   import static java.util.concurrent.TimeUnit.MILLISECONDS;
10  
11 + import java.util.ArrayDeque;
12   import java.util.ArrayList;
13   import java.util.Arrays;
14   import java.util.Collection;
# Line 101 | Line 102 | public class Collection8Test extends JSR
102              assertEquals(Collections.emptyList(), x);
103              assertEquals(-1, x.indexOf(impl.makeElement(86)));
104              assertEquals(-1, x.lastIndexOf(impl.makeElement(99)));
105 +            assertThrows(
106 +                IndexOutOfBoundsException.class,
107 +                () -> x.get(0),
108 +                () -> x.set(0, impl.makeElement(42)));
109          }
110          else if (c instanceof Set<?>) {
111              assertEquals(0, c.hashCode());
# Line 902 | Line 907 | public class Collection8Test extends JSR
907          }
908      }
909  
910 +    public void testCollectionCopies() throws Exception {
911 +        ThreadLocalRandom rnd = ThreadLocalRandom.current();
912 +        Collection c = impl.emptyCollection();
913 +        for (int n = rnd.nextInt(4); n--> 0; )
914 +            c.add(impl.makeElement(rnd.nextInt()));
915 +        assertEquals(c, c);
916 +        if (c instanceof List)
917 +            assertCollectionsEquals(c, new ArrayList(c));
918 +        else if (c instanceof Set)
919 +            assertCollectionsEquals(c, new HashSet(c));
920 +        else if (c instanceof Deque)
921 +            assertCollectionsEquivalent(c, new ArrayDeque(c));
922 +
923 +        Collection clone = cloneableClone(c);
924 +        if (clone != null) {
925 +            assertSame(c.getClass(), clone.getClass());
926 +            assertCollectionsEquivalent(c, clone);
927 +        }
928 +        try {
929 +            Collection serialClone = serialClonePossiblyFailing(c);
930 +            assertSame(c.getClass(), serialClone.getClass());
931 +            assertCollectionsEquivalent(c, serialClone);
932 +        } catch (java.io.NotSerializableException acceptable) {}
933 +    }
934 +
935 +    public void testReplaceAllIsNotStructuralModification() {
936 +        Collection c = impl.emptyCollection();
937 +        if (!(c instanceof List))
938 +            return;
939 +        List list = (List) c;
940 +        ThreadLocalRandom rnd = ThreadLocalRandom.current();
941 +        for (int n = rnd.nextInt(2, 10); n--> 0; )
942 +            list.add(impl.makeElement(rnd.nextInt()));
943 +        ArrayList copy = new ArrayList(list);
944 +        int size = list.size(), half = size / 2;
945 +        Iterator it = list.iterator();
946 +        for (int i = 0; i < half; i++)
947 +            assertEquals(it.next(), copy.get(i));
948 +        list.replaceAll(n -> n);
949 +        // ConcurrentModificationException must not be thrown here.
950 +        for (int i = half; i < size; i++)
951 +            assertEquals(it.next(), copy.get(i));
952 +    }
953 +
954   //     public void testCollection8DebugFail() {
955   //         fail(impl.klazz().getSimpleName());
956   //     }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines