--- old/test/java/util/Spliterator/SpliteratorFailFastTest.java 2017-05-02 14:22:25.000000000 +0800 +++ new/test/java/util/Spliterator/SpliteratorFailFastTest.java 2017-05-02 14:22:22.000000000 +0800 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2013, 2016, Oracle and/or its affiliates. All rights reserved. + * 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 @@ -21,9 +21,6 @@ * questions. */ -import org.testng.annotations.DataProvider; -import org.testng.annotations.Test; - import java.util.ArrayList; import java.util.Arrays; import java.util.ConcurrentModificationException; @@ -42,8 +39,11 @@ import java.util.WeakHashMap; import java.util.function.Supplier; -import static org.testng.Assert.assertNotNull; -import static org.testng.Assert.assertTrue; +import org.testng.Assert.ThrowingRunnable; +import org.testng.annotations.DataProvider; +import org.testng.annotations.Test; + +import static org.testng.Assert.assertThrows; /** * @test @@ -125,7 +125,7 @@ }); source.update(); - executeAndCatch(() -> s.tryAdvance(e -> { + assertThrowsCME(() -> s.tryAdvance(e -> { })); } @@ -137,7 +137,7 @@ }); source.update(); - executeAndCatch(() -> s.forEachRemaining(e -> { + assertThrowsCME(() -> s.forEachRemaining(e -> { })); } } @@ -147,7 +147,7 @@ Source source = ss.get(); Spliterator s = source.spliterator(); - executeAndCatch(() -> s.forEachRemaining(e -> { + assertThrowsCME(() -> s.forEachRemaining(e -> { source.update(); })); } @@ -161,7 +161,7 @@ s.estimateSize(); source.update(); - executeAndCatch(() -> s.tryAdvance(e -> { + assertThrowsCME(() -> s.tryAdvance(e -> { })); } @@ -172,30 +172,13 @@ s.estimateSize(); source.update(); - executeAndCatch(() -> s.forEachRemaining(e -> { + assertThrowsCME(() -> s.forEachRemaining(e -> { })); } } - private void executeAndCatch(Runnable r) { - executeAndCatch(ConcurrentModificationException.class, r); - } - - private void executeAndCatch(Class 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())); + private void assertThrowsCME(ThrowingRunnable r) { + assertThrows(ConcurrentModificationException.class, r); } }