Class MockInjectionStrategy
java.lang.Object
org.mockito.internal.configuration.injection.MockInjectionStrategy
- Direct Known Subclasses:
ConstructorInjection,PropertyAndSetterInjection,SpyOnInjectedFieldsHandler
Injector strategy contract
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic MockInjectionStrategynop()NOP Strategy that will always try the next strategy.booleanActually inject mockCandidates on field.protected abstract booleanprocessInjection(Field field, Object fieldOwner, Set<Object> mockCandidates) Process actual injection.thenTry(MockInjectionStrategy strategy) Enqueue next injection strategy.
-
Constructor Details
-
MockInjectionStrategy
public MockInjectionStrategy()
-
-
Method Details
-
nop
NOP Strategy that will always try the next strategy. -
thenTry
Enqueue next injection strategy.The implementation should take care of the actual calling if required.
- Parameters:
strategy- Queued strategy.- Returns:
- The passed strategy instance to allow chaining.
-
process
Actually inject mockCandidates on field.Actual algorithm is defined in the implementations of
processInjection(Field, Object, Set). However if injection occurred successfully, the process should returntrue, andfalseotherwise.The code takes care of calling the next strategy if available and if of course if required
- Parameters:
onField- Field needing injection.fieldOwnedBy- The owning instance of the field.mockCandidates- A set of mock candidate, that might be injected.- Returns:
trueif successful,falseotherwise.
-
processInjection
protected abstract boolean processInjection(Field field, Object fieldOwner, Set<Object> mockCandidates) Process actual injection.Don't call this method directly, instead call
process(Field, Object, Set)- Parameters:
field- Field needing injectionfieldOwner- Field owner instance.mockCandidates- Pool of mocks to inject.- Returns:
trueif injection occurred,falseotherwise
-