public abstract class SelfMock<MockedType> extends Object implements InvocationHandler
To use, construct with the interface to be mocked (only one allowed, due to
Java parameterization), then call getInstance()
to create the proxy
instance.
By default, all invocations are counted and the invocation arguments retained.
See getInvocationCount(java.lang.String)
and #getInvocationArgument
for more
information.
Constructor and Description |
---|
SelfMock(Class<MockedType> klass) |
Modifier and Type | Method and Description |
---|---|
MockedType |
getInstance()
Returns a proxy instance that passes invocations to this mock.
|
<T> T |
getInvocationArg(String methodName,
int invocationIndex,
int argumentIndex,
Class<T> argType)
Returns a specific invocation argument, cast to a particular type.
|
Object[] |
getInvocationArgs(String methodName,
int invocationIndex)
Returns the arguments passed to a particular invocation of the named method
(using zero-based counting).
|
int |
getInvocationCount(String methodName)
Returns the number of times the named function was invoked.
|
<T> T |
getMostRecentInvocationArg(String methodName,
int argumentIndex,
Class<T> argType)
The a specific argument from the most recent invocation, cast to a particular
type.
|
Object[] |
getMostRecentInvocationArgs(String methodName)
Returns the arguments passed to the most recent invocation of the named
method.This is primarily useful when dealing with overloaded methods,
where you might not know what types the arguments are.
|
Object |
invoke(Object proxy,
Method method,
Object[] args) |
public SelfMock(Class<MockedType> klass)
public MockedType getInstance()
public int getInvocationCount(String methodName)
public Object[] getInvocationArgs(String methodName, int invocationIndex)
#getInvocationArgAs
is a better choice.
Note: this method returns the actual argument array that was passed to the invocation handler. Don't modify it unless you want to invalidate your tests.
IndexOutOfBoundsException
- if accessing a call that was never made.public <T> T getInvocationArg(String methodName, int invocationIndex, int argumentIndex, Class<T> argType)
public Object[] getMostRecentInvocationArgs(String methodName)
#getInvocationArgAs
is a better choice.
Note: this method returns the actual argument array that was passed to the invocation handler. Don't modify it unless you want to invalidate your tests.
public <T> T getMostRecentInvocationArg(String methodName, int argumentIndex, Class<T> argType)