com.hammingweight.hammock
Class InvocationMatcher

java.lang.Object
  extended by com.hammingweight.hammock.InvocationMatcher
All Implemented Interfaces:
IHammockExceptionErrors

public class InvocationMatcher
extends java.lang.Object
implements IHammockExceptionErrors

The InvocationMatcher class is a helper class for verifying that expected and actual method invocations are equal.

Since:
Hammock 2.0
Author:
C.A. Meijer

Field Summary
 
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
InvocationMatcher(MockMethod mockMethod)
          Constructor.
InvocationMatcher(MockMethod mockMethod, IMockObject mockObject)
           
InvocationMatcher(MockMethod mockMethod, IMockObject mockObject, java.lang.Object[] expectedArgs)
          Constructor.
InvocationMatcher(MockMethod mockMethod, java.lang.Object[] expectedArgs)
          Constructor.
 
Method Summary
 MockMethod getMethod()
          A method to determine the method that is being validated.
 InvocationMatcher ignoreArgument(int argIndex)
          A method to specify that we must ignore a particular argument when verifying whether expected and actual arguments are equal.
 boolean isMatch(MethodInvocation methodInvocation)
          Verifies that the actual arguments passed to a method are as expected (i.e.
 InvocationMatcher setArgumentMatcher(int argIndex, IArgumentMatcher argMatcher)
          A method to set an argument matcher for a specific argument index.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

InvocationMatcher

public InvocationMatcher(MockMethod mockMethod)
Constructor.

Parameters:
mockMethod - A method to be matched.

InvocationMatcher

public InvocationMatcher(MockMethod mockMethod,
                         IMockObject mockObject)

InvocationMatcher

public InvocationMatcher(MockMethod mockMethod,
                         java.lang.Object[] expectedArgs)
Constructor.

Parameters:
mockMethod - A method to be matched.
expectedArgs - The arguments that are expected to be passed to the method.

InvocationMatcher

public InvocationMatcher(MockMethod mockMethod,
                         IMockObject mockObject,
                         java.lang.Object[] expectedArgs)
Constructor.

Parameters:
mockMethod - A method to be matched.
mockObject - The object on which the method is invoked.
expectedArgs - The arguments that are expected to be passed to the method.
Method Detail

isMatch

public boolean isMatch(MethodInvocation methodInvocation)
Verifies that the actual arguments passed to a method are as expected (i.e. as specified in the constructor of this class).

Parameters:
methodInvocation - The method invocation of interest.
Returns:
true if the methodInvocation matches the expectation; else false.

setArgumentMatcher

public InvocationMatcher setArgumentMatcher(int argIndex,
                                            IArgumentMatcher argMatcher)
A method to set an argument matcher for a specific argument index.

Parameters:
argIndex - The argument index of interest.
argMatcher - The matcher to use for the specified index.

ignoreArgument

public InvocationMatcher ignoreArgument(int argIndex)
A method to specify that we must ignore a particular argument when verifying whether expected and actual arguments are equal.

Parameters:
argIndex - The argument index to ignore.

getMethod

public MockMethod getMethod()
A method to determine the method that is being validated.

Returns:
The method that we expect to be invoked.