public class MockitoMethodInvocationControl extends java.lang.Object implements MethodInvocationControl
MethodInvocationControl interface.| Modifier and Type | Field and Description |
|---|---|
private java.lang.Object |
delegator |
private MethodInterceptorFilter |
methodInterceptorFilter |
private java.util.Set<java.lang.reflect.Method> |
mockedMethods |
private java.lang.Object |
mockInstance |
| Constructor and Description |
|---|
MockitoMethodInvocationControl(MethodInterceptorFilter methodInterceptionFilter,
java.lang.Object mockInstance,
java.lang.reflect.Method... methodsToMock)
Creates a new instance.
|
MockitoMethodInvocationControl(MethodInterceptorFilter methodInterceptionFilter,
java.lang.Object delegator,
java.lang.Object mockInstance,
java.lang.reflect.Method... methodsToMock)
Creates a new instance with a delegator.
|
| Modifier and Type | Method and Description |
|---|---|
MethodInterceptorFilter |
getInvocationHandler() |
private org.mockito.verification.VerificationMode |
getVerificationMode() |
private org.mockito.verification.VerificationMode |
getVerificationModeFromMockProgress(org.mockito.internal.progress.MockingProgress mockingProgress) |
private void |
handleStaticVerification(java.lang.Class<?> cls) |
private boolean |
hasBeenCaughtByMockitoProxy() |
private boolean |
hasDelegator() |
java.lang.Object |
invoke(java.lang.Object obj,
java.lang.reflect.Method method,
java.lang.Object[] arguments) |
private boolean |
isInVerificationMode() |
boolean |
isMocked(java.lang.reflect.Method method)
Determine whether a certain method is mocked by this Invocation Control.
|
private java.lang.Object |
performIntercept(MethodInterceptorFilter invocationHandler,
java.lang.Object interceptionObject,
java.lang.reflect.Method method,
java.lang.Object[] arguments) |
private org.mockito.invocation.MockHandler |
replaceMatchersBinderIfNeeded(org.mockito.invocation.MockHandler mockHandler) |
java.lang.Object |
replay(java.lang.Object... mocks)
Replay the given objects or classes.
|
java.lang.Object |
reset(java.lang.Object... mocks)
Reset the given objects or classes.
|
private java.util.Set<java.lang.reflect.Method> |
toSet(java.lang.reflect.Method... methods) |
java.lang.Object |
verify(java.lang.Object... mocks)
Verify the given objects or classes.
|
void |
verifyNoMoreInteractions() |
private final MethodInterceptorFilter methodInterceptorFilter
private final java.util.Set<java.lang.reflect.Method> mockedMethods
private final java.lang.Object delegator
private final java.lang.Object mockInstance
public MockitoMethodInvocationControl(MethodInterceptorFilter methodInterceptionFilter, java.lang.Object mockInstance, java.lang.reflect.Method... methodsToMock)
methodInterceptionFilter - The methodInterceptionFilter to be associated with this
instance.mockInstance - The actual mock instance. May be null. Even
though the mock instance may not be used it's needed to keep a
reference to this object otherwise it may be garbage collected
in some situations. For example when mocking static methods we
don't return the mock object and thus it will be garbage
collected (and thus the finalize method will be invoked which
will be caught by the proxy and the test will fail because we
haven't setup expectations for this method) because then that
object has no reference. In order to avoid this we keep a
reference to this instance here.methodsToMock - The methods that are mocked for this instance. If
methodsToMock is null or empty, all methods for
the invocationHandler are considered to be
mocked.public MockitoMethodInvocationControl(MethodInterceptorFilter methodInterceptionFilter, java.lang.Object delegator, java.lang.Object mockInstance, java.lang.reflect.Method... methodsToMock)
null (if it is then no calls will be forwarded to this
instance). If a delegator exists (i.e. not null) all non-mocked calls
will be delegated to that instance.methodInterceptionFilter - The methodInterceptionFilter to be associated with this
instance.delegator - If the user spies on an instance the original instance must be
injected here.mockInstance - The actual mock instance. May be null. Even
though the mock instance may not be used it's needed to keep a
reference to this object otherwise it may be garbage collected
in some situations. For example when mocking static methods we
don't return the mock object and thus it will be garbage
collected (and thus the finalize method will be invoked which
will be caught by the proxy and the test will fail because we
haven't setup expectations for this method) because then that
object has no reference. In order to avoid this we keep a
reference to this instance here.methodsToMock - The methods that are mocked for this instance. If
methodsToMock is null or empty, all methods for
the invocationHandler are considered to bepublic boolean isMocked(java.lang.reflect.Method method)
isMocked in interface MethodInvocationControlmethod - The method that should be checked.true if the method is mocked, false
otherwise.private boolean isInVerificationMode()
private org.mockito.verification.VerificationMode getVerificationMode()
private org.mockito.verification.VerificationMode getVerificationModeFromMockProgress(org.mockito.internal.progress.MockingProgress mockingProgress)
public java.lang.Object invoke(java.lang.Object obj,
java.lang.reflect.Method method,
java.lang.Object[] arguments)
throws java.lang.Throwable
invoke in interface java.lang.reflect.InvocationHandlerjava.lang.Throwableprivate void handleStaticVerification(java.lang.Class<?> cls)
private boolean hasBeenCaughtByMockitoProxy()
private java.lang.Object performIntercept(MethodInterceptorFilter invocationHandler, java.lang.Object interceptionObject, java.lang.reflect.Method method, java.lang.Object[] arguments) throws java.lang.Throwable
java.lang.Throwableprivate org.mockito.invocation.MockHandler replaceMatchersBinderIfNeeded(org.mockito.invocation.MockHandler mockHandler)
public java.lang.Object replay(java.lang.Object... mocks)
DefaultBehaviorreplay in interface DefaultBehaviornull).public java.lang.Object reset(java.lang.Object... mocks)
DefaultBehaviorreset in interface DefaultBehaviornull).public java.lang.Object verify(java.lang.Object... mocks)
DefaultBehaviorverify in interface DefaultBehaviornull).public void verifyNoMoreInteractions()
private java.util.Set<java.lang.reflect.Method> toSet(java.lang.reflect.Method... methods)
private boolean hasDelegator()
public MethodInterceptorFilter getInvocationHandler()