Class EventContext


  • public class EventContext
    extends java.lang.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

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

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

      • 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 Detail

      • 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:
        java.lang.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:
        java.lang.IllegalStateException - if the injector object not found (should be impossible)
      • getBean

        public <T> T getBean​(java.lang.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:
        java.lang.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