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
public class InjectWithGuice extends Object implements 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
Constructors Constructor Description InjectWithGuice(com.google.inject.Module... modules)
Creates an instance ofInjectWithGuice
.InjectWithGuice(Collection<com.google.inject.Module> modules)
Creates an instance ofInjectWithGuice
.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description org.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
get(Class<T> type)
Returns the appropriate instance for the provided injection type.
-
-
-
Constructor Detail
-
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
public InjectWithGuice(Collection<com.google.inject.Module> modules)
Creates an instance ofInjectWithGuice
.- Parameters:
modules
- the modules to create Guice test support with, cannot benull
, may be empty
-
-
Method Detail
-
get
public <T> T get(Class<T> type)
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
-
-