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 java.lang.Object implements AfterEachCallback, TestExecutionExceptionHandlerThisExtensionprovides native support for theExpectedExceptionrule from JUnit 4.By using this class-level extension on a test class,
ExpectedExceptioncan 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.- Since:
- 5.0
- See Also:
Assertions.assertThrows(java.lang.Class<T>, org.junit.jupiter.api.function.Executable),ExpectedException,TestRule,Rule
-
-
Field Summary
Fields Modifier and Type Field Description private static java.lang.StringEXCEPTION_WAS_HANDLEDprivate TestRuleSupportsupport
-
Constructor Summary
Constructors Constructor Description ExpectedExceptionSupport()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidafterEach(ExtensionContext context)Callback that is invoked after an individual test and any user-defined teardown methods for that test have been executed.private ExtensionContext.StoregetStore(ExtensionContext context)voidhandleTestExecutionException(ExtensionContext context, java.lang.Throwable throwable)Handle the suppliedthrowable.
-
-
-
Field Detail
-
EXCEPTION_WAS_HANDLED
private static final java.lang.String EXCEPTION_WAS_HANDLED
- See Also:
- Constant Field Values
-
support
private final TestRuleSupport support
-
-
Method Detail
-
handleTestExecutionException
public void handleTestExecutionException(ExtensionContext context, java.lang.Throwable throwable) throws java.lang.Throwable
Description copied from interface:TestExecutionExceptionHandlerHandle the suppliedthrowable.Implementors must perform one of the following.
- Swallow the supplied
throwable, thereby preventing propagation. - Rethrow the supplied
throwableas is. - Throw a new exception, potentially wrapping the supplied
throwable.
If the supplied
throwableis swallowed, subsequentTestExecutionExceptionHandlerswill not be invoked; otherwise, the next registeredTestExecutionExceptionHandler(if there is one) will be invoked with anyThrowablethrown by this handler.Note that the
execution exceptionin the suppliedExtensionContextwill not contain theThrowablethrown during invocation of the corresponding@Testmethod.- Specified by:
handleTestExecutionExceptionin interfaceTestExecutionExceptionHandler- Parameters:
context- the current extension context; nevernullthrowable- theThrowableto handle; nevernull- Throws:
java.lang.Throwable
- Swallow the supplied
-
afterEach
public void afterEach(ExtensionContext context) throws java.lang.Exception
Description copied from interface:AfterEachCallbackCallback that is invoked after an individual test and any user-defined teardown methods for that test have been executed.- Specified by:
afterEachin interfaceAfterEachCallback- Parameters:
context- the current extension context; nevernull- Throws:
java.lang.Exception
-
getStore
private ExtensionContext.Store getStore(ExtensionContext context)
-
-