Class TestRuleSupport
java.lang.Object
org.junit.jupiter.migrationsupport.rules.TestRuleSupport
- All Implemented Interfaces:
AfterEachCallback
,BeforeEachCallback
,Extension
,TestExecutionExceptionHandler
class TestRuleSupport
extends Object
implements BeforeEachCallback, TestExecutionExceptionHandler, AfterEachCallback
- Since:
- 5.0
-
Nested Class Summary
Nested Classes -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final Function<TestRuleAnnotatedMember,
AbstractTestRuleAdapter> private final Class<? extends org.junit.rules.TestRule>
-
Constructor Summary
ConstructorsConstructorDescriptionTestRuleSupport
(Function<TestRuleAnnotatedMember, AbstractTestRuleAdapter> adapterGenerator, Class<? extends org.junit.rules.TestRule> ruleType) -
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
beforeEach
(ExtensionContext context) Callback that is invoked before an individual test and any user-defined setup methods for that test have been executed.findAnnotatedFields
(Object testInstance) findAnnotatedMethods
(Object testInstance) private List<TestRuleAnnotatedMember>
findRuleAnnotatedMembers
(Object testInstance) private List<TestRuleAnnotatedMember>
getRuleAnnotatedMembers
(ExtensionContext context) void
handleTestExecutionException
(ExtensionContext context, Throwable throwable) Handle the suppliedthrowable
.private int
invokeAppropriateMethodOnRuleAnnotatedMembers
(ExtensionContext context, boolean reverseOrder, TestRuleSupport.AdviceInvoker adviceInvoker)
-
Field Details
-
ruleType
-
adapterGenerator
-
-
Constructor Details
-
TestRuleSupport
TestRuleSupport(Function<TestRuleAnnotatedMember, AbstractTestRuleAdapter> adapterGenerator, Class<? extends org.junit.rules.TestRule> ruleType)
-
-
Method Details
-
findRuleAnnotatedMembers
- See Also:
-
BlockJUnit4ClassRunner.withRules(org.junit.runners.model.FrameworkMethod, java.lang.Object, org.junit.runners.model.Statement)
RunRules
-
findAnnotatedMethods
-
findAnnotatedFields
-
beforeEach
Description copied from interface:BeforeEachCallback
Callback that is invoked before an individual test and any user-defined setup methods for that test have been executed.- Specified by:
beforeEach
in interfaceBeforeEachCallback
- Parameters:
context
- the current extension context; nevernull
-
handleTestExecutionException
public void handleTestExecutionException(ExtensionContext context, Throwable throwable) throws Throwable Description 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
-
invokeAppropriateMethodOnRuleAnnotatedMembers
private int invokeAppropriateMethodOnRuleAnnotatedMembers(ExtensionContext context, boolean reverseOrder, TestRuleSupport.AdviceInvoker adviceInvoker) - Returns:
- the number of appropriate rule-annotated members that were discovered
-
getRuleAnnotatedMembers
- Returns:
- a modifiable copy of the list of rule-annotated members
-