com.hammingweight.hammock
Class Hammock

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

public class Hammock
extends ATestDoubleHandler

The Hammock class is an IInvocationHandler that causes a test double associated with the handler to behave like a mock object. 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 Hammock can respond to more than one method. The methods that this handler must respond to are set via the setExpectation methods.

Since:
Hammock 1.5
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
Hammock()
           
 
Method Summary
 void invoke(MethodInvocation mi)
          Called by a test double when a method is invoked.
 boolean isVerified()
          Checks whether all expectations were met and whether no methods were unexpectedly invoked.
 void setStrictOrdering()
          Sets that the mock objects associated with this handler are strict mocks and that the methods must be invoked in the order that they were added to the handler.
 void verify()
          A method that verifies that a handler was invoked by mock objects as expected.
 
Methods inherited from class com.hammingweight.hammock.ATestDoubleHandler
getExpectation, getNumberOfExpectations, setExpectation, setExpectation, setExpectation, setExpectation, setStubExpectation, setStubExpectation, setStubExpectation, setStubExpectation
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Hammock

public Hammock()
Method Detail

verify

public void verify()
A method that verifies that a handler was invoked by mock objects as expected.

Throws:
HammockException - if verification fails.

isVerified

public boolean isVerified()
Checks whether all expectations were met and whether no methods were unexpectedly invoked.

Returns:
true if, and only if, all expectations were met and no methods were unepectedly invoked.
Since:
Hammock 2.0

setStrictOrdering

public void setStrictOrdering()
Sets that the mock objects associated with this handler are strict mocks and that the methods must be invoked in the order that they were added to the handler.


invoke

public void invoke(MethodInvocation mi)
Called by a test double when a method is invoked. This method sets the return value for the invocation if this handler can process the invocation. If the handler cannot process the method invocation it throws a HammockException. An exception is also thrown if strict expectations have been set and a method is invoked out of sequence.

Parameters:
mi - The method invocation.
Throws:
HammockException