Class TestRuleSupport
- java.lang.Object
-
- org.junit.jupiter.migrationsupport.rules.TestRuleSupport
-
- All Implemented Interfaces:
AfterEachCallback,BeforeEachCallback,Extension,TestExecutionExceptionHandler
class TestRuleSupport extends java.lang.Object implements BeforeEachCallback, TestExecutionExceptionHandler, AfterEachCallback
- Since:
- 5.0
-
-
Field Summary
Fields Modifier and Type Field Description private java.util.function.Function<TestRuleAnnotatedMember,AbstractTestRuleAdapter>adapterGeneratorprivate static java.util.function.Consumer<java.util.List<TestRuleAnnotatedMember>>NO_OPprivate java.lang.Class<? extends org.junit.rules.TestRule>ruleType
-
Constructor Summary
Constructors Constructor Description TestRuleSupport(java.util.function.Function<TestRuleAnnotatedMember,AbstractTestRuleAdapter> adapterGenerator, java.lang.Class<? extends org.junit.rules.TestRule> ruleType)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidafterEach(ExtensionContext context)Callback that is invoked after each test has been invoked.voidbeforeEach(ExtensionContext context)Callback that is invoked before each test is invoked.private java.util.List<java.lang.reflect.Field>findAnnotatedFields(java.lang.Object testInstance)private java.util.List<java.lang.reflect.Method>findAnnotatedMethods(java.lang.Object testInstance)private java.util.List<TestRuleAnnotatedMember>findRuleAnnotatedMembers(java.lang.Object testInstance)private java.util.List<TestRuleAnnotatedMember>getRuleAnnotatedMembers(ExtensionContext context)voidhandleTestExecutionException(ExtensionContext context, java.lang.Throwable throwable)Handle the suppliedthrowable.private longinvokeAppropriateMethodOnRuleAnnotatedMembers(ExtensionContext context, java.util.function.Consumer<java.util.List<TestRuleAnnotatedMember>> ordering, java.util.function.Consumer<GenericBeforeAndAfterAdvice> methodCaller)
-
-
-
Field Detail
-
NO_OP
private static final java.util.function.Consumer<java.util.List<TestRuleAnnotatedMember>> NO_OP
-
ruleType
private final java.lang.Class<? extends org.junit.rules.TestRule> ruleType
-
adapterGenerator
private final java.util.function.Function<TestRuleAnnotatedMember,AbstractTestRuleAdapter> adapterGenerator
-
-
Constructor Detail
-
TestRuleSupport
TestRuleSupport(java.util.function.Function<TestRuleAnnotatedMember,AbstractTestRuleAdapter> adapterGenerator, java.lang.Class<? extends org.junit.rules.TestRule> ruleType)
-
-
Method Detail
-
findRuleAnnotatedMembers
private java.util.List<TestRuleAnnotatedMember> findRuleAnnotatedMembers(java.lang.Object testInstance)
- See Also:
BlockJUnit4ClassRunner.withRules(org.junit.runners.model.FrameworkMethod, java.lang.Object, org.junit.runners.model.Statement),RunRules
-
findAnnotatedMethods
private java.util.List<java.lang.reflect.Method> findAnnotatedMethods(java.lang.Object testInstance)
-
findAnnotatedFields
private java.util.List<java.lang.reflect.Field> findAnnotatedFields(java.lang.Object testInstance)
-
beforeEach
public void beforeEach(ExtensionContext context)
Description copied from interface:BeforeEachCallbackCallback that is invoked before each test is invoked.- Specified by:
beforeEachin interfaceBeforeEachCallback- Parameters:
context- the current extension context; nevernull
-
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)
Description copied from interface:AfterEachCallbackCallback that is invoked after each test has been invoked.- Specified by:
afterEachin interfaceAfterEachCallback- Parameters:
context- the current extension context; nevernull
-
invokeAppropriateMethodOnRuleAnnotatedMembers
private long invokeAppropriateMethodOnRuleAnnotatedMembers(ExtensionContext context, java.util.function.Consumer<java.util.List<TestRuleAnnotatedMember>> ordering, java.util.function.Consumer<GenericBeforeAndAfterAdvice> methodCaller)
- Returns:
- the number of appropriate rule-annotated members that were discovered
-
getRuleAnnotatedMembers
private java.util.List<TestRuleAnnotatedMember> getRuleAnnotatedMembers(ExtensionContext context)
-
-