com.hammingweight.hammock
Class ATestDoubleHandler

java.lang.Object
  extended by com.hammingweight.hammock.ATestDoubleHandler
All Implemented Interfaces:
IClassDefinitions, IHammockExceptionErrors, IInvocationHandler
Direct Known Subclasses:
Hammock, Hamspy

public abstract class ATestDoubleHandler
extends java.lang.Object
implements IInvocationHandler, IClassDefinitions, IHammockExceptionErrors

The ATestDoubleHandler class is an IInvocationHandler that can be extended to support mock and spy objects. The class allows expectations to be set that certain methods will be invoked on mock objects. The class is an example of the composite pattern; it is an aggregation of MethodHandler instances. A MethodHandler can respond to only one method; the ATestDouble can respond to more than one method. The methods that this handler must respond to are set via the setExpectation and setStubExpectation methods.

Since:
Hammock 2.0
Author:
C.A. Meijer

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
 
Fields inherited from interface com.hammingweight.hammock.IHammockExceptionErrors
ARGUMENT_MATCHER_ALREADY_SET, CANT_SET_VOID_RETURN_VALUE, CLASS_IS_NOT_THROWABLE, DOES_NOT_SUBCLASS_MOCK_OBJECT, HANDLER_NOT_SET, INCORRECT_MOCK_OBJECT, INCORRECT_RETURN_CLASS, INCORRECT_THROWABLE_CLASS, METHOD_CANNOT_BE_EVALUATED, METHOD_INVOKED_OUT_OF_SEQUENCE, METHOD_INVOKED_TOO_MANY_TIMES, METHOD_INVOKED_UNEXPECTED_NUMBER_OF_TIMES, NO_RETURN_VALUE, NO_RETURN_VALUE_SET, NUM_INVOCATIONS_ALREADY_SET, RETURN_VALUE_ALREADY_SET, WRONG_ARGUMENT_CLASS, WRONG_NUMBER_OF_ARGS
 
Constructor Summary
ATestDoubleHandler()
           
 
Method Summary
protected  MethodHandler getExpectation(int expectationNumber)
          A method to get the MethodHandler for a particular expectation.
protected  int getNumberOfExpectations()
          A method to determine how many expectations have been set.
 MethodHandler setExpectation(MockMethod method)
          This method sets an expectation that method will be called on a mock object.
 MethodHandler setExpectation(MockMethod method, IMockObject mockObject)
          This method sets an expectation that a particular method will be invoked on a particular object.
 MethodHandler setExpectation(MockMethod method, IMockObject mockObject, java.lang.Object[] args)
          This method sets an expectation that a particular method will be invoked on a particular object with a particular set of arguments.
 MethodHandler setExpectation(MockMethod method, java.lang.Object[] args)
          This method sets an expectation that a particular method will be invoked with a particular set of arguments.
 MethodHandler setStubExpectation(MockMethod method)
          This method allows the handler to respond identically to an arbitrary, possibly zero, number of invocations of a particular method.
 MethodHandler setStubExpectation(MockMethod method, IMockObject mockObject)
          This method allows the handler to respond identically to an arbitrary, possibly zero, number of invocations of a particular method on a mock object.
 MethodHandler setStubExpectation(MockMethod method, IMockObject mockObject, java.lang.Object[] args)
          This method allows the handler to respond identically to an arbitrary, possibly zero, number of invocations of a particular method on a mock object with a particular set of arguments
 MethodHandler setStubExpectation(MockMethod method, java.lang.Object[] args)
          This method allows the handler to respond identically to an arbitrary, possibly zero, number of invocations of a particular method with a particular set of arguments.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface com.hammingweight.hammock.IInvocationHandler
invoke
 

Constructor Detail

ATestDoubleHandler

public ATestDoubleHandler()
Method Detail

setExpectation

public MethodHandler setExpectation(MockMethod method)
This method sets an expectation that method will be called on a mock object. Any arguments passed when the method is invoked will be ignored.

Parameters:
method - The method that we expect to be invoked.
Returns:
A method handler for processing an invocation of the specified method.

setExpectation

public MethodHandler setExpectation(MockMethod method,
                                    java.lang.Object[] args)
This method sets an expectation that a particular method will be invoked with a particular set of arguments. No attention is paid to the particular object that the method is invoked on.

Parameters:
method - The method that we expect to be invoked.
args - The arguments that are expected to be passed in the method invocation.
Returns:
A method handler for processing an invocation of the specified method.

setExpectation

public MethodHandler setExpectation(MockMethod method,
                                    IMockObject mockObject)
This method sets an expectation that a particular method will be invoked on a particular object.

Parameters:
method - The method that we expect to be invoked.
mockObject - The object that we expect the method to be invoked on.
Returns:
A method handler for processing an invocation of the specified method.

setExpectation

public MethodHandler setExpectation(MockMethod method,
                                    IMockObject mockObject,
                                    java.lang.Object[] args)
This method sets an expectation that a particular method will be invoked on a particular object with a particular set of arguments.

Parameters:
method - The method that we expect to be invoked.
mockObject - The object that we expect the method to be invoked on.
args - The arguments that are expected to be passed in the method invocation.
Returns:
A method handler for processing an invocation of the specified method.

setStubExpectation

public MethodHandler setStubExpectation(MockMethod method)
This method allows the handler to respond identically to an arbitrary, possibly zero, number of invocations of a particular method. Any arguments passed when the method is invoked will be ignored.

Parameters:
method - The method that may be invoked.
Returns:
A method handler for processing an invocation of the specified method.

setStubExpectation

public MethodHandler setStubExpectation(MockMethod method,
                                        java.lang.Object[] args)
This method allows the handler to respond identically to an arbitrary, possibly zero, number of invocations of a particular method with a particular set of arguments. No attention is paid to the particular object that the method is invoked on.

Parameters:
method - The method that may be invoked.
args - The arguments that are expected to be passed in the method invocation.
Returns:
A method handler for processing an invocation of the specified method.

setStubExpectation

public MethodHandler setStubExpectation(MockMethod method,
                                        IMockObject mockObject)
This method allows the handler to respond identically to an arbitrary, possibly zero, number of invocations of a particular method on a mock object.

Parameters:
method - The method that may be invoked.
mockObject - The object that we expect the method to be invoked on.
Returns:
A method handler for processing an invocation of the specified method.

setStubExpectation

public MethodHandler setStubExpectation(MockMethod method,
                                        IMockObject mockObject,
                                        java.lang.Object[] args)
This method allows the handler to respond identically to an arbitrary, possibly zero, number of invocations of a particular method on a mock object with a particular set of arguments

Parameters:
method - The method that may be invoked.
mockObject - The object that we expect the method to be invoked on.
args - The arguments that are expected to be passed in the method invocation.
Returns:
A method handler for processing an invocation of the specified method.

getNumberOfExpectations

protected int getNumberOfExpectations()
A method to determine how many expectations have been set.

Returns:
The number of expectations.

getExpectation

protected MethodHandler getExpectation(int expectationNumber)
A method to get the MethodHandler for a particular expectation.

Parameters:
expectationNumber - The expectation of interest.
Returns:
The handler for the expectation.