Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Delete assertThrows() #1396

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 1 addition & 16 deletions src/main/java/org/junit/Assert.java
Original file line number Diff line number Diff line change
Expand Up @@ -967,22 +967,7 @@ public static <T> void assertThat(String reason, T actual,
}

/**
* Asserts that {@code runnable} throws an exception of type {@code expectedThrowable} when
* executed. 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 be obtained by calling {@link
* AssertionError#getCause}.
*
* @param expectedThrowable the expected type of the exception
* @param runnable a function that is expected to throw an exception when executed
* @since 4.13
*/
public static void assertThrows(Class<? extends Throwable> expectedThrowable, ThrowingRunnable runnable) {
expectThrows(expectedThrowable, runnable);
}

/**
* 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
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/org/junit/function/ThrowingRunnable.java
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package org.junit.function;

/**
* This interface facilitates the use of expectThrows from Java 8. It allows method references
* to void methods (that declare checked exceptions) to be passed directly into expectThrows
* 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
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/org/junit/rules/ErrorCollector.java
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -117,7 +117,7 @@ public <T> T checkSucceeds(Callable<T> callable) {
*/
public void checkThrows(Class<? extends Throwable> expectedThrowable, ThrowingRunnable runnable) {
try {
assertThrows(expectedThrowable, runnable);
expectThrows(expectedThrowable, runnable);
} catch (AssertionError e) {
addError(e);
}
Expand Down
9 changes: 3 additions & 6 deletions src/main/java/org/junit/rules/ExpectedException.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,10 @@
/**
* 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. Use
* {@link org.junit.Assert#expectThrows(java.lang.Class,
* org.junit.function.ThrowingRunnable) expectThrows}
* if you need to assert something about the thrown exception.
* expect the exception to be thrown.
*
* <h3>Usage</h3>
*
Expand Down