diff --git a/src/main/java/org/junit/Assert.java b/src/main/java/org/junit/Assert.java index bb2c4bc93661..8d11ece9b11a 100755 --- a/src/main/java/org/junit/Assert.java +++ b/src/main/java/org/junit/Assert.java @@ -967,7 +967,7 @@ public static void assertThat(String reason, T actual, } /** - * Asserts that {@code runnable} throws an exception of type {@code expectedThrowable} when + * Checks that {@code runnable} throws an exception of type {@code expectedThrowable} when * executed. If it does, the exception object is returned. If it does not throw an exception, an * {@link AssertionError} is thrown. If it throws the wrong type of exception, an {@code * AssertionError} is thrown describing the mismatch; the exception that was actually thrown can @@ -978,7 +978,7 @@ public static void assertThat(String reason, T actual, * @return the exception thrown by {@code runnable} * @since 4.13 */ - public static T assertThrows(Class expectedThrowable, ThrowingRunnable runnable) { + public static T expectThrows(Class expectedThrowable, ThrowingRunnable runnable) { try { runnable.run(); } catch (Throwable actualThrown) { diff --git a/src/main/java/org/junit/function/ThrowingRunnable.java b/src/main/java/org/junit/function/ThrowingRunnable.java index e8b095a5308b..2a1625d89e88 100644 --- a/src/main/java/org/junit/function/ThrowingRunnable.java +++ b/src/main/java/org/junit/function/ThrowingRunnable.java @@ -1,8 +1,8 @@ package org.junit.function; /** - * This interface facilitates the use of assertThrows from Java 8. It allows method references - * to void methods (that declare checked exceptions) to be passed directly into assertThrows + * This interface facilitates the use of {@code expectThrows} from Java 8. It allows method references + * to void methods (that declare checked exceptions) to be passed directly into {@code expectThrows}. * without wrapping. It is not meant to be implemented directly. * * @since 4.13 diff --git a/src/main/java/org/junit/rules/ErrorCollector.java b/src/main/java/org/junit/rules/ErrorCollector.java index 80a7c12712ef..2228de081dde 100644 --- a/src/main/java/org/junit/rules/ErrorCollector.java +++ b/src/main/java/org/junit/rules/ErrorCollector.java @@ -1,7 +1,7 @@ package org.junit.rules; import static org.junit.Assert.assertThat; -import static org.junit.Assert.assertThrows; +import static org.junit.Assert.expectThrows; import java.util.ArrayList; import java.util.List; @@ -117,7 +117,7 @@ public T checkSucceeds(Callable callable) { */ public void checkThrows(Class expectedThrowable, ThrowingRunnable runnable) { try { - assertThrows(expectedThrowable, runnable); + expectThrows(expectedThrowable, runnable); } catch (AssertionError e) { addError(e); } diff --git a/src/main/java/org/junit/rules/ExpectedException.java b/src/main/java/org/junit/rules/ExpectedException.java index 4457dab264fc..b20cbe097435 100644 --- a/src/main/java/org/junit/rules/ExpectedException.java +++ b/src/main/java/org/junit/rules/ExpectedException.java @@ -15,8 +15,8 @@ /** * The {@code ExpectedException} rule allows you to verify that your code * throws a specific exception. Note that, starting with Java 8, - * {@link org.junit.Assert#assertThrows(java.lang.Class, org.junit.function.ThrowingRunnable) - * Assert.assertThrows} + * {@link org.junit.Assert#expectThrows(java.lang.Class, org.junit.function.ThrowingRunnable) + * Assert.expectThrows} * is often a better choice since it allows you to express exactly where you * expect the exception to be thrown. * diff --git a/src/test/java/org/junit/tests/assertion/AssertionTest.java b/src/test/java/org/junit/tests/assertion/AssertionTest.java index ced5e00df8df..0c5746a6e817 100755 --- a/src/test/java/org/junit/tests/assertion/AssertionTest.java +++ b/src/test/java/org/junit/tests/assertion/AssertionTest.java @@ -10,8 +10,8 @@ import static org.junit.Assert.assertNull; import static org.junit.Assert.assertSame; import static org.junit.Assert.assertThat; -import static org.junit.Assert.assertThrows; import static org.junit.Assert.assertTrue; +import static org.junit.Assert.expectThrows; import static org.junit.Assert.fail; import java.io.IOException; @@ -797,14 +797,14 @@ public void assertNotEqualsIgnoresFloatDeltaOnNaN() { } @Test(expected = AssertionError.class) - public void assertThrowsRequiresAnExceptionToBeThrown() { - assertThrows(Throwable.class, nonThrowingRunnable()); + public void expectThrowsRequiresAnExceptionToBeThrown() { + expectThrows(Throwable.class, nonThrowingRunnable()); } @Test - public void assertThrowsIncludesAnInformativeDefaultMessage() { + public void expectThrowsIncludesAnInformativeDefaultMessage() { try { - assertThrows(Throwable.class, nonThrowingRunnable()); + expectThrows(Throwable.class, nonThrowingRunnable()); } catch (AssertionError ex) { assertEquals("expected java.lang.Throwable to be thrown, but nothing was thrown", ex.getMessage()); return; @@ -813,27 +813,27 @@ public void assertThrowsIncludesAnInformativeDefaultMessage() { } @Test - public void assertThrowsReturnsTheSameObjectThrown() { + public void expectThrowsReturnsTheSameObjectThrown() { NullPointerException npe = new NullPointerException(); - Throwable throwable = assertThrows(Throwable.class, throwingRunnable(npe)); + Throwable throwable = expectThrows(Throwable.class, throwingRunnable(npe)); assertSame(npe, throwable); } @Test(expected = AssertionError.class) - public void assertThrowsDetectsTypeMismatchesViaExplicitTypeHint() { + public void expectThrowsDetectsTypeMismatchesViaExplicitTypeHint() { NullPointerException npe = new NullPointerException(); - assertThrows(IOException.class, throwingRunnable(npe)); + expectThrows(IOException.class, throwingRunnable(npe)); } @Test - public void assertThrowsWrapsAndPropagatesUnexpectedExceptions() { + public void expectThrowsWrapsAndPropagatesUnexpectedExceptions() { NullPointerException npe = new NullPointerException("inner-message"); try { - assertThrows(IOException.class, throwingRunnable(npe)); + expectThrows(IOException.class, throwingRunnable(npe)); } catch (AssertionError ex) { assertSame(npe, ex.getCause()); assertEquals("inner-message", ex.getCause().getMessage()); @@ -843,11 +843,11 @@ public void assertThrowsWrapsAndPropagatesUnexpectedExceptions() { } @Test - public void assertThrowsSuppliesACoherentErrorMessageUponTypeMismatch() { + public void expectThrowsSuppliesACoherentErrorMessageUponTypeMismatch() { NullPointerException npe = new NullPointerException(); try { - assertThrows(IOException.class, throwingRunnable(npe)); + expectThrows(IOException.class, throwingRunnable(npe)); } catch (AssertionError error) { assertEquals("unexpected exception type thrown; expected: but was:", error.getMessage()); @@ -858,11 +858,11 @@ public void assertThrowsSuppliesACoherentErrorMessageUponTypeMismatch() { } @Test - public void assertThrowsUsesCanonicalNameUponTypeMismatch() { + public void expectThrowsUsesCanonicalNameUponTypeMismatch() { NullPointerException npe = new NullPointerException(); try { - assertThrows(NestedException.class, throwingRunnable(npe)); + expectThrows(NestedException.class, throwingRunnable(npe)); } catch (AssertionError error) { assertEquals( "unexpected exception type thrown; expected:" @@ -875,12 +875,12 @@ public void assertThrowsUsesCanonicalNameUponTypeMismatch() { } @Test - public void assertThrowsUsesNameUponTypeMismatchWithAnonymousClass() { + public void expectThrowsUsesNameUponTypeMismatchWithAnonymousClass() { NullPointerException npe = new NullPointerException() { }; try { - assertThrows(IOException.class, throwingRunnable(npe)); + expectThrows(IOException.class, throwingRunnable(npe)); } catch (AssertionError error) { assertEquals( "unexpected exception type thrown; expected:" @@ -893,9 +893,9 @@ public void assertThrowsUsesNameUponTypeMismatchWithAnonymousClass() { } @Test - public void assertThrowsUsesCanonicalNameWhenRequiredExceptionNotThrown() { + public void expectThrowsUsesCanonicalNameWhenRequiredExceptionNotThrown() { try { - assertThrows(NestedException.class, nonThrowingRunnable()); + expectThrows(NestedException.class, nonThrowingRunnable()); } catch (AssertionError error) { assertEquals( "expected org.junit.tests.assertion.AssertionTest.NestedException to be thrown,"