Class ExpectedExceptionSupport
java.lang.Object
org.junit.jupiter.migrationsupport.rules.ExpectedExceptionSupport
- All Implemented Interfaces:
AfterEachCallback
,Extension
,TestExecutionExceptionHandler
@API(status=STABLE,
since="5.7")
public class ExpectedExceptionSupport
extends Object
implements AfterEachCallback, TestExecutionExceptionHandler
This
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.
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionvoid
afterEach(ExtensionContext context)
Callback that is invoked after an individual test and any user-defined teardown methods for that test have been executed.void
handleTestExecutionException(ExtensionContext context, Throwable throwable)
Handle the suppliedthrowable
.
-
Constructor Details
-
ExpectedExceptionSupport
public ExpectedExceptionSupport()
-
-
Method Details
-
handleTestExecutionException
public void handleTestExecutionException(ExtensionContext context, Throwable throwable) throws ThrowableDescription copied from interface:TestExecutionExceptionHandler
Handle the suppliedthrowable
.Implementors must perform one of the following.
- Swallow the supplied
throwable
, thereby preventing propagation. - Rethrow the supplied
throwable
as is. - Throw a new exception, potentially wrapping the supplied
throwable
.
If the supplied
throwable
is swallowed, subsequentTestExecutionExceptionHandlers
will not be invoked; otherwise, the next registeredTestExecutionExceptionHandler
(if there is one) will be invoked with anyThrowable
thrown by this handler.Note that the
execution exception
in the suppliedExtensionContext
will not contain theThrowable
thrown during invocation of the corresponding@Test
method.- Specified by:
handleTestExecutionException
in interfaceTestExecutionExceptionHandler
- Parameters:
context
- the current extension context; nevernull
throwable
- theThrowable
to handle; nevernull
- Throws:
Throwable
- Swallow the supplied
-
afterEach
Description copied from interface:AfterEachCallback
Callback that is invoked after an individual test and any user-defined teardown methods for that test have been executed.- Specified by:
afterEach
in interfaceAfterEachCallback
- Parameters:
context
- the current extension context; nevernull
- Throws:
Exception
-