Package com._1c.g5.v8.dt.testing
Class InjectWithGuice
java.lang.Object
com._1c.g5.v8.dt.testing.InjectWithGuice
- All Implemented Interfaces:
org.junit.rules.MethodRule
Method rule to inject Google Guice dependencies to the annotated test class tests. Creates new injector for each
executing test.
Example of usage:
public class Test { @Rule public InjectWithGuice injectWithGuice = new InjectWithGuice(new ModuleA(), new ModuleB()); @Inject private IServiceFromModuleA serviceFromModuleA; @Inject private IServiceFromModuleB serviceFromModuleB; @Test public void shouldTestSomething() { serviceFromModuleA.use(); serviceFromModuleB.use(); } }
-
Constructor Summary
ConstructorsConstructorDescriptionInjectWithGuice
(com.google.inject.Module... modules) Creates an instance ofInjectWithGuice
.InjectWithGuice
(Collection<com.google.inject.Module> modules) Creates an instance ofInjectWithGuice
. -
Method Summary
Modifier and TypeMethodDescriptionorg.junit.runners.model.Statement
apply
(org.junit.runners.model.Statement base, org.junit.runners.model.FrameworkMethod method, Object target) <T> T
get
(com.google.inject.Key<T> key) Returns the appropriate instance for the provided injection key.<T> T
Returns the appropriate instance for the provided injection type.
-
Constructor Details
-
InjectWithGuice
public InjectWithGuice(com.google.inject.Module... modules) Creates an instance ofInjectWithGuice
.- Parameters:
modules
- the modules to create Guice test support with, cannot benull
, may be empty
-
InjectWithGuice
Creates an instance ofInjectWithGuice
.- Parameters:
modules
- the modules to create Guice test support with, cannot benull
, may be empty
-
-
Method Details
-
get
Returns the appropriate instance for the provided injection type.- Parameters:
type
- the type of instance to get, cannot benull
- Returns:
- the appropriate instance for the provided injection type, never
null
-
get
public <T> T get(com.google.inject.Key<T> key) Returns the appropriate instance for the provided injection key.- Parameters:
key
- the key of instance to get, cannot benull
- Returns:
- the appropriate instance for the provided injection key, never
null
-
apply
public org.junit.runners.model.Statement apply(org.junit.runners.model.Statement base, org.junit.runners.model.FrameworkMethod method, Object target) - Specified by:
apply
in interfaceorg.junit.rules.MethodRule
-