Package ru.vyarus.dropwizard.guice.test
Class GuiceyAppRule<C extends io.dropwizard.Configuration>
- java.lang.Object
-
- org.junit.rules.ExternalResource
-
- ru.vyarus.dropwizard.guice.test.GuiceyAppRule<C>
-
- Type Parameters:
C- configuration type
- All Implemented Interfaces:
org.junit.rules.TestRule
public class GuiceyAppRule<C extends io.dropwizard.Configuration> extends org.junit.rules.ExternalResourceA JUnit rule for starting and stopping your guice application at the start and end of a test class.By default, the
Applicationwill be constructed using reflection to invoke the nullary constructor. If your application does not provide a public nullary constructor, you will need to override thenewApplication()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 voidafter()protected voidbefore()<A extends io.dropwizard.Application<C>>
AgetApplication()<T> TgetBean(java.lang.Class<T> type)CgetConfiguration()io.dropwizard.setup.EnvironmentgetEnvironment()com.google.inject.InjectorgetInjector()protected io.dropwizard.Application<C>newApplication()
-
-
-
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:
beforein classorg.junit.rules.ExternalResource- Throws:
java.lang.Throwable
-
after
protected void after()
- Overrides:
afterin classorg.junit.rules.ExternalResource
-
-