Package io.micronaut.test.extensions
Class AbstractMicronautExtension<C>
java.lang.Object
io.micronaut.test.extensions.AbstractMicronautExtension<C>
- Type Parameters:
C
- The extension context
- All Implemented Interfaces:
TestExecutionListener
,TestMethodInterceptor<Object>
- Direct Known Subclasses:
MicronautJunit5Extension
,MicronautSpockExtension
public abstract class AbstractMicronautExtension<C>
extends Object
implements TestExecutionListener, TestMethodInterceptor<Object>
Abstract base class for both JUnit 5 and Spock.
- Since:
- 1.0
- Author:
- graemerocher
-
Field Summary
Modifier and TypeFieldDescriptionprotected io.micronaut.context.ApplicationContext
static final String
protected io.micronaut.runtime.EmbeddedApplication
static final String
protected io.micronaut.runtime.context.scope.refresh.RefreshScope
protected io.micronaut.inject.BeanDefinition<?>
static final String
The name of the property source that contains test properties.static final String
static final String
static final String
protected MicronautTestValue
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionprotected void
afterClass
(C context) Executed after the class is complete.void
afterCleanupTest
(TestContext testContext) Executed after the setup method of a test method.void
Executed after each test completes.void
afterSetupTest
(TestContext testContext) Executed after the setup method of a test method.void
afterTestClass
(TestContext testContext) Executed after all of the tests of a class have bean executed.void
afterTestExecution
(TestContext testContext) Executed after a single test iteration has been executed .void
afterTestMethod
(TestContext testContext) Executed after a test method has been executed (a test method may contain multiple iterations).protected abstract void
alignMocks
(C context, Object instance) protected void
beforeClass
(C context, Class<?> testClass, @Nullable MicronautTestValue testAnnotationValue) Executed before tests within a class are run.void
beforeCleanupTest
(TestContext testContext) Executed before the setup method of a test method.protected void
beforeEach
(C context, @Nullable Object testInstance, @Nullable AnnotatedElement method, List<io.micronaut.context.annotation.Property> propertyAnnotations) To be called by the different implementations before each test method.void
beforeSetupTest
(TestContext testContext) Executed before the setup method of a test method.void
beforeTestClass
(TestContext testContext) Executed before all of the tests of a class are executed.void
beforeTestExecution
(TestContext testContext) Executed before a single test iteration is executed.void
beforeTestMethod
(TestContext testContext) Executed before a test method is executed (a test method may contain multiple iterations).protected boolean
interceptAfterEach
(TestMethodInvocationContext<Object> methodInvocationContext) Intercepts after each test invocation.interceptBeforeEach
(TestMethodInvocationContext<Object> methodInvocationContext) Intercepts before each test invocation.interceptTest
(TestMethodInvocationContext<Object> methodInvocationContext) Intercepts each test invocation.protected boolean
isTestSuiteBeanPresent
(Class<?> requiredTestClass) protected void
postProcessBuilder
(io.micronaut.context.ApplicationContextBuilder builder) Allows subclasses to customize the builder right before context initialization.protected abstract void
resolveTestProperties
(C context, MicronautTestValue testAnnotationValue, Map<String, Object> testProperties) Resolves any test properties.protected void
Starts the application context.
-
Field Details
-
TEST_ROLLBACK
- See Also:
-
TEST_TRANSACTIONAL
- See Also:
-
TEST_TRANSACTION_MODE
- See Also:
-
DISABLED_MESSAGE
- See Also:
-
MISCONFIGURED_MESSAGE
- See Also:
-
TEST_PROPERTY_SOURCE
The name of the property source that contains test properties.- See Also:
-
applicationContext
protected io.micronaut.context.ApplicationContext applicationContext -
embeddedApplication
protected io.micronaut.runtime.EmbeddedApplication embeddedApplication -
refreshScope
protected io.micronaut.runtime.context.scope.refresh.RefreshScope refreshScope -
specDefinition
protected io.micronaut.inject.BeanDefinition<?> specDefinition -
testProperties
-
oldValues
-
testAnnotationValue
-
-
Constructor Details
-
AbstractMicronautExtension
public AbstractMicronautExtension()
-
-
Method Details
-
hasInterceptors
protected boolean hasInterceptors()- Returns:
- True if there are interceptors
-
interceptBeforeEach
public Object interceptBeforeEach(TestMethodInvocationContext<Object> methodInvocationContext) throws Throwable Description copied from interface:TestMethodInterceptor
Intercepts before each test invocation.- Specified by:
interceptBeforeEach
in interfaceTestMethodInterceptor<C>
- Parameters:
methodInvocationContext
- the method invocation context- Returns:
- intercepted return value
- Throws:
Exception
- allows any exception to propagateThrowable
-
interceptAfterEach
public Object interceptAfterEach(TestMethodInvocationContext<Object> methodInvocationContext) throws Throwable Description copied from interface:TestMethodInterceptor
Intercepts after each test invocation.- Specified by:
interceptAfterEach
in interfaceTestMethodInterceptor<C>
- Parameters:
methodInvocationContext
- the method invocation context- Returns:
- intercepted return value
- Throws:
Exception
- allows any exception to propagateThrowable
-
interceptTest
public Object interceptTest(TestMethodInvocationContext<Object> methodInvocationContext) throws Throwable Description copied from interface:TestMethodInterceptor
Intercepts each test invocation.- Specified by:
interceptTest
in interfaceTestMethodInterceptor<C>
- Parameters:
methodInvocationContext
- the method invocation context- Returns:
- intercepted return value
- Throws:
Exception
- allows any exception to propagateThrowable
-
beforeTestExecution
Description copied from interface:TestExecutionListener
Executed before a single test iteration is executed.- Specified by:
beforeTestExecution
in interfaceTestExecutionListener
- Parameters:
testContext
- the test context- Throws:
Exception
- allows any exception to propagate
-
beforeCleanupTest
Description copied from interface:TestExecutionListener
Executed before the setup method of a test method.- Specified by:
beforeCleanupTest
in interfaceTestExecutionListener
- Parameters:
testContext
- the test context- Throws:
Exception
- allows any exception to propagate
-
afterCleanupTest
Description copied from interface:TestExecutionListener
Executed after the setup method of a test method.- Specified by:
afterCleanupTest
in interfaceTestExecutionListener
- Parameters:
testContext
- the test context- Throws:
Exception
- allows any exception to propagate
-
afterTestExecution
Description copied from interface:TestExecutionListener
Executed after a single test iteration has been executed .- Specified by:
afterTestExecution
in interfaceTestExecutionListener
- Parameters:
testContext
- the test context- Throws:
Exception
- allows any exception to propagate
-
beforeTestClass
Description copied from interface:TestExecutionListener
Executed before all of the tests of a class are executed.- Specified by:
beforeTestClass
in interfaceTestExecutionListener
- Parameters:
testContext
- the test context- Throws:
Exception
- allows any exception to propagate
-
afterTestClass
Description copied from interface:TestExecutionListener
Executed after all of the tests of a class have bean executed.- Specified by:
afterTestClass
in interfaceTestExecutionListener
- Parameters:
testContext
- the test context- Throws:
Exception
- allows any exception to propagate
-
beforeSetupTest
Description copied from interface:TestExecutionListener
Executed before the setup method of a test method.- Specified by:
beforeSetupTest
in interfaceTestExecutionListener
- Parameters:
testContext
- the test context- Throws:
Exception
- allows any exception to propagate
-
afterSetupTest
Description copied from interface:TestExecutionListener
Executed after the setup method of a test method.- Specified by:
afterSetupTest
in interfaceTestExecutionListener
- Parameters:
testContext
- the test context- Throws:
Exception
- allows any exception to propagate
-
beforeTestMethod
Description copied from interface:TestExecutionListener
Executed before a test method is executed (a test method may contain multiple iterations).- Specified by:
beforeTestMethod
in interfaceTestExecutionListener
- Parameters:
testContext
- the test context- Throws:
Exception
- allows any exception to propagate
-
afterTestMethod
Description copied from interface:TestExecutionListener
Executed after a test method has been executed (a test method may contain multiple iterations).- Specified by:
afterTestMethod
in interfaceTestExecutionListener
- Parameters:
testContext
- the test context- Throws:
Exception
- allows any exception to propagate
-
beforeClass
protected void beforeClass(C context, Class<?> testClass, @Nullable @Nullable MicronautTestValue testAnnotationValue) Executed before tests within a class are run.- Parameters:
context
- The test contexttestClass
- The test classtestAnnotationValue
- The test annotation values
-
postProcessBuilder
protected void postProcessBuilder(io.micronaut.context.ApplicationContextBuilder builder) Allows subclasses to customize the builder right before context initialization.- Parameters:
builder
- the application context builder
-
resolveTestProperties
protected abstract void resolveTestProperties(C context, MicronautTestValue testAnnotationValue, Map<String, Object> testProperties) Resolves any test properties.- Parameters:
context
- The test contexttestAnnotationValue
- The test annotationtestProperties
- The test properties
-
beforeEach
protected void beforeEach(C context, @Nullable @Nullable Object testInstance, @Nullable @Nullable AnnotatedElement method, List<io.micronaut.context.annotation.Property> propertyAnnotations) To be called by the different implementations before each test method.- Parameters:
context
- The test contexttestInstance
- The test instancemethod
- The test methodpropertyAnnotations
- The@Property
annotations found in the test method, if any
-
afterClass
Executed after the class is complete.- Parameters:
context
- the context
-
afterEach
Executed after each test completes.- Parameters:
context
- The context- Throws:
Exception
- allows any exception to propagate
-
startApplicationContext
protected void startApplicationContext()Starts the application context. -
isTestSuiteBeanPresent
- Parameters:
requiredTestClass
- The test class- Returns:
- true if the te given class has a bean definition class in the classpath (ie: the annotation processor has been run correctly)
-
alignMocks
- Parameters:
context
- The contextinstance
- The mock instance to inject
-