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.44 by jsr166, Sun Dec 18 20:47:28 2016 UTC vs.
Revision 1.49 by jsr166, Mon Mar 26 21:06:51 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 140 | Line 159 | public class Collection8Test extends JSR
159          }
160          if (c instanceof BlockingQueue) {
161              BlockingQueue q = (BlockingQueue) c;
162 <            assertNull(q.poll(0L, MILLISECONDS));
162 >            assertNull(q.poll(randomExpiredTimeout(), randomTimeUnit()));
163          }
164          if (c instanceof BlockingDeque) {
165              BlockingDeque q = (BlockingDeque) c;
166 <            assertNull(q.pollFirst(0L, MILLISECONDS));
167 <            assertNull(q.pollLast(0L, MILLISECONDS));
166 >            assertNull(q.pollFirst(randomExpiredTimeout(), randomTimeUnit()));
167 >            assertNull(q.pollLast(randomExpiredTimeout(), randomTimeUnit()));
168          }
169      }
170  
# 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 727 | Line 756 | public class Collection8Test extends JSR
756      }
757  
758      /**
759 +     * Concurrent Spliterators, once exhausted, stay exhausted.
760 +     */
761 +    public void testStickySpliteratorExhaustion() throws Throwable {
762 +        if (!impl.isConcurrent()) return;
763 +        if (!testImplementationDetails) return;
764 +        final ThreadLocalRandom rnd = ThreadLocalRandom.current();
765 +        final Consumer alwaysThrows = e -> { throw new AssertionError(); };
766 +        final Collection c = impl.emptyCollection();
767 +        final Spliterator s = c.spliterator();
768 +        if (rnd.nextBoolean()) {
769 +            assertFalse(s.tryAdvance(alwaysThrows));
770 +        } else {
771 +            s.forEachRemaining(alwaysThrows);
772 +        }
773 +        final Object one = impl.makeElement(1);
774 +        // Spliterator should not notice added element
775 +        c.add(one);
776 +        if (rnd.nextBoolean()) {
777 +            assertFalse(s.tryAdvance(alwaysThrows));
778 +        } else {
779 +            s.forEachRemaining(alwaysThrows);
780 +        }
781 +    }
782 +
783 +    /**
784       * Motley crew of threads concurrently randomly hammer the collection.
785       */
786      public void testDetectRaces() throws Throwable {

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines