|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectcom.hammingweight.hammock.MethodHandler
public class MethodHandler
The MethodHandler class creates a handler for processing a method invocation. The handler can be configured to respond more than once to a method invocation but will always respond identically. This class is used to set expectations for mock objects.
Field Summary |
---|
Fields inherited from interface com.hammingweight.hammock.IClassDefinitions |
---|
BOOLEAN_CLASS, BYTE_CLASS, CHARACTER_CLASS, DOUBLE_CLASS, FLOAT_CLASS, IMOCKOBJECT_CLASS, INTEGER_CLASS, LONG_CLASS, OBJECT_CLASS, SHORT_CLASS, THROWABLE_CLASS |
Constructor Summary | |
---|---|
MethodHandler(MethodInvocation mi)
Constructor. |
|
MethodHandler(MockMethod mockMethod)
Constructor. |
|
MethodHandler(MockMethod mockMethod,
IMockObject mockObject)
Constructor. |
|
MethodHandler(MockMethod mockMethod,
IMockObject mockObject,
java.lang.Object[] args)
Constructor. |
|
MethodHandler(MockMethod mockMethod,
java.lang.Object[] args)
Constructor. |
Method Summary | |
---|---|
MethodHandler |
ignoreArgument(int argIndex)
A method to set an argument that should be ignored when determining whether this handler responds to a particular method invocation. |
void |
invoke(MethodInvocation mi)
A method that invokes the handler. |
MethodHandler |
setArgumentMatcher(int argIndex,
IArgumentMatcher argMatcher)
This method adds an argument matcher to be added to a method handler so that two arguments, object1 and object2 can be
determined to be equal even if object1.equals(object2)
returns false. |
MethodHandler |
setDelay(long delayInMs)
A method to configure a delay before this handler responds to a method invocation. |
MethodHandler |
setInvocationCount(int expectedNumInvocations)
Sets the number of times that we expect a method to be invoked. |
MethodHandler |
setInvocationCount(int minNumber,
int maxNumber)
Sets upper and lower limits for the number of times that we expect a method to be invoked. |
MethodHandler |
setReturnValue(java.lang.Object retVal)
Sets the value to be returned if a method is invoked. |
MethodHandler |
setThrowable(java.lang.Throwable t)
Sets an exception to be thrown when the method is invoked. |
void |
verify()
A method that verifies that the handler was invoked as expected. |
Methods inherited from class java.lang.Object |
---|
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
public MethodHandler(MockMethod mockMethod)
mockMethod
- The method that this handler will respond to.public MethodHandler(MockMethod mockMethod, java.lang.Object[] args)
mockMethod
- The method that this handler responds to.args
- The expected arguments.public MethodHandler(MethodInvocation mi)
mi
- The method invocation (specifying a method, a mock object and
arguments) that this handler will respond to.public MethodHandler(MockMethod mockMethod, IMockObject mockObject)
mockMethod
- The method that this handler responds to.mockObject
- The object on which the method is invoked.public MethodHandler(MockMethod mockMethod, IMockObject mockObject, java.lang.Object[] args)
mockMethod
- The method that this handler responds to.mockObject
- The object on which the method is invoked.args
- The expected arguments.Method Detail |
---|
public MethodHandler setInvocationCount(int expectedNumInvocations)
expectedNumInvocations
- The expected number of invocations.
this
.public MethodHandler setInvocationCount(int minNumber, int maxNumber)
minNumber
- A lower expected limit.maxNumber
- An upper expected limit.
this
.public MethodHandler setReturnValue(java.lang.Object retVal)
retVal
- The value to be returned when the method is invoked. Primitive
values must be wrapped by the appropriate wrapper class (e.g.
an int
must be wrapped by an Integer
.
this
.public MethodHandler setThrowable(java.lang.Throwable t)
t
- The exception (or error) to throw,
this
.public void verify()
public void invoke(MethodInvocation mi)
mi
- The invoked method.public MethodHandler setDelay(long delayInMs)
delayInMs
- The delay in milliseconds.
this
.public MethodHandler ignoreArgument(int argIndex)
argIndex
- The argument number (indexed from zero) that can be ignored.
this
.public MethodHandler setArgumentMatcher(int argIndex, IArgumentMatcher argMatcher)
object1
and object2
can be
determined to be equal even if object1.equals(object2)
returns false.
argIndex
- The index of the argument in the method's signature.argMatcher
- A class that can determine whether two objects are equal.
this
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |