< prev index next >

test/java/util/Spliterator/SpliteratorFailFastTest.java

Print this page

        

*** 1,7 **** /* ! * Copyright (c) 2013, 2016, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License version 2 only, as * published by the Free Software Foundation. --- 1,7 ---- /* ! * Copyright (c) 2013, 2017, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License version 2 only, as * published by the Free Software Foundation.
*** 19,31 **** * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA * or visit www.oracle.com if you need additional information or have any * questions. */ - import org.testng.annotations.DataProvider; - import org.testng.annotations.Test; - import java.util.ArrayList; import java.util.Arrays; import java.util.ConcurrentModificationException; import java.util.HashMap; import java.util.HashSet; --- 19,28 ----
*** 40,51 **** import java.util.TreeSet; import java.util.Vector; import java.util.WeakHashMap; import java.util.function.Supplier; ! import static org.testng.Assert.assertNotNull; ! import static org.testng.Assert.assertTrue; /** * @test * @bug 8148748 * @summary Spliterator fail-fast tests --- 37,51 ---- import java.util.TreeSet; import java.util.Vector; import java.util.WeakHashMap; import java.util.function.Supplier; ! import org.testng.Assert.ThrowingRunnable; ! import org.testng.annotations.DataProvider; ! import org.testng.annotations.Test; ! ! import static org.testng.Assert.assertThrows; /** * @test * @bug 8148748 * @summary Spliterator fail-fast tests
*** 123,133 **** s.tryAdvance(e -> { }); source.update(); ! executeAndCatch(() -> s.tryAdvance(e -> { })); } { Source<T> source = ss.get(); --- 123,133 ---- s.tryAdvance(e -> { }); source.update(); ! assertThrowsCME(() -> s.tryAdvance(e -> { })); } { Source<T> source = ss.get();
*** 135,155 **** s.tryAdvance(e -> { }); source.update(); ! executeAndCatch(() -> s.forEachRemaining(e -> { })); } } @Test(dataProvider = "Source") public <T> void testForEach(String description, Supplier<Source<T>> ss) { Source<T> source = ss.get(); Spliterator<T> s = source.spliterator(); ! executeAndCatch(() -> s.forEachRemaining(e -> { source.update(); })); } @Test(dataProvider = "Source") --- 135,155 ---- s.tryAdvance(e -> { }); source.update(); ! assertThrowsCME(() -> s.forEachRemaining(e -> { })); } } @Test(dataProvider = "Source") public <T> void testForEach(String description, Supplier<Source<T>> ss) { Source<T> source = ss.get(); Spliterator<T> s = source.spliterator(); ! assertThrowsCME(() -> s.forEachRemaining(e -> { source.update(); })); } @Test(dataProvider = "Source")
*** 159,201 **** Spliterator<T> s = source.spliterator(); s.estimateSize(); source.update(); ! executeAndCatch(() -> s.tryAdvance(e -> { })); } { Source<T> source = ss.get(); Spliterator<T> s = source.spliterator(); s.estimateSize(); source.update(); ! executeAndCatch(() -> s.forEachRemaining(e -> { })); } } ! private void executeAndCatch(Runnable r) { ! executeAndCatch(ConcurrentModificationException.class, r); ! } ! ! private void executeAndCatch(Class<? extends Exception> expected, Runnable r) { ! Exception caught = null; ! try { ! r.run(); ! } ! catch (Exception e) { ! caught = e; ! } ! ! assertNotNull(caught, ! String.format("No Exception was thrown, expected an Exception of %s to be thrown", ! expected.getName())); ! assertTrue(expected.isInstance(caught), ! String.format("Exception thrown %s not an instance of %s", ! caught.getClass().getName(), expected.getName())); } } --- 159,184 ---- Spliterator<T> s = source.spliterator(); s.estimateSize(); source.update(); ! assertThrowsCME(() -> s.tryAdvance(e -> { })); } { Source<T> source = ss.get(); Spliterator<T> s = source.spliterator(); s.estimateSize(); source.update(); ! assertThrowsCME(() -> s.forEachRemaining(e -> { })); } } ! private void assertThrowsCME(ThrowingRunnable r) { ! assertThrows(ConcurrentModificationException.class, r); } }
< prev index next >