Class TestJunitExtension

java.lang.Object
io.helidon.testing.junit5.TestJunitExtension
All Implemented Interfaces:
org.junit.jupiter.api.extension.AfterAllCallback, org.junit.jupiter.api.extension.BeforeAllCallback, org.junit.jupiter.api.extension.Extension, org.junit.jupiter.api.extension.InvocationInterceptor, org.junit.jupiter.api.extension.ParameterResolver
Direct Known Subclasses:
HelidonJunitExtension

public class TestJunitExtension extends Object implements org.junit.jupiter.api.extension.Extension, org.junit.jupiter.api.extension.InvocationInterceptor, org.junit.jupiter.api.extension.BeforeAllCallback, org.junit.jupiter.api.extension.AfterAllCallback, org.junit.jupiter.api.extension.ParameterResolver
Helidon JUnit extension, added through Testing.Test.

This extension has the following features:

  • Run constructor and every test class method within a custom Context
  • Support configuration annotations to set up configuration before running the tests
  • Support for injection service registry (if on classpath) to discover configuration
  • Nested Class Summary

    Nested classes/interfaces inherited from interface org.junit.jupiter.api.extension.InvocationInterceptor

    org.junit.jupiter.api.extension.InvocationInterceptor.Invocation<T>
  • Constructor Summary

    Constructors
    Modifier
    Constructor
    Description
    protected
    Default constructor with no side effects.
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    afterAll(org.junit.jupiter.api.extension.ExtensionContext context)
     
    void
    beforeAll(org.junit.jupiter.api.extension.ExtensionContext ctx)
     
    protected void
    initStaticContext(org.junit.jupiter.api.extension.ExtensionContext ctx)
    Initialize the static context to be used for all actions this extension invokes, and to store the global instances.
    protected void
    initStaticContext(org.junit.jupiter.api.extension.ExtensionContext.Store store, org.junit.jupiter.api.extension.ExtensionContext ctx)
    Initialize the static context to be used for all actions this extension invokes, and to store the global instances.
    void
    interceptAfterAllMethod(org.junit.jupiter.api.extension.InvocationInterceptor.Invocation<Void> invocation, org.junit.jupiter.api.extension.ReflectiveInvocationContext<Method> ic, org.junit.jupiter.api.extension.ExtensionContext ctx)
     
    void
    interceptAfterEachMethod(org.junit.jupiter.api.extension.InvocationInterceptor.Invocation<Void> invocation, org.junit.jupiter.api.extension.ReflectiveInvocationContext<Method> ic, org.junit.jupiter.api.extension.ExtensionContext ctx)
     
    void
    interceptBeforeAllMethod(org.junit.jupiter.api.extension.InvocationInterceptor.Invocation<Void> invocation, org.junit.jupiter.api.extension.ReflectiveInvocationContext<Method> ic, org.junit.jupiter.api.extension.ExtensionContext ctx)
     
    void
    interceptBeforeEachMethod(org.junit.jupiter.api.extension.InvocationInterceptor.Invocation<Void> invocation, org.junit.jupiter.api.extension.ReflectiveInvocationContext<Method> ic, org.junit.jupiter.api.extension.ExtensionContext ctx)
     
    void
    interceptDynamicTest(org.junit.jupiter.api.extension.InvocationInterceptor.Invocation<Void> invocation, org.junit.jupiter.api.extension.DynamicTestInvocationContext ic, org.junit.jupiter.api.extension.ExtensionContext ctx)
     
    <T> T
    interceptTestClassConstructor(org.junit.jupiter.api.extension.InvocationInterceptor.Invocation<T> invocation, org.junit.jupiter.api.extension.ReflectiveInvocationContext<Constructor<T>> ic, org.junit.jupiter.api.extension.ExtensionContext ctx)
     
    <T> T
    interceptTestFactoryMethod(org.junit.jupiter.api.extension.InvocationInterceptor.Invocation<T> invocation, org.junit.jupiter.api.extension.ReflectiveInvocationContext<Method> ic, org.junit.jupiter.api.extension.ExtensionContext ctx)
     
    void
    interceptTestMethod(org.junit.jupiter.api.extension.InvocationInterceptor.Invocation<Void> invocation, org.junit.jupiter.api.extension.ReflectiveInvocationContext<Method> ic, org.junit.jupiter.api.extension.ExtensionContext ctx)
     
    void
    interceptTestTemplateMethod(org.junit.jupiter.api.extension.InvocationInterceptor.Invocation<Void> invocation, org.junit.jupiter.api.extension.ReflectiveInvocationContext<Method> ic, org.junit.jupiter.api.extension.ExtensionContext ctx)
     
    protected <T> T
    invoke(org.junit.jupiter.api.extension.ExtensionContext ctx, org.junit.jupiter.api.extension.InvocationInterceptor.Invocation<T> invocation)
    Invoke a JUnit invocation within context.
    resolveParameter(org.junit.jupiter.api.extension.ParameterContext pc, org.junit.jupiter.api.extension.ExtensionContext ctx)
     
    protected void
    run(org.junit.jupiter.api.extension.ExtensionContext ctx, Runnable runnable)
    Run a runnable within context.
    protected <E extends Throwable>
    void
    runChecked(org.junit.jupiter.api.extension.ExtensionContext ctx, Functions.CheckedRunnable<E> runnable)
    Invoke a runnable that may throw a checked exception.
    protected Optional<Context>
    staticContext(org.junit.jupiter.api.extension.ExtensionContext ctx)
    The current "static" context (if already available) that the test actions will be executed in.
    protected static org.junit.jupiter.api.extension.ExtensionContext.Store
    store(org.junit.jupiter.api.extension.ExtensionContext ctx, AnnotatedElement... qualifiers)
    Get a JUnit extension store.
    protected static <T> Optional<T>
    storeLookup(org.junit.jupiter.api.extension.ExtensionContext.Store store, Object key, Class<T> type)
    Get an object from the given store.
    protected <T> T
    supply(org.junit.jupiter.api.extension.ExtensionContext ctx, Supplier<T> supplier)
    Call a supplier within context.
    protected <T, E extends Throwable>
    T
    supplyChecked(org.junit.jupiter.api.extension.ExtensionContext ctx, Functions.CheckedSupplier<T,E> supplier)
    Call a supplier that can throw Throwable within context.
    boolean
    supportsParameter(org.junit.jupiter.api.extension.ParameterContext pc, org.junit.jupiter.api.extension.ExtensionContext ctx)
     

    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

    interceptDynamicTest
  • Constructor Details

    • TestJunitExtension

      protected TestJunitExtension()
      Default constructor with no side effects.
  • Method Details

    • beforeAll

      public void beforeAll(org.junit.jupiter.api.extension.ExtensionContext ctx)
      Specified by:
      beforeAll in interface org.junit.jupiter.api.extension.BeforeAllCallback
    • afterAll

      public void afterAll(org.junit.jupiter.api.extension.ExtensionContext context)
      Specified by:
      afterAll in interface org.junit.jupiter.api.extension.AfterAllCallback
    • supportsParameter

      public boolean supportsParameter(org.junit.jupiter.api.extension.ParameterContext pc, org.junit.jupiter.api.extension.ExtensionContext ctx) 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 pc, org.junit.jupiter.api.extension.ExtensionContext ctx) 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
    • interceptTestClassConstructor

      public <T> T interceptTestClassConstructor(org.junit.jupiter.api.extension.InvocationInterceptor.Invocation<T> invocation, org.junit.jupiter.api.extension.ReflectiveInvocationContext<Constructor<T>> ic, org.junit.jupiter.api.extension.ExtensionContext ctx) throws Throwable
      Specified by:
      interceptTestClassConstructor in interface org.junit.jupiter.api.extension.InvocationInterceptor
      Throws:
      Throwable
    • interceptBeforeAllMethod

      public void interceptBeforeAllMethod(org.junit.jupiter.api.extension.InvocationInterceptor.Invocation<Void> invocation, org.junit.jupiter.api.extension.ReflectiveInvocationContext<Method> ic, org.junit.jupiter.api.extension.ExtensionContext ctx) throws Throwable
      Specified by:
      interceptBeforeAllMethod in interface org.junit.jupiter.api.extension.InvocationInterceptor
      Throws:
      Throwable
    • interceptBeforeEachMethod

      public void interceptBeforeEachMethod(org.junit.jupiter.api.extension.InvocationInterceptor.Invocation<Void> invocation, org.junit.jupiter.api.extension.ReflectiveInvocationContext<Method> ic, org.junit.jupiter.api.extension.ExtensionContext ctx) 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> ic, org.junit.jupiter.api.extension.ExtensionContext ctx) throws Throwable
      Specified by:
      interceptTestMethod 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> ic, org.junit.jupiter.api.extension.ExtensionContext ctx) throws Throwable
      Specified by:
      interceptTestFactoryMethod 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> ic, org.junit.jupiter.api.extension.ExtensionContext ctx) throws Throwable
      Specified by:
      interceptTestTemplateMethod in interface org.junit.jupiter.api.extension.InvocationInterceptor
      Throws:
      Throwable
    • interceptDynamicTest

      public void interceptDynamicTest(org.junit.jupiter.api.extension.InvocationInterceptor.Invocation<Void> invocation, org.junit.jupiter.api.extension.DynamicTestInvocationContext ic, org.junit.jupiter.api.extension.ExtensionContext ctx) throws Throwable
      Specified by:
      interceptDynamicTest 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> ic, org.junit.jupiter.api.extension.ExtensionContext ctx) throws Throwable
      Specified by:
      interceptAfterEachMethod in interface org.junit.jupiter.api.extension.InvocationInterceptor
      Throws:
      Throwable
    • interceptAfterAllMethod

      public void interceptAfterAllMethod(org.junit.jupiter.api.extension.InvocationInterceptor.Invocation<Void> invocation, org.junit.jupiter.api.extension.ReflectiveInvocationContext<Method> ic, org.junit.jupiter.api.extension.ExtensionContext ctx) throws Throwable
      Specified by:
      interceptAfterAllMethod in interface org.junit.jupiter.api.extension.InvocationInterceptor
      Throws:
      Throwable
    • initStaticContext

      protected void initStaticContext(org.junit.jupiter.api.extension.ExtensionContext ctx)
      Initialize the static context to be used for all actions this extension invokes, and to store the global instances. This extension creates a unit test context by default for each test class.
      Parameters:
      ctx - JUnit extension context
    • initStaticContext

      protected void initStaticContext(org.junit.jupiter.api.extension.ExtensionContext.Store store, org.junit.jupiter.api.extension.ExtensionContext ctx)
      Initialize the static context to be used for all actions this extension invokes, and to store the global instances. This extension creates a unit test context by default for each test class.
      Parameters:
      store - JUnit extension store
      ctx - JUnit extension context
    • storeLookup

      protected static <T> Optional<T> storeLookup(org.junit.jupiter.api.extension.ExtensionContext.Store store, Object key, Class<T> type)
      Get an object from the given store.
      Type Parameters:
      T - object type
      Parameters:
      store - store
      key - key
      type - type
      Returns:
      optional
    • staticContext

      protected Optional<Context> staticContext(org.junit.jupiter.api.extension.ExtensionContext ctx)
      The current "static" context (if already available) that the test actions will be executed in.
      Parameters:
      ctx - JUnit extension context
      Returns:
      context used by this extension
    • store

      protected static org.junit.jupiter.api.extension.ExtensionContext.Store store(org.junit.jupiter.api.extension.ExtensionContext ctx, AnnotatedElement... qualifiers)
      Get a JUnit extension store.
      Parameters:
      ctx - JUnit extension context
      qualifiers - qualifiers
      Returns:
      JUnit extension store
    • supply

      protected <T> T supply(org.junit.jupiter.api.extension.ExtensionContext ctx, Supplier<T> supplier) throws Throwable
      Call a supplier within context.
      Type Parameters:
      T - type of the result
      Parameters:
      ctx - JUnit extension context
      supplier - callable to invoke
      Returns:
      result of the callable
      Throws:
      Throwable - in case the call to callable threw an exception
    • supplyChecked

      protected <T, E extends Throwable> T supplyChecked(org.junit.jupiter.api.extension.ExtensionContext ctx, Functions.CheckedSupplier<T,E> supplier) throws E
      Call a supplier that can throw Throwable within context.
      Type Parameters:
      T - type of the result
      E - type of checked exception that is expected
      Parameters:
      ctx - JUnit extension context
      supplier - supplier to invoke
      Returns:
      result of the callable
      Throws:
      E - in case the call to callable threw an exception
    • run

      protected void run(org.junit.jupiter.api.extension.ExtensionContext ctx, Runnable runnable)
      Run a runnable within context.
      Parameters:
      ctx - JUnit extension context
      runnable - runnable to run
    • runChecked

      protected <E extends Throwable> void runChecked(org.junit.jupiter.api.extension.ExtensionContext ctx, Functions.CheckedRunnable<E> runnable) throws E
      Invoke a runnable that may throw a checked exception.
      Type Parameters:
      E - type of the exception that can be thrown
      Parameters:
      ctx - JUnit extension context
      runnable - runnable to run
      Throws:
      E - in case the runnable threw an exception
    • invoke

      protected <T> T invoke(org.junit.jupiter.api.extension.ExtensionContext ctx, org.junit.jupiter.api.extension.InvocationInterceptor.Invocation<T> invocation) throws Throwable
      Invoke a JUnit invocation within context.
      Type Parameters:
      T - type of the returned value
      Parameters:
      ctx - JUnit extension context
      invocation - invocation to invoke
      Returns:
      result of the invocation
      Throws:
      Throwable - in case the invocation threw an exception