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
  • Constructor Details

    • MicronautJunit5Extension

      public MicronautJunit5Extension()
  • Method Details

    • beforeAll

      public void beforeAll(org.junit.jupiter.api.extension.ExtensionContext extensionContext) throws Exception
      Specified by:
      beforeAll in interface org.junit.jupiter.api.extension.BeforeAllCallback
      Throws:
      Exception
    • buildMicronautTestValue

      protected MicronautTestValue buildMicronautTestValue(Class<?> testClass)
      Builds a MicronautTestValue 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 interface org.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 interface org.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 interface org.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 interface org.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 interface org.junit.jupiter.api.extension.InvocationInterceptor
      Throws:
      Throwable
    • afterAll

      public void afterAll(org.junit.jupiter.api.extension.ExtensionContext extensionContext) throws Exception
      Specified by:
      afterAll in interface org.junit.jupiter.api.extension.AfterAllCallback
      Throws:
      Exception
    • beforeEach

      public void beforeEach(org.junit.jupiter.api.extension.ExtensionContext extensionContext) throws Exception
      Specified by:
      beforeEach in interface org.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 interface org.junit.jupiter.api.extension.AfterEachCallback
      Overrides:
      afterEach in class AbstractMicronautExtension<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 interface org.junit.jupiter.api.extension.ExecutionCondition
    • hasExpectedAnnotations

      protected boolean hasExpectedAnnotations(Class<?> testClass)
      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 class AbstractMicronautExtension<org.junit.jupiter.api.extension.ExtensionContext>
      Parameters:
      context - The test context
      testAnnotationValue - The test annotation
      testProperties - The test properties
    • alignMocks

      protected void alignMocks(org.junit.jupiter.api.extension.ExtensionContext context, Object instance)
      Specified by:
      alignMocks in class AbstractMicronautExtension<org.junit.jupiter.api.extension.ExtensionContext>
      Parameters:
      context - The context
      instance - The mock instance to inject
    • afterTestExecution

      public void afterTestExecution(org.junit.jupiter.api.extension.ExtensionContext context) throws Exception
      Specified by:
      afterTestExecution in interface org.junit.jupiter.api.extension.AfterTestExecutionCallback
      Throws:
      Exception
    • beforeTestExecution

      public void beforeTestExecution(org.junit.jupiter.api.extension.ExtensionContext context) throws Exception
      Specified by:
      beforeTestExecution in interface org.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 interface org.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 interface org.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