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>
adapterGenerator
private static java.util.function.Consumer<java.util.List<TestRuleAnnotatedMember>>
NO_OP
private 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 void
afterEach(ExtensionContext context)
Callback that is invoked after each test has been invoked.void
beforeEach(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)
void
handleTestExecutionException(ExtensionContext context, java.lang.Throwable throwable)
Handle the suppliedthrowable
.private long
invokeAppropriateMethodOnRuleAnnotatedMembers(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:BeforeEachCallback
Callback that is invoked before each test is invoked.- Specified by:
beforeEach
in 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: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:
java.lang.Throwable
- Swallow the supplied
-
afterEach
public void afterEach(ExtensionContext context)
Description copied from interface:AfterEachCallback
Callback that is invoked after each test has been invoked.- Specified by:
afterEach
in 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)
-
-