Class GuiceyAppRule<C extends io.dropwizard.Configuration>

  • Type Parameters:
    C - configuration type
    All Implemented Interfaces:
    org.junit.rules.TestRule

    public class GuiceyAppRule<C extends io.dropwizard.Configuration>
    extends org.junit.rules.ExternalResource
    A JUnit rule for starting and stopping your guice application at the start and end of a test class.

    By default, the Application will be constructed using reflection to invoke the nullary constructor. If your application does not provide a public nullary constructor, you will need to override the newApplication() method to provide your application instance(s).

    Based on DropwizardAppRule, but doesn't start jetty and as a consequence jersey and guice web modules not initialized. Emulates managed objects lifecycle.

    Suppose to be used for testing internal services business logic as lightweight alternative for dropwizard rule.

    Since:
    23.10.2014
    See Also:
    for junit 5 alterantive
    • Constructor Summary

      Constructors 
      Constructor Description
      GuiceyAppRule​(java.lang.Class<? extends io.dropwizard.Application<C>> applicationClass, java.lang.String configPath, io.dropwizard.testing.ConfigOverride... configOverrides)  
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      protected void after()  
      protected void before()  
      <A extends io.dropwizard.Application<C>>
      A
      getApplication()  
      <T> T getBean​(java.lang.Class<T> type)  
      C getConfiguration()  
      io.dropwizard.setup.Environment getEnvironment()  
      com.google.inject.Injector getInjector()  
      protected io.dropwizard.Application<C> newApplication()  
      • Methods inherited from class org.junit.rules.ExternalResource

        apply
      • Methods inherited from class java.lang.Object

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

      • GuiceyAppRule

        public GuiceyAppRule​(java.lang.Class<? extends io.dropwizard.Application<C>> applicationClass,
                             @Nullable
                             java.lang.String configPath,
                             io.dropwizard.testing.ConfigOverride... configOverrides)
    • Method Detail

      • getConfiguration

        public C getConfiguration()
      • getApplication

        public <A extends io.dropwizard.Application<C>> A getApplication()
      • getEnvironment

        public io.dropwizard.setup.Environment getEnvironment()
      • getInjector

        public com.google.inject.Injector getInjector()
      • getBean

        public <T> T getBean​(java.lang.Class<T> type)
      • newApplication

        protected io.dropwizard.Application<C> newApplication()
      • before

        protected void before()
                       throws java.lang.Throwable
        Overrides:
        before in class org.junit.rules.ExternalResource
        Throws:
        java.lang.Throwable
      • after

        protected void after()
        Overrides:
        after in class org.junit.rules.ExternalResource