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.52 by jsr166, Sat May 5 18:29:53 2018 UTC vs.
Revision 1.58 by jsr166, Fri Feb 22 19:27:47 2019 UTC

# Line 182 | Line 182 | public class Collection8Test extends JSR
182              () -> c.iterator().forEachRemaining(null),
183              () -> c.spliterator().forEachRemaining(null),
184              () -> c.spliterator().tryAdvance(null),
185 <            () -> c.toArray(null));
185 >            () -> c.toArray((Object[])null));
186  
187          if (!impl.permitsNulls()) {
188              assertThrows(
# Line 210 | Line 210 | public class Collection8Test extends JSR
210              BlockingQueue q = (BlockingQueue) c;
211              assertThrows(
212                  NullPointerException.class,
213 <                () -> {
214 <                    try { q.offer(null, 1L, HOURS); }
215 <                    catch (InterruptedException ex) {
216 <                        throw new AssertionError(ex);
217 <                    }},
218 <                () -> {
219 <                    try { q.put(null); }
220 <                    catch (InterruptedException ex) {
221 <                        throw new AssertionError(ex);
222 <                    }});
213 >                () -> q.offer(null, 1L, HOURS),
214 >                () -> q.put(null));
215          }
216          if (c instanceof BlockingDeque) {
217              BlockingDeque q = (BlockingDeque) c;
218              assertThrows(
219                  NullPointerException.class,
220 <                () -> {
221 <                    try { q.offerFirst(null, 1L, HOURS); }
222 <                    catch (InterruptedException ex) {
223 <                        throw new AssertionError(ex);
232 <                    }},
233 <                () -> {
234 <                    try { q.offerLast(null, 1L, HOURS); }
235 <                    catch (InterruptedException ex) {
236 <                        throw new AssertionError(ex);
237 <                    }},
238 <                () -> {
239 <                    try { q.putFirst(null); }
240 <                    catch (InterruptedException ex) {
241 <                        throw new AssertionError(ex);
242 <                    }},
243 <                () -> {
244 <                    try { q.putLast(null); }
245 <                    catch (InterruptedException ex) {
246 <                        throw new AssertionError(ex);
247 <                    }});
220 >                () -> q.offerFirst(null, 1L, HOURS),
221 >                () -> q.offerLast(null, 1L, HOURS),
222 >                () -> q.putFirst(null),
223 >                () -> q.putLast(null));
224          }
225      }
226  
# Line 589 | Line 565 | public class Collection8Test extends JSR
565      public void testRemoveAfterForEachRemaining() {
566          Collection c = impl.emptyCollection();
567          ThreadLocalRandom rnd = ThreadLocalRandom.current();
568 +        ArrayList copy = new ArrayList();
569 +        boolean ordered = c.spliterator().hasCharacteristics(Spliterator.ORDERED);
570          testCollection: {
571              int n = 3 + rnd.nextInt(2);
572 <            for (int i = 0; i < n; i++) c.add(impl.makeElement(i));
572 >            for (int i = 0; i < n; i++) {
573 >                Object x = impl.makeElement(i);
574 >                c.add(x);
575 >                copy.add(x);
576 >            }
577              Iterator it = c.iterator();
578 <            assertTrue(it.hasNext());
579 <            assertEquals(impl.makeElement(0), it.next());
580 <            assertTrue(it.hasNext());
581 <            assertEquals(impl.makeElement(1), it.next());
582 <            it.forEachRemaining(e -> assertTrue(c.contains(e)));
578 >            if (ordered) {
579 >                if (rnd.nextBoolean()) assertTrue(it.hasNext());
580 >                assertEquals(impl.makeElement(0), it.next());
581 >                if (rnd.nextBoolean()) assertTrue(it.hasNext());
582 >                assertEquals(impl.makeElement(1), it.next());
583 >            } else {
584 >                if (rnd.nextBoolean()) assertTrue(it.hasNext());
585 >                assertTrue(copy.contains(it.next()));
586 >                if (rnd.nextBoolean()) assertTrue(it.hasNext());
587 >                assertTrue(copy.contains(it.next()));
588 >            }
589 >            if (rnd.nextBoolean()) assertTrue(it.hasNext());
590 >            it.forEachRemaining(
591 >                e -> {
592 >                    assertTrue(c.contains(e));
593 >                    assertTrue(copy.contains(e));});
594              if (testImplementationDetails) {
595                  if (c instanceof java.util.concurrent.ArrayBlockingQueue) {
596                      assertIteratorExhausted(it);
# Line 607 | Line 600 | public class Collection8Test extends JSR
600                          break testCollection;
601                      }
602                      assertEquals(n - 1, c.size());
603 <                    for (int i = 0; i < n - 1; i++)
604 <                        assertTrue(c.contains(impl.makeElement(i)));
605 <                    assertFalse(c.contains(impl.makeElement(n - 1)));
603 >                    if (ordered) {
604 >                        for (int i = 0; i < n - 1; i++)
605 >                            assertTrue(c.contains(impl.makeElement(i)));
606 >                        assertFalse(c.contains(impl.makeElement(n - 1)));
607 >                    }
608                  }
609              }
610          }
611          if (c instanceof Deque) {
612              Deque d = (Deque) impl.emptyCollection();
613 +            assertTrue(ordered);
614              int n = 3 + rnd.nextInt(2);
615              for (int i = 0; i < n; i++) d.add(impl.makeElement(i));
616              Iterator it = d.descendingIterator();

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines