Class MockInjectionStrategy
- java.lang.Object
-
- org.mockito.internal.configuration.injection.MockInjectionStrategy
-
- Direct Known Subclasses:
ConstructorInjection,PropertyAndSetterInjection,SpyOnInjectedFieldsHandler
public abstract class MockInjectionStrategy extends java.lang.ObjectInjector strategy contract
-
-
Field Summary
Fields Modifier and Type Field Description private MockInjectionStrategynextStrategy
-
Constructor Summary
Constructors Constructor Description MockInjectionStrategy()
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description static MockInjectionStrategynop()NOP Strategy that will always try the next strategy.booleanprocess(java.lang.reflect.Field onField, java.lang.Object fieldOwnedBy, java.util.Set<java.lang.Object> mockCandidates)Actually inject mockCandidates on field.protected abstract booleanprocessInjection(java.lang.reflect.Field field, java.lang.Object fieldOwner, java.util.Set<java.lang.Object> mockCandidates)Process actual injection.private booleanrelayProcessToNextStrategy(java.lang.reflect.Field field, java.lang.Object fieldOwner, java.util.Set<java.lang.Object> mockCandidates)MockInjectionStrategythenTry(MockInjectionStrategy strategy)Enqueue next injection strategy.
-
-
-
Field Detail
-
nextStrategy
private MockInjectionStrategy nextStrategy
-
-
Method Detail
-
nop
public static MockInjectionStrategy nop()
NOP Strategy that will always try the next strategy.
-
thenTry
public MockInjectionStrategy thenTry(MockInjectionStrategy strategy)
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
public boolean process(java.lang.reflect.Field onField, java.lang.Object fieldOwnedBy, java.util.Set<java.lang.Object> mockCandidates)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(java.lang.reflect.Field field, java.lang.Object fieldOwner, java.util.Set<java.lang.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
-
relayProcessToNextStrategy
private boolean relayProcessToNextStrategy(java.lang.reflect.Field field, java.lang.Object fieldOwner, java.util.Set<java.lang.Object> mockCandidates)
-
-