Class MicronautJunit5Extension
java.lang.Object
io.micronaut.test.extensions.AbstractMicronautExtension<org.junit.jupiter.api.extension.ExtensionContext>
io.micronaut.test.extensions.junit5.MicronautJunit5Extension
- All Implemented Interfaces:
TestExecutionListener
,TestMethodInterceptor<Object>
,org.junit.jupiter.api.extension.AfterAllCallback
,org.junit.jupiter.api.extension.AfterEachCallback
,org.junit.jupiter.api.extension.AfterTestExecutionCallback
,org.junit.jupiter.api.extension.BeforeAllCallback
,org.junit.jupiter.api.extension.BeforeEachCallback
,org.junit.jupiter.api.extension.BeforeTestExecutionCallback
,org.junit.jupiter.api.extension.ExecutionCondition
,org.junit.jupiter.api.extension.Extension
,org.junit.jupiter.api.extension.InvocationInterceptor
,org.junit.jupiter.api.extension.ParameterResolver
public class MicronautJunit5Extension
extends AbstractMicronautExtension<org.junit.jupiter.api.extension.ExtensionContext>
implements org.junit.jupiter.api.extension.BeforeAllCallback, org.junit.jupiter.api.extension.AfterAllCallback, org.junit.jupiter.api.extension.BeforeEachCallback, org.junit.jupiter.api.extension.AfterEachCallback, org.junit.jupiter.api.extension.ExecutionCondition, org.junit.jupiter.api.extension.BeforeTestExecutionCallback, org.junit.jupiter.api.extension.AfterTestExecutionCallback, org.junit.jupiter.api.extension.ParameterResolver, org.junit.jupiter.api.extension.InvocationInterceptor
Extension for JUnit 5.
- Since:
- 1.0
- Author:
- graemerocher
-
Nested Class Summary
Nested classes/interfaces inherited from interface org.junit.jupiter.api.extension.InvocationInterceptor
org.junit.jupiter.api.extension.InvocationInterceptor.Invocation<T extends Object>
-
Field Summary
Fields inherited from class io.micronaut.test.extensions.AbstractMicronautExtension
applicationContext, DISABLED_MESSAGE, embeddedApplication, MISCONFIGURED_MESSAGE, oldValues, refreshScope, specDefinition, TEST_PROPERTY_SOURCE, TEST_ROLLBACK, TEST_TRANSACTION_MODE, TEST_TRANSACTIONAL, testAnnotationValue, testProperties
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionvoid
afterAll
(org.junit.jupiter.api.extension.ExtensionContext extensionContext) void
afterEach
(org.junit.jupiter.api.extension.ExtensionContext extensionContext) Executed after each test completes.void
afterTestExecution
(org.junit.jupiter.api.extension.ExtensionContext context) protected void
alignMocks
(org.junit.jupiter.api.extension.ExtensionContext context, Object instance) void
beforeAll
(org.junit.jupiter.api.extension.ExtensionContext extensionContext) void
beforeEach
(org.junit.jupiter.api.extension.ExtensionContext extensionContext) void
beforeTestExecution
(org.junit.jupiter.api.extension.ExtensionContext context) protected MicronautTestValue
buildMicronautTestValue
(Class<?> testClass) Builds aMicronautTestValue
object from the provided class (e.g.org.junit.jupiter.api.extension.ConditionEvaluationResult
evaluateExecutionCondition
(org.junit.jupiter.api.extension.ExtensionContext extensionContext) protected org.junit.jupiter.api.extension.ExtensionContext.Store
getStore
(org.junit.jupiter.api.extension.ExtensionContext context) protected boolean
hasExpectedAnnotations
(Class<?> testClass) void
interceptAfterEachMethod
(org.junit.jupiter.api.extension.InvocationInterceptor.Invocation<Void> invocation, org.junit.jupiter.api.extension.ReflectiveInvocationContext<Method> invocationContext, org.junit.jupiter.api.extension.ExtensionContext extensionContext) void
interceptBeforeEachMethod
(org.junit.jupiter.api.extension.InvocationInterceptor.Invocation<Void> invocation, org.junit.jupiter.api.extension.ReflectiveInvocationContext<Method> invocationContext, org.junit.jupiter.api.extension.ExtensionContext extensionContext) <T> T
interceptTestFactoryMethod
(org.junit.jupiter.api.extension.InvocationInterceptor.Invocation<T> invocation, org.junit.jupiter.api.extension.ReflectiveInvocationContext<Method> invocationContext, org.junit.jupiter.api.extension.ExtensionContext extensionContext) void
interceptTestMethod
(org.junit.jupiter.api.extension.InvocationInterceptor.Invocation<Void> invocation, org.junit.jupiter.api.extension.ReflectiveInvocationContext<Method> invocationContext, org.junit.jupiter.api.extension.ExtensionContext extensionContext) void
interceptTestTemplateMethod
(org.junit.jupiter.api.extension.InvocationInterceptor.Invocation<Void> invocation, org.junit.jupiter.api.extension.ReflectiveInvocationContext<Method> invocationContext, org.junit.jupiter.api.extension.ExtensionContext extensionContext) resolveParameter
(org.junit.jupiter.api.extension.ParameterContext parameterContext, org.junit.jupiter.api.extension.ExtensionContext extensionContext) protected void
resolveTestProperties
(org.junit.jupiter.api.extension.ExtensionContext context, MicronautTestValue testAnnotationValue, Map<String, Object> testProperties) Resolves any test properties.boolean
supportsParameter
(org.junit.jupiter.api.extension.ParameterContext parameterContext, org.junit.jupiter.api.extension.ExtensionContext extensionContext) Methods inherited from class io.micronaut.test.extensions.AbstractMicronautExtension
afterClass, afterCleanupTest, afterSetupTest, afterTestClass, afterTestExecution, afterTestMethod, beforeClass, beforeCleanupTest, beforeEach, beforeSetupTest, beforeTestClass, beforeTestExecution, beforeTestMethod, hasInterceptors, interceptAfterEach, interceptBeforeEach, interceptTest, isTestSuiteBeanPresent, postProcessBuilder, startApplicationContext
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface org.junit.jupiter.api.extension.InvocationInterceptor
interceptAfterAllMethod, interceptBeforeAllMethod, interceptDynamicTest, interceptDynamicTest, interceptTestClassConstructor
-
Constructor Details
-
MicronautJunit5Extension
public MicronautJunit5Extension()
-
-
Method Details
-
beforeAll
public void beforeAll(org.junit.jupiter.api.extension.ExtensionContext extensionContext) throws Exception - Specified by:
beforeAll
in interfaceorg.junit.jupiter.api.extension.BeforeAllCallback
- Throws:
Exception
-
buildMicronautTestValue
Builds aMicronautTestValue
object from the provided class (e.g. by scanning annotations).- Parameters:
testClass
- the class to extract builder configuration from- Returns:
- a MicronautTestValue to configure the test application context
-
interceptBeforeEachMethod
public void interceptBeforeEachMethod(org.junit.jupiter.api.extension.InvocationInterceptor.Invocation<Void> invocation, org.junit.jupiter.api.extension.ReflectiveInvocationContext<Method> invocationContext, org.junit.jupiter.api.extension.ExtensionContext extensionContext) throws Throwable - Specified by:
interceptBeforeEachMethod
in interfaceorg.junit.jupiter.api.extension.InvocationInterceptor
- Throws:
Throwable
-
interceptTestMethod
public void interceptTestMethod(org.junit.jupiter.api.extension.InvocationInterceptor.Invocation<Void> invocation, org.junit.jupiter.api.extension.ReflectiveInvocationContext<Method> invocationContext, org.junit.jupiter.api.extension.ExtensionContext extensionContext) throws Throwable - Specified by:
interceptTestMethod
in interfaceorg.junit.jupiter.api.extension.InvocationInterceptor
- Throws:
Throwable
-
interceptTestTemplateMethod
public void interceptTestTemplateMethod(org.junit.jupiter.api.extension.InvocationInterceptor.Invocation<Void> invocation, org.junit.jupiter.api.extension.ReflectiveInvocationContext<Method> invocationContext, org.junit.jupiter.api.extension.ExtensionContext extensionContext) throws Throwable - Specified by:
interceptTestTemplateMethod
in interfaceorg.junit.jupiter.api.extension.InvocationInterceptor
- Throws:
Throwable
-
interceptTestFactoryMethod
public <T> T interceptTestFactoryMethod(org.junit.jupiter.api.extension.InvocationInterceptor.Invocation<T> invocation, org.junit.jupiter.api.extension.ReflectiveInvocationContext<Method> invocationContext, org.junit.jupiter.api.extension.ExtensionContext extensionContext) throws Throwable - Specified by:
interceptTestFactoryMethod
in interfaceorg.junit.jupiter.api.extension.InvocationInterceptor
- Throws:
Throwable
-
interceptAfterEachMethod
public void interceptAfterEachMethod(org.junit.jupiter.api.extension.InvocationInterceptor.Invocation<Void> invocation, org.junit.jupiter.api.extension.ReflectiveInvocationContext<Method> invocationContext, org.junit.jupiter.api.extension.ExtensionContext extensionContext) throws Throwable - Specified by:
interceptAfterEachMethod
in interfaceorg.junit.jupiter.api.extension.InvocationInterceptor
- Throws:
Throwable
-
afterAll
public void afterAll(org.junit.jupiter.api.extension.ExtensionContext extensionContext) throws Exception - Specified by:
afterAll
in interfaceorg.junit.jupiter.api.extension.AfterAllCallback
- Throws:
Exception
-
beforeEach
public void beforeEach(org.junit.jupiter.api.extension.ExtensionContext extensionContext) throws Exception - Specified by:
beforeEach
in interfaceorg.junit.jupiter.api.extension.BeforeEachCallback
- Throws:
Exception
-
afterEach
public void afterEach(org.junit.jupiter.api.extension.ExtensionContext extensionContext) throws Exception Description copied from class:AbstractMicronautExtension
Executed after each test completes.- Specified by:
afterEach
in interfaceorg.junit.jupiter.api.extension.AfterEachCallback
- Overrides:
afterEach
in classAbstractMicronautExtension<org.junit.jupiter.api.extension.ExtensionContext>
- Parameters:
extensionContext
- The context- Throws:
Exception
- allows any exception to propagate
-
evaluateExecutionCondition
public org.junit.jupiter.api.extension.ConditionEvaluationResult evaluateExecutionCondition(org.junit.jupiter.api.extension.ExtensionContext extensionContext) - Specified by:
evaluateExecutionCondition
in interfaceorg.junit.jupiter.api.extension.ExecutionCondition
-
hasExpectedAnnotations
- Parameters:
testClass
- the test class- Returns:
- true if the provided test class holds the expected test annotations
-
resolveTestProperties
protected void resolveTestProperties(org.junit.jupiter.api.extension.ExtensionContext context, MicronautTestValue testAnnotationValue, Map<String, Object> testProperties) Description copied from class:AbstractMicronautExtension
Resolves any test properties.- Specified by:
resolveTestProperties
in classAbstractMicronautExtension<org.junit.jupiter.api.extension.ExtensionContext>
- Parameters:
context
- The test contexttestAnnotationValue
- The test annotationtestProperties
- The test properties
-
alignMocks
protected void alignMocks(org.junit.jupiter.api.extension.ExtensionContext context, Object instance) - Specified by:
alignMocks
in classAbstractMicronautExtension<org.junit.jupiter.api.extension.ExtensionContext>
- Parameters:
context
- The contextinstance
- The mock instance to inject
-
afterTestExecution
public void afterTestExecution(org.junit.jupiter.api.extension.ExtensionContext context) throws Exception - Specified by:
afterTestExecution
in interfaceorg.junit.jupiter.api.extension.AfterTestExecutionCallback
- Throws:
Exception
-
beforeTestExecution
public void beforeTestExecution(org.junit.jupiter.api.extension.ExtensionContext context) throws Exception - Specified by:
beforeTestExecution
in interfaceorg.junit.jupiter.api.extension.BeforeTestExecutionCallback
- Throws:
Exception
-
supportsParameter
public boolean supportsParameter(org.junit.jupiter.api.extension.ParameterContext parameterContext, org.junit.jupiter.api.extension.ExtensionContext extensionContext) throws org.junit.jupiter.api.extension.ParameterResolutionException - Specified by:
supportsParameter
in interfaceorg.junit.jupiter.api.extension.ParameterResolver
- Throws:
org.junit.jupiter.api.extension.ParameterResolutionException
-
resolveParameter
public Object resolveParameter(org.junit.jupiter.api.extension.ParameterContext parameterContext, org.junit.jupiter.api.extension.ExtensionContext extensionContext) throws org.junit.jupiter.api.extension.ParameterResolutionException - Specified by:
resolveParameter
in interfaceorg.junit.jupiter.api.extension.ParameterResolver
- Throws:
org.junit.jupiter.api.extension.ParameterResolutionException
-
getStore
protected org.junit.jupiter.api.extension.ExtensionContext.Store getStore(org.junit.jupiter.api.extension.ExtensionContext context) - Parameters:
context
- the current extension context- Returns:
- the store to use for this extension
-