Class TestSupportHolder

java.lang.Object
ru.vyarus.dropwizard.guice.test.builder.TestSupportHolder

public final class TestSupportHolder extends Object
Holds DropwizardTestSupport object during test application execution. Works for junit 5 extensions run and for manual runs with TestSupport.run(io.dropwizard.testing.DropwizardTestSupport, ru.vyarus.dropwizard.guice.test.TestSupport.RunCallback) method (or builder run methods).
Since:
15.11.2023
  • Method Details

    • setContext

      public static void setContext(io.dropwizard.testing.DropwizardTestSupport<?> support, @Nullable TestClientFactory clientFactory)
      Used to register a context support object. Intended to be used ONLY by guicey.
      Parameters:
      support - context support object
      clientFactory - custom factory object for ClientSupport (may be null for default factory usage)
      Throws:
      IllegalStateException - if any support object already bound in thread
    • setContext

      public static void setContext(io.dropwizard.testing.DropwizardTestSupport<?> support, @Nullable ClientSupport client)
      Used to register a context support object. Intended to be used ONLY by guicey.
      Parameters:
      support - context support object
      client - client support instance (from junit 5 extension context; null to create new client)
      Throws:
      IllegalStateException - if any support object already bound in thread
    • getContext

      public static <C extends io.dropwizard.core.Configuration> io.dropwizard.testing.DropwizardTestSupport<C> getContext()
      Obtain the test support object, used for test application execution (by junit 5 extension or with TestSupport.run(io.dropwizard.testing.DropwizardTestSupport, ru.vyarus.dropwizard.guice.test.TestSupport.RunCallback) (or any derived method, like builder run methods).

      Use isContextSet() to check context initialization

      Type Parameters:
      C - configuration type
      Returns:
      context support object
      Throws:
      NullPointerException - if test support context is not bound in thread
    • isContextSet

      public static boolean isContextSet()
      Returns:
      true if the support object is bound in thread, false otherwise
    • getClient

      public static ClientSupport getClient()
      Returns:
      context test web client (in case of junit extensions would be the same client as in extenion)
    • reset

      public static void reset()
      Reset thread-bound state.