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
public class GuiceyHooksRule extends org.junit.rules.ExternalResourceJunit rule for changing application configuration (remove some components or register test specific (e.g. mocks)). Supposed to be used in conjunction withDropwizardAppRuleorGuiceyAppRule. Must be used ONLY withRuleChainbecause 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);@ClassRuleannotation!) 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
UseGuiceyHooksor newhooksattribute inru.vyarus.dropwizard.guice.test.spock.UseGuiceyApporru.vyarus.dropwizard.guice.test.spock.UseDropwizardAppinstead.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(ru.vyarus.dropwizard.guice.hook.GuiceyConfigurationHook... hooks)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected voidafter()protected voidbefore()
-