Package ru.vyarus.dropwizard.guice.test
Class GuiceyTestSupport<C extends io.dropwizard.core.Configuration>
- java.lang.Object
-
- io.dropwizard.testing.DropwizardTestSupport<C>
-
- ru.vyarus.dropwizard.guice.test.GuiceyTestSupport<C>
-
- Type Parameters:
C
- configuration type
public class GuiceyTestSupport<C extends io.dropwizard.core.Configuration> extends io.dropwizard.testing.DropwizardTestSupport<C>
An alternative toDropwizardTestSupport
which does not run jetty (web part) allowing to test only guice context. Internally,TestCommand
used instead ofServerCommand
.Supposed to be used in cases when application startup fail must be tested:
new GuiceyTestSupport(MyApp.class, (String) null).before()
.- Since:
- 03.02.2022
-
-
Constructor Summary
Constructors Constructor Description GuiceyTestSupport(java.lang.Class<? extends io.dropwizard.core.Application<C>> applicationClass, C configuration)
GuiceyTestSupport(java.lang.Class<? extends io.dropwizard.core.Application<C>> applicationClass, java.lang.String configPath, io.dropwizard.configuration.ConfigurationSourceProvider configSourceProvider, io.dropwizard.testing.ConfigOverride... configOverrides)
GuiceyTestSupport(java.lang.Class<? extends io.dropwizard.core.Application<C>> applicationClass, java.lang.String configPath, io.dropwizard.configuration.ConfigurationSourceProvider configSourceProvider, java.lang.String customPropertyPrefix, io.dropwizard.testing.ConfigOverride... configOverrides)
GuiceyTestSupport(java.lang.Class<? extends io.dropwizard.core.Application<C>> applicationClass, java.lang.String configPath, io.dropwizard.testing.ConfigOverride... configOverrides)
GuiceyTestSupport(java.lang.Class<? extends io.dropwizard.core.Application<C>> applicationClass, java.lang.String configPath, java.lang.String customPropertyPrefix, io.dropwizard.testing.ConfigOverride... configOverrides)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
after()
<T> T
getBean(com.google.inject.Key<T> key)
Shortcut for accessing guice beans.<T> T
getBean(java.lang.Class<T> type)
Shortcut for accessing guice beans.<T> T
run(TestSupport.RunCallback<T> callback)
Normally,DropwizardTestSupport.before()
andafter()
methods are called separately.
-
-
-
Constructor Detail
-
GuiceyTestSupport
public GuiceyTestSupport(java.lang.Class<? extends io.dropwizard.core.Application<C>> applicationClass, @Nullable java.lang.String configPath, io.dropwizard.testing.ConfigOverride... configOverrides)
-
GuiceyTestSupport
public GuiceyTestSupport(java.lang.Class<? extends io.dropwizard.core.Application<C>> applicationClass, @Nullable java.lang.String configPath, @Nullable io.dropwizard.configuration.ConfigurationSourceProvider configSourceProvider, io.dropwizard.testing.ConfigOverride... configOverrides)
-
GuiceyTestSupport
public GuiceyTestSupport(java.lang.Class<? extends io.dropwizard.core.Application<C>> applicationClass, @Nullable java.lang.String configPath, @Nullable io.dropwizard.configuration.ConfigurationSourceProvider configSourceProvider, @Nullable java.lang.String customPropertyPrefix, io.dropwizard.testing.ConfigOverride... configOverrides)
-
GuiceyTestSupport
public GuiceyTestSupport(java.lang.Class<? extends io.dropwizard.core.Application<C>> applicationClass, @Nullable java.lang.String configPath, @Nullable java.lang.String customPropertyPrefix, io.dropwizard.testing.ConfigOverride... configOverrides)
-
-
Method Detail
-
run
public <T> T run(@Nullable TestSupport.RunCallback<T> callback) throws java.lang.Exception
Normally,DropwizardTestSupport.before()
andafter()
methods are called separately. This method is a shortcut mostly for errors testing whenDropwizardTestSupport.before()
assumed to fail to make sureafter()
will be called in any case:testSupport.run(null)
.- Type Parameters:
T
- result type- Parameters:
callback
- callback (may be null)- Returns:
- callback result
- Throws:
java.lang.Exception
- any appeared exception
-
getBean
public <T> T getBean(java.lang.Class<T> type)
Shortcut for accessing guice beans.- Type Parameters:
T
- bean type- Parameters:
type
- target bean type- Returns:
- bean instance
-
getBean
public <T> T getBean(com.google.inject.Key<T> key)
Shortcut for accessing guice beans.- Type Parameters:
T
- bean type- Parameters:
key
- binding key- Returns:
- bean instance
-
after
public void after()
- Overrides:
after
in classio.dropwizard.testing.DropwizardTestSupport<C extends io.dropwizard.core.Configuration>
-
-