java.lang.Object
ru.vyarus.dropwizard.guice.test.jupiter.env.listen.EventContext

public class EventContext extends Object
Event context wraps junit ExtensionContext and provides access for the main test objects (like injector, test support and http client). Custom object is required mainly for lambda even listeners, which are unable to see default interface methods.
Since:
20.02.2025
  • Constructor Summary

    Constructors
    Constructor
    Description
    EventContext(org.junit.jupiter.api.extension.ExtensionContext context, boolean debug)
    Create event context.
  • Method Summary

    Modifier and Type
    Method
    Description
    <T> T
    getBean(Class<T> type)
    Shortcut to get bean directly from injector.
    Note that client is created even for pure guicey tests (in case if something external must be called).
    com.google.inject.Injector
    Normally, it is impossible that injector would not be found (under called lifecycle methods).
    org.junit.jupiter.api.extension.ExtensionContext
     
    io.dropwizard.testing.DropwizardTestSupport<?>
    Normally, it is impossible that support would not be found (under called lifecycle methods).
    boolean
    Useful to bind debug options on the extension debug (no need for additional keys).
    boolean
     

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • EventContext

      public EventContext(org.junit.jupiter.api.extension.ExtensionContext context, boolean debug)
      Create event context.
      Parameters:
      context - extension context
      debug - true if debug enabled in extension
  • Method Details

    • getJunitContext

      public org.junit.jupiter.api.extension.ExtensionContext getJunitContext()
      Returns:
      junit context
    • isDebug

      public boolean isDebug()
      Useful to bind debug options on the extension debug (no need for additional keys).
      Returns:
      true if debug is enabled on guicey extension
    • getSupport

      public io.dropwizard.testing.DropwizardTestSupport<?> getSupport()
      Normally, it is impossible that support would not be found (under called lifecycle methods).
      Returns:
      dropwizard support object (or guicey support)
      Throws:
      IllegalStateException - if the support object not found (should be impossible)
    • getInjector

      public com.google.inject.Injector getInjector()
      Normally, it is impossible that injector would not be found (under called lifecycle methods).
      Returns:
      injector instance
      Throws:
      IllegalStateException - if the injector object not found (should be impossible)
    • getBean

      public <T> T getBean(Class<T> type)
      Shortcut to get bean directly from injector.
      Type Parameters:
      T - bean type
      Parameters:
      type - bean class
      Returns:
      bean instance, never null (throw error if not found)
    • getClient

      public ClientSupport getClient()
      Note that client is created even for pure guicey tests (in case if something external must be called).
      Returns:
      client instance
      Throws:
      IllegalStateException - if the client object not found (should be impossible)
    • isWebStarted

      public boolean isWebStarted()
      Returns:
      true if complete application started, false for guice-only part