Class MockitoMethodInvocationControl<T>
java.lang.Object
org.powermock.api.mockito.invocation.MockitoMethodInvocationControl<T>
- All Implemented Interfaces:
InvocationHandler
,DefaultBehavior
,MethodInvocationControl
A Mockito implementation of the
MethodInvocationControl
interface.-
Field Summary
Fields -
Constructor Summary
ConstructorsConstructorDescriptionMockitoMethodInvocationControl
(Object delegator, T mockInstance, Method... methodsToMock) Creates a new instance with a delegator. -
Method Summary
Modifier and TypeMethodDescriptionprivate boolean
private boolean
private boolean
isCanBeHandledByMockito
(Method method) boolean
Determine whether a certain method is mocked by this Invocation Control.Replay the given objects or classes.Reset the given objects or classes.void
-
Field Details
-
mockedMethods
-
delegator
-
mockHandlerAdaptor
-
-
Constructor Details
-
MockitoMethodInvocationControl
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:
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. IfmethodsToMock
is null or empty, all methods for theinvocationHandler
are considered to be
-
-
Method Details
-
isMocked
Description copied from interface:MethodInvocationControl
Determine whether a certain method is mocked by this Invocation Control.- Specified by:
isMocked
in interfaceMethodInvocationControl
- Parameters:
method
- The method that should be checked.- Returns:
true
if the method is mocked,false
otherwise.
-
invoke
- Specified by:
invoke
in interfaceInvocationHandler
- Throws:
Throwable
-
isCanBeHandledByMockito
-
hasBeenCaughtByMockitoProxy
private boolean hasBeenCaughtByMockitoProxy() -
replay
Description copied from interface:DefaultBehavior
Replay the given objects or classes. May throw exception if replay is not needed or not supported.- Specified by:
replay
in interfaceDefaultBehavior
- Parameters:
mocks
- The object(s) to replay. May benull
.- Returns:
- the result of the replay (may be
null
).
-
reset
Description copied from interface:DefaultBehavior
Reset the given objects or classes. May throw exception if reset is not needed or not supported.- Specified by:
reset
in interfaceDefaultBehavior
- Parameters:
mocks
- The object(s) to replay. May benull
.- Returns:
- the result of the replay (may be
null
).
-
verifyNoMoreInteractions
public void verifyNoMoreInteractions() -
toSet
-
hasDelegator
private boolean hasDelegator() -
getMockHandlerAdaptor
-