Class EasyMockMethodInvocationControl<T>
- java.lang.Object
-
- org.powermock.api.easymock.internal.invocationcontrol.EasyMockMethodInvocationControl<T>
-
- All Implemented Interfaces:
java.lang.reflect.InvocationHandler,DefaultBehavior,MethodInvocationControl
public class EasyMockMethodInvocationControl<T> extends java.lang.Object implements MethodInvocationControl
The default implementation of theMethodInvocationControlinterface.
-
-
Field Summary
Fields Modifier and Type Field Description private booleanhasReplayedprivate booleanhasVerifiedprivate org.easymock.internal.MockInvocationHandlerinvocationHandlerprivate java.util.Set<java.lang.reflect.Method>mockedMethodsprivate TmockInstance
-
Constructor Summary
Constructors Constructor Description EasyMockMethodInvocationControl(org.easymock.internal.MockInvocationHandler invocationHandler, java.util.Set<java.lang.reflect.Method> methodsToMock)Initializes internal state.EasyMockMethodInvocationControl(org.easymock.internal.MockInvocationHandler invocationHandler, java.util.Set<java.lang.reflect.Method> methodsToMock, T mockInstance)Initializes internal state.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description org.easymock.MockTypegetMockType()java.lang.Objectinvoke(java.lang.Object proxy, java.lang.reflect.Method method, java.lang.Object[] arguments)booleanisMocked(java.lang.reflect.Method method)Determine whether a certain method is mocked by this Invocation Control.java.lang.Objectreplay(java.lang.Object... mocks)Replay the given objects or classes.java.lang.Objectreset(java.lang.Object... mocks)Reset the given objects or classes.java.lang.Objectverify(java.lang.Object... mocks)
-
-
-
Field Detail
-
invocationHandler
private org.easymock.internal.MockInvocationHandler invocationHandler
-
mockedMethods
private java.util.Set<java.lang.reflect.Method> mockedMethods
-
mockInstance
private T mockInstance
-
hasReplayed
private boolean hasReplayed
-
hasVerified
private boolean hasVerified
-
-
Constructor Detail
-
EasyMockMethodInvocationControl
public EasyMockMethodInvocationControl(org.easymock.internal.MockInvocationHandler invocationHandler, java.util.Set<java.lang.reflect.Method> methodsToMock, T mockInstance)Initializes internal state.- Parameters:
invocationHandler- The mock invocation handler to be associated with this instance.methodsToMock- The methods that are mocked for this instance. IfmethodsToMockis null all methods for theinvocationHandlerare considered to be mocked.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.
-
EasyMockMethodInvocationControl
public EasyMockMethodInvocationControl(org.easymock.internal.MockInvocationHandler invocationHandler, java.util.Set<java.lang.reflect.Method> methodsToMock)Initializes internal state.- Parameters:
invocationHandler- The mock invocation handler to be associated with this instance.methodsToMock- The methods that are mocked for this instance. IfmethodsToMockis null all methods for theinvocationHandlerare considered to be mocked.
-
-
Method Detail
-
isMocked
public boolean isMocked(java.lang.reflect.Method method)
Description copied from interface:MethodInvocationControlDetermine 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.
-
invoke
public java.lang.Object invoke(java.lang.Object proxy, java.lang.reflect.Method method, java.lang.Object[] arguments) throws java.lang.Throwable- Specified by:
invokein interfacejava.lang.reflect.InvocationHandler- Throws:
java.lang.Throwable
-
getMockType
public org.easymock.MockType getMockType()
-
replay
public java.lang.Object replay(java.lang.Object... mocks)
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- Parameters:
mocks- The object(s) to replay. May benull.- Returns:
- the result of the replay (may be
null).
-
verify
public java.lang.Object verify(java.lang.Object... mocks)
-
reset
public java.lang.Object reset(java.lang.Object... mocks)
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- Parameters:
mocks- The object(s) to replay. May benull.- Returns:
- the result of the replay (may be
null).
-
-