Class MockitoMethodInvocationControl
java.lang.Object
org.powermock.api.mockito.internal.invocation.MockitoMethodInvocationControl
- All Implemented Interfaces:
InvocationHandler,DefaultBehavior,MethodInvocationControl
A Mockito implementation of the
MethodInvocationControl interface.-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final Objectprivate final MethodInterceptorFilterprivate final Object -
Constructor Summary
ConstructorsConstructorDescriptionMockitoMethodInvocationControl(MethodInterceptorFilter methodInterceptionFilter, Object delegator, Object mockInstance, Method... methodsToMock) Creates a new instance with a delegator.MockitoMethodInvocationControl(MethodInterceptorFilter methodInterceptionFilter, Object mockInstance, Method... methodsToMock) Creates a new instance. -
Method Summary
Modifier and TypeMethodDescriptionprivate org.mockito.verification.VerificationModeprivate org.mockito.verification.VerificationModegetVerificationModeFromMockProgress(org.mockito.internal.progress.MockingProgress mockingProgress) private voidhandleStaticVerification(Class<?> cls) private booleanprivate booleanprivate booleanbooleanDetermine whether a certain method is mocked by this Invocation Control.private ObjectperformIntercept(MethodInterceptorFilter invocationHandler, Object interceptionObject, Method method, Object[] arguments) private org.mockito.invocation.MockHandlerreplaceMatchersBinderIfNeeded(org.mockito.invocation.MockHandler mockHandler) Replay the given objects or classes.Reset the given objects or classes.Verify the given objects or classes.void
-
Field Details
-
methodInterceptorFilter
-
mockedMethods
-
delegator
-
mockInstance
-
-
Constructor Details
-
MockitoMethodInvocationControl
public MockitoMethodInvocationControl(MethodInterceptorFilter methodInterceptionFilter, Object mockInstance, Method... methodsToMock) Creates a new instance.- Parameters:
methodInterceptionFilter- The methodInterceptionFilter to be associated with this instance.mockInstance- The actual mock instance. May benull. 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. IfmethodsToMockis null or empty, all methods for theinvocationHandlerare considered to be mocked.
-
MockitoMethodInvocationControl
public MockitoMethodInvocationControl(MethodInterceptorFilter methodInterceptionFilter, Object delegator, Object mockInstance, Method... methodsToMock) Creates a new instance with a delegator. This delegator may benull(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.- Parameters:
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 benull. 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. IfmethodsToMockis null or empty, all methods for theinvocationHandlerare considered to be
-
-
Method Details
-
isMocked
Determine whether a certain method is mocked by this Invocation Control.- Specified by:
isMockedin interfaceMethodInvocationControl- Parameters:
method- The method that should be checked.- Returns:
trueif the method is mocked,falseotherwise.
-
isInVerificationMode
private boolean isInVerificationMode() -
getVerificationMode
private org.mockito.verification.VerificationMode getVerificationMode() -
getVerificationModeFromMockProgress
private org.mockito.verification.VerificationMode getVerificationModeFromMockProgress(org.mockito.internal.progress.MockingProgress mockingProgress) -
invoke
- Specified by:
invokein interfaceInvocationHandler- Throws:
Throwable
-
handleStaticVerification
-
hasBeenCaughtByMockitoProxy
private boolean hasBeenCaughtByMockitoProxy() -
performIntercept
private Object performIntercept(MethodInterceptorFilter invocationHandler, Object interceptionObject, Method method, Object[] arguments) throws Throwable - Throws:
Throwable
-
replaceMatchersBinderIfNeeded
private org.mockito.invocation.MockHandler replaceMatchersBinderIfNeeded(org.mockito.invocation.MockHandler mockHandler) -
replay
Description copied from interface:DefaultBehaviorReplay the given objects or classes. May throw exception if replay is not needed or not supported.- Specified by:
replayin interfaceDefaultBehavior- Returns:
- the result of the replay (may be
null).
-
reset
Description copied from interface:DefaultBehaviorReset the given objects or classes. May throw exception if reset is not needed or not supported.- Specified by:
resetin interfaceDefaultBehavior- Returns:
- the result of the replay (may be
null).
-
verify
Description copied from interface:DefaultBehaviorVerify the given objects or classes. May throw exception if verify is not needed or not supported.- Specified by:
verifyin interfaceDefaultBehavior- Returns:
- the result of the verification (may be
null).
-
verifyNoMoreInteractions
public void verifyNoMoreInteractions() -
toSet
-
hasDelegator
private boolean hasDelegator() -
getInvocationHandler
-