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 TypeMethodDescriptionvoidafterEach(ExtensionContext context) Callback that is invoked after an individual test and any user-defined teardown methods for that test have been executed.voidbeforeEach(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) voidhandleTestExecutionException(ExtensionContext context, Throwable throwable) Handle the suppliedthrowable.private longinvokeAppropriateMethodOnRuleAnnotatedMembers(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:BeforeEachCallbackCallback that is invoked before an individual test and any user-defined setup methods for that test have been executed.- Specified by:
beforeEachin interfaceBeforeEachCallback- Parameters:
context- the current extension context; nevernull
-
handleTestExecutionException
public void handleTestExecutionException(ExtensionContext context, Throwable throwable) throws 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:
Throwable
- Swallow the supplied
-
afterEach
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
-
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
-