Class GuiceRule
- java.lang.Object
-
- org.opendaylight.infrautils.inject.guice.testutils.GuiceRule
-
- All Implemented Interfaces:
org.junit.rules.MethodRule
public class GuiceRule extends Object implements org.junit.rules.MethodRule
JUnit Rule which initializes GuiceInjectorfor tests.Usage:
public @Rule GuiceRule guice = new GuiceRule(YourGuiceModule.class); @Inject SomeClass someClass;
- Author:
- Michael Vorburger.ch
-
-
Field Summary
Fields Modifier and Type Field Description protected static com.google.inject.StageDEFAULT_STAGEDefault Stage PRODUCTION.protected com.google.inject.Injectorinjectorprotected Iterable<? extends com.google.inject.Module>modulesprotected com.google.inject.Stagestage
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description org.junit.runners.model.Statementapply(org.junit.runners.model.Statement base, org.junit.runners.model.FrameworkMethod method, Object target)protected voidsetUpGuice(Object target)protected voidtearDownGuice()
-
-
-
Field Detail
-
DEFAULT_STAGE
protected static final com.google.inject.Stage DEFAULT_STAGE
Default Stage PRODUCTION. Note that this is different from Guice's DEVELOPMENT default. We do this to avoid having to declare bindings of Listeners asEagerSingleton(), because in typical OpenDaylight projects there are Listener classes which are not @Inject, but must still be created (so that they're registered). See Guice documentation.
-
modules
protected final Iterable<? extends com.google.inject.Module> modules
-
stage
protected final com.google.inject.Stage stage
-
injector
protected com.google.inject.Injector injector
-
-
Constructor Detail
-
GuiceRule
public GuiceRule(com.google.inject.Module... modules)
-
GuiceRule
protected GuiceRule(com.google.inject.Stage stage, com.google.inject.Module... modules)
-
GuiceRule
@SafeVarargs public GuiceRule(Class<? extends com.google.inject.Module>... moduleClasses)
-
-
Method Detail
-
apply
public org.junit.runners.model.Statement apply(org.junit.runners.model.Statement base, org.junit.runners.model.FrameworkMethod method, Object target)- Specified by:
applyin interfaceorg.junit.rules.MethodRule
-
setUpGuice
protected void setUpGuice(Object target)
-
tearDownGuice
protected void tearDownGuice()
-
-