public class TestGuiceyAppExtension extends GuiceyExtensionsSupport
TestGuiceyApp junit 5 extension implementation. Normally, extension should be activated with annotation,
but in some cases manual registration may be used:
@RegisterExtension
static TestGuiceyAppExtension app = TestGuiceyAppExtension.forApp(MyApp.class).create()
This is complete equivalent of annotation declaration! Static modifier is important! There is no additional
methods in extension (intentionally), so registration type changes nothing in usage.
Reasons why it could be used instead of annotation:
.hooks(builder -> builder.modules(new DebugGuiceModule()))
You can't use manual registration to configure multiple applications because junit allows only one extension
instance (if you really need to use multiple applications in tests then register one with extension and for
another use DropwizardTestSupport directly).
If both declarations will be used at the same class (don't do that!) then annotation will win and manual registration will be ignored (junit default behaviour).
Other extensions requiring access to dropwizard application may use
GuiceyExtensionsSupport.lookupSupport(ExtensionContext).
| Modifier and Type | Class and Description |
|---|---|
static class |
TestGuiceyAppExtension.Builder
Builder used for manual extension registration (
forApp(Class)). |
| Constructor and Description |
|---|
TestGuiceyAppExtension() |
| Modifier and Type | Method and Description |
|---|---|
static TestGuiceyAppExtension.Builder |
forApp(java.lang.Class<? extends io.dropwizard.Application> app)
Builder for manual extension registration with
RegisterExtension. |
protected void |
onShutdown(org.junit.jupiter.api.extension.ExtensionContext context)
Hook to perform additional work after server shutdown.
|
protected io.dropwizard.testing.DropwizardTestSupport<?> |
prepareTestSupport(org.junit.jupiter.api.extension.ExtensionContext context)
The only role of actual extension class is to configure
DropwizardTestSupport object
according to annotated configuration. |
afterAll, beforeAll, getClient, getExtensionStore, getInjector, getSupport, lookupClient, lookupInjector, lookupSupport, postProcessTestInstanceresolveParameter, supportsParameterpublic static TestGuiceyAppExtension.Builder forApp(java.lang.Class<? extends io.dropwizard.Application> app)
RegisterExtension. Provides the same configuration
options as TestGuiceyApp annotation (annotation considered as preferred usage way).
IMPORTANT: extension must be used with static field only! You can't register multiple extensions!
This is just a different way of extension configuration! Resulted extension object does not provide any additional methods (and not intended to be used at all)!
Pure DropwizardTestSupport provides an ability to register custom Managed
or listener DropwizardTestSupport.addListener(DropwizardTestSupport.ServiceListener). If you need these
then use TestGuiceyAppExtension.Builder.hooks(GuiceyConfigurationHook...) to register additional managed object or
additional dropwizard bundle (which will be the same as listener above).
app - application classprotected io.dropwizard.testing.DropwizardTestSupport<?> prepareTestSupport(org.junit.jupiter.api.extension.ExtensionContext context)
GuiceyExtensionsSupportDropwizardTestSupport object
according to annotated configuration.prepareTestSupport in class GuiceyExtensionsSupportcontext - extension contextprotected void onShutdown(org.junit.jupiter.api.extension.ExtensionContext context)
GuiceyExtensionsSupportonShutdown in class GuiceyExtensionsSupportcontext - test context