@API(status=EXPERIMENTAL,
since="5.0")
public class ExpectedExceptionSupport
extends java.lang.Object
implements AfterEachCallback, TestExecutionExceptionHandler
Extension provides native support for the
ExpectedException rule from JUnit 4.
By using this class-level extension on a test class,
ExpectedException can continue to be used.
However, you should rather switch to
Assertions.assertThrows(java.lang.Class<T>, org.junit.jupiter.api.function.Executable) for new code.
Assertions.assertThrows(java.lang.Class<T>, org.junit.jupiter.api.function.Executable),
ExpectedException,
TestRule,
Rule| Modifier and Type | Field and Description |
|---|---|
private static java.lang.String |
EXCEPTION_WAS_HANDLED |
private TestRuleSupport |
support |
| Constructor and Description |
|---|
ExpectedExceptionSupport() |
| Modifier and Type | Method and Description |
|---|---|
void |
afterEach(ExtensionContext context)
Callback that is invoked after each test has been invoked.
|
private ExtensionContext.Store |
getStore(ExtensionContext context) |
void |
handleTestExecutionException(ExtensionContext context,
java.lang.Throwable throwable)
Handle the supplied
throwable. |
private static final java.lang.String EXCEPTION_WAS_HANDLED
private final TestRuleSupport support
public void handleTestExecutionException(ExtensionContext context, java.lang.Throwable throwable) throws java.lang.Throwable
TestExecutionExceptionHandlerthrowable.
Implementors must perform one of the following.
throwable, thereby preventing propagation.throwable as is.throwable.If the supplied throwable is swallowed, subsequent
TestExecutionExceptionHandlers will not be invoked; otherwise,
the next registered TestExecutionExceptionHandler (if there is
one) will be invoked with any Throwable thrown by this handler.
Note that the execution
exception in the supplied ExtensionContext will not
contain the Throwable thrown during invocation of the corresponding
@Test method.
handleTestExecutionException in interface TestExecutionExceptionHandlercontext - the current extension context; never nullthrowable - the Throwable to handle; never nulljava.lang.Throwablepublic void afterEach(ExtensionContext context) throws java.lang.Exception
AfterEachCallbackafterEach in interface AfterEachCallbackcontext - the current extension context; never nulljava.lang.Exceptionprivate ExtensionContext.Store getStore(ExtensionContext context)