Class MockitoMethodInvocationControl
- java.lang.Object
-
- org.powermock.api.mockito.internal.invocation.MockitoMethodInvocationControl
-
- All Implemented Interfaces:
InvocationHandler
,DefaultBehavior
,MethodInvocationControl
public class MockitoMethodInvocationControl extends Object implements MethodInvocationControl
A Mockito implementation of theMethodInvocationControl
interface.
-
-
Constructor Summary
Constructors Constructor Description MockitoMethodInvocationControl(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
All Methods Instance Methods Concrete Methods Modifier and Type Method Description MethodInterceptorFilter
getInvocationHandler()
Object
invoke(Object obj, Method method, Object[] arguments)
boolean
isMocked(Method method)
Determine whether a certain method is mocked by this Invocation Control.Object
replay(Object... mocks)
Replay the given objects or classes.Object
reset(Object... mocks)
Reset the given objects or classes.Object
verify(Object... mocks)
Verify the given objects or classes.void
verifyNoMoreInteractions()
-
-
-
Constructor Detail
-
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. IfmethodsToMock
is null or empty, all methods for theinvocationHandler
are 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. IfmethodsToMock
is null or empty, all methods for theinvocationHandler
are considered to be
-
-
Method Detail
-
isMocked
public boolean isMocked(Method method)
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
public Object invoke(Object obj, Method method, Object[] arguments) throws Throwable
- Specified by:
invoke
in interfaceInvocationHandler
- Throws:
Throwable
-
replay
public Object replay(Object... mocks)
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
- Returns:
- the result of the replay (may be
null
).
-
reset
public Object reset(Object... mocks)
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
- Returns:
- the result of the replay (may be
null
).
-
verify
public Object verify(Object... mocks)
Description copied from interface:DefaultBehavior
Verify the given objects or classes. May throw exception if verify is not needed or not supported.- Specified by:
verify
in interfaceDefaultBehavior
- Returns:
- the result of the verification (may be
null
).
-
verifyNoMoreInteractions
public void verifyNoMoreInteractions()
-
getInvocationHandler
public MethodInterceptorFilter getInvocationHandler()
-
-