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.46 by jsr166, Mon May 29 19:15:02 2017 UTC vs.
Revision 1.50 by jsr166, Wed Apr 4 03:35:13 2018 UTC

# Line 19 | Line 19 | import java.util.Iterator;
19   import java.util.List;
20   import java.util.NoSuchElementException;
21   import java.util.Queue;
22 + import java.util.Set;
23   import java.util.Spliterator;
24   import java.util.concurrent.BlockingDeque;
25   import java.util.concurrent.BlockingQueue;
# Line 59 | Line 60 | public class Collection8Test extends JSR
60  
61      Object bomb() {
62          return new Object() {
63 <                public boolean equals(Object x) { throw new AssertionError(); }
64 <                public int hashCode() { throw new AssertionError(); }
65 <            };
63 >            @Override public boolean equals(Object x) { throw new AssertionError(); }
64 >            @Override public int hashCode() { throw new AssertionError(); }
65 >            @Override public String toString() { throw new AssertionError(); }
66 >        };
67      }
68  
69      /** Checks properties of empty collections. */
# Line 92 | Line 94 | public class Collection8Test extends JSR
94          assertTrue(c.isEmpty());
95          assertEquals(0, c.size());
96          assertEquals("[]", c.toString());
97 +        if (c instanceof List<?>) {
98 +            List x = (List) c;
99 +            assertEquals(1, x.hashCode());
100 +            assertEquals(x, Collections.emptyList());
101 +            assertEquals(Collections.emptyList(), x);
102 +            assertEquals(-1, x.indexOf(impl.makeElement(86)));
103 +            assertEquals(-1, x.lastIndexOf(impl.makeElement(99)));
104 +            assertThrows(
105 +                IndexOutOfBoundsException.class,
106 +                () -> x.get(0),
107 +                () -> x.set(0, impl.makeElement(42)));
108 +        }
109 +        else if (c instanceof Set<?>) {
110 +            assertEquals(0, c.hashCode());
111 +            assertEquals(c, Collections.emptySet());
112 +            assertEquals(Collections.emptySet(), c);
113 +        }
114          {
115              Object[] a = c.toArray();
116              assertEquals(0, a.length);
# Line 252 | Line 271 | public class Collection8Test extends JSR
271                  () -> d.pop(),
272                  () -> d.descendingIterator().next());
273          }
274 +        if (c instanceof List) {
275 +            List x = (List) c;
276 +            assertThrows(
277 +                NoSuchElementException.class,
278 +                () -> x.iterator().next(),
279 +                () -> x.listIterator().next(),
280 +                () -> x.listIterator(0).next(),
281 +                () -> x.listIterator().previous(),
282 +                () -> x.listIterator(0).previous());
283 +        }
284      }
285  
286      public void testRemoveIf() {
# Line 877 | Line 906 | public class Collection8Test extends JSR
906          }
907      }
908  
909 +    public void testObjectMethods() {
910 +        ThreadLocalRandom rnd = ThreadLocalRandom.current();
911 +        Collection c = impl.emptyCollection();
912 +        for (int n = rnd.nextInt(3); n--> 0; )
913 +            c.add(impl.makeElement(rnd.nextInt()));
914 +        assertEquals(c, c);
915 +        if (c instanceof List) {
916 +            List copy = new ArrayList(c);
917 +            assertEquals(copy, c);
918 +            assertEquals(c, copy);
919 +            assertEquals(copy.hashCode(), c.hashCode());
920 +        }
921 +        if (c instanceof Set) {
922 +            Set copy = new HashSet(c);
923 +            assertEquals(copy, c);
924 +            assertEquals(c, copy);
925 +            assertEquals(copy.hashCode(), c.hashCode());
926 +        }
927 +    }
928 +
929   //     public void testCollection8DebugFail() {
930   //         fail(impl.klazz().getSimpleName());
931   //     }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines