Package ru.vyarus.dropwizard.guice.test
Class GuiceyHooksRule
- java.lang.Object
-
- org.junit.rules.ExternalResource
-
- ru.vyarus.dropwizard.guice.test.GuiceyHooksRule
-
- All Implemented Interfaces:
org.junit.rules.TestRule
@Deprecated public class GuiceyHooksRule extends org.junit.rules.ExternalResource
Deprecated.use junit 5 extensions which allow hooks declaration directlyJunit rule for changing application configuration (remove some components or register test specific (e.g. mocks)). Supposed to be used in conjunction withDropwizardAppRule
orGuiceyAppRule
. Must be used ONLY withRuleChain
because normally rules order is not predictable:
To declare common extensions for all tests, declare common rule in test class (withoutstatic GuiceyAppRule RULE = new GuiceyAppRule(App.class, null); {@literal @}ClassRule public static RuleChain chain = RuleChain .outerRule(new GuiceyHooksRule((builder) -> builder.modules(...))) .around(RULE);
@ClassRule
annotation!) and use it in chain:public class BaseTest { static GuiceyHooksRule BASE = new GuiceyHooksRule((builder) -> builder.modules(...)) } public class SomeTest extends BaseTest { static GuiceyAppRule RULE = new GuiceyAppRule(App.class, null); {@literal @}ClassRule public static RuleChain chain = RuleChain .outerRule(BASE) .around(new GuiceyHooksRule((builder) -> builder.modules(...)) // optional test-specific staff .around(RULE); }
IMPORTANT: rule will not work with spock extensions (because of lifecycle specifics)! Use
UseGuiceyHooks
or newhooks
attribute inUseGuiceyApp
orUseDropwizardApp
instead.Rule is thread safe: it is assumed that rule will be applied at the same thread as test application initialization.
- Since:
- 11.04.2018
-
-
Constructor Summary
Constructors Constructor Description GuiceyHooksRule(GuiceyConfigurationHook... hooks)
Deprecated.
-
Method Summary
All Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description protected void
after()
Deprecated.protected void
before()
Deprecated.
-
-
-
Constructor Detail
-
GuiceyHooksRule
public GuiceyHooksRule(GuiceyConfigurationHook... hooks)
Deprecated.
-
-