public class DelayedInjectionRunner
extends org.junit.runners.BlockJUnit4ClassRunner
InjectDelayed and BeforeInjecting.
This runner also initializes fields with Mockito's Mock, Spy and
InjectMocks.
Mockito's Mock and InjectMocks are initialized before
Before methods are run. This leaves no possibility to initialize some mock
behavior before InjectMocks fields get instantiated.
The runner fills this gap by introducing BeforeInjecting. At the time these methods
are run Mockito's annotation will have taken effect but not InjectDelayed. Fields with
this annotation are initialized after BeforeInjecting methods have been run.
Additionally, after a field annotated with InjectDelayed has been initialized, its
PostConstruct method will be invoked, if available.
Important: It is required to declare all dependencies of classes annotated with
InjectDelayed as Mock fields. If a dependency is missing, an exception
will be thrown.
| Constructor and Description |
|---|
DelayedInjectionRunner(Class<?> clazz) |
| Modifier and Type | Method and Description |
|---|---|
protected org.junit.runners.model.Statement |
createDelayedInjectsStatement(Object target,
org.junit.runners.model.Statement statement,
List<org.junit.runners.model.FrameworkField> delayedFields)
Creates a statement that will instantiate the fields annotated with
InjectDelayed. |
void |
run(org.junit.runner.notification.RunNotifier notifier) |
org.junit.runners.model.Statement |
withBefores(org.junit.runners.model.FrameworkMethod method,
Object target,
org.junit.runners.model.Statement statement) |
collectInitializationErrors, computeTestMethods, createTest, describeChild, getChildren, getTestRules, isIgnored, methodBlock, methodInvoker, possiblyExpectingExceptions, rules, runChild, testName, validateConstructor, validateFields, validateInstanceMethods, validateNoNonStaticInnerClass, validateOnlyOneConstructor, validateTestMethods, validateZeroArgConstructor, withAfters, withPotentialTimeoutpublic DelayedInjectionRunner(Class<?> clazz) throws org.junit.runners.model.InitializationError
org.junit.runners.model.InitializationErrorpublic org.junit.runners.model.Statement withBefores(org.junit.runners.model.FrameworkMethod method,
Object target,
org.junit.runners.model.Statement statement)
withBefores in class org.junit.runners.BlockJUnit4ClassRunnerpublic void run(org.junit.runner.notification.RunNotifier notifier)
run in class org.junit.runners.ParentRunner<org.junit.runners.model.FrameworkMethod>protected org.junit.runners.model.Statement createDelayedInjectsStatement(Object target, org.junit.runners.model.Statement statement, List<org.junit.runners.model.FrameworkField> delayedFields)
InjectDelayed.
Override this method to provide another statement. For example, you can override
RunDelayedInjects.getInjector() to use a differently configured injector.target - the object the test will be run onstatement - the next statementdelayedFields - fields annotated with InjectDelayedCopyright © 2017. All rights reserved.