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
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final Function
<TestRuleAnnotatedMember, AbstractTestRuleAdapter> private static final Consumer
<List<TestRuleAnnotatedMember>> 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 long
invokeAppropriateMethodOnRuleAnnotatedMembers
(ExtensionContext context, Consumer<List<TestRuleAnnotatedMember>> ordering, Consumer<GenericBeforeAndAfterAdvice> methodCaller)
-
Field Details
-
NO_OP
-
ruleType
-
adapterGenerator
-
-
Constructor Details
-
TestRuleSupport
TestRuleSupport(Function<TestRuleAnnotatedMember, AbstractTestRuleAdapter> adapterGenerator, Class<? extends org.junit.rules.TestRule> ruleType)
-
-
Method Details
-
findRuleAnnotatedMembers
- See Also:
-
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 long invokeAppropriateMethodOnRuleAnnotatedMembers(ExtensionContext context, Consumer<List<TestRuleAnnotatedMember>> ordering, Consumer<GenericBeforeAndAfterAdvice> methodCaller) - Returns:
- the number of appropriate rule-annotated members that were discovered
-
getRuleAnnotatedMembers
-