Class GuiceRule
java.lang.Object
org.opendaylight.infrautils.inject.guice.testutils.GuiceRule
- All Implemented Interfaces:
org.junit.rules.MethodRule
JUnit Rule which initializes Guice
Injector for tests.
Usage:
public @Rule GuiceRule guice = new GuiceRule(YourGuiceModule.class); @Inject SomeClass someClass;
- Author:
- Michael Vorburger.ch
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected static final com.google.inject.StageDefault Stage PRODUCTION.protected com.google.inject.Injectorprotected final Iterable<? extends com.google.inject.Module>protected final com.google.inject.Stage -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionorg.junit.runners.model.Statementapply(org.junit.runners.model.Statement base, org.junit.runners.model.FrameworkMethod method, Object target) protected voidsetUpGuice(Object target) protected void
-
Field Details
-
DEFAULT_STAGE
protected static final com.google.inject.Stage DEFAULT_STAGEDefault 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
-
stage
protected final com.google.inject.Stage stage -
injector
protected com.google.inject.Injector injector
-
-
Constructor Details
-
GuiceRule
public GuiceRule(com.google.inject.Module... modules) -
GuiceRule
protected GuiceRule(com.google.inject.Stage stage, com.google.inject.Module... modules) -
GuiceRule
-
-
Method Details
-
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
-
tearDownGuice
protected void tearDownGuice()
-