mirror of
https://github.com/google/nomulus.git
synced 2025-05-16 01:17:14 +02:00
Merge JUnitBackport's expectThrows into assertThrows
More information: https://github.com/junit-team/junit5/issues/531 ------------- Created by MOE: https://github.com/google/moe MOE_MIGRATED_REVID=187034408
This commit is contained in:
parent
f96a0b7da9
commit
606b470cd0
180 changed files with 1325 additions and 1381 deletions
|
@ -10,8 +10,8 @@ public class JUnitBackports {
|
|||
// TODO(b/68257761): Delete these and switch over to JUnit 4.13 methods upon release.
|
||||
|
||||
/**
|
||||
* 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 without
|
||||
* 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 without
|
||||
* wrapping. It is not meant to be implemented directly.
|
||||
*
|
||||
* @since 4.13
|
||||
|
@ -20,21 +20,6 @@ public class JUnitBackports {
|
|||
void run() throws Throwable;
|
||||
}
|
||||
|
||||
/**
|
||||
* 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
|
||||
* executed. If it does, the exception object is returned. If it does not throw an exception, an
|
||||
|
@ -47,7 +32,7 @@ public class JUnitBackports {
|
|||
* @return the exception thrown by {@code runnable}
|
||||
* @since 4.13
|
||||
*/
|
||||
public static <T extends Throwable> T expectThrows(
|
||||
public static <T extends Throwable> T assertThrows(
|
||||
Class<T> expectedThrowable, ThrowingRunnable runnable) {
|
||||
try {
|
||||
runnable.run();
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue