com.hammingweight.hammock
Class InvocationVerifier

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

public class InvocationVerifier
extends java.lang.Object
implements IHammockExceptionErrors

The InvocationVerifier class is a helper class for verifying that methods were invoked as expected; in particular it is used with spy objects.

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
InvocationVerifier(InvocationMatcher matcher, MethodInvocation[] methodInvocations)
          Constructor.
 
Method Summary
 int getInvocationCount()
           
 InvocationVerifier ignoreArgument(int argIndex)
          Ignores a particular argument when checking whether a method was invoked with the expected arguments.
 boolean isVerified()
          A method to check whether an expected method was invoked an expected number of times.
 InvocationVerifier setArgumentMatcher(int argIndex, IArgumentMatcher argMatcher)
          Sets the IArgumentMatcher to use for matching method invocations.
 InvocationVerifier setInvocationCount(int numInvocations)
          A method to set the number of times that the expected method should have been called.
 InvocationVerifier setInvocationCount(int minNumInvocations, int maxNumInvocations)
          A method to set the number of times that the expected method should have been called.
 void verify()
          A method to check whether an expected method was invoked an expected number of times.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

InvocationVerifier

public InvocationVerifier(InvocationMatcher matcher,
                          MethodInvocation[] methodInvocations)
Constructor.

Parameters:
matcher - The MethodInvocationMatcher to match actual invocations against expected invocations.
methodInvocations - The methods invoked on a test double.
Method Detail

isVerified

public boolean isVerified()
A method to check whether an expected method was invoked an expected number of times. Unless setInvocationCount has been called, this method will verify that the expected method has been invoked at least once.

Returns:
true if an expected method was invoked, an expected number of times.

verify

public void verify()
A method to check whether an expected method was invoked an expected number of times. Unless setInvocationCount has been called, this method will verify that the expected method has been invoked at least once.

Throws:
HammockException - if the method wasn't invoked as expected.

setInvocationCount

public InvocationVerifier setInvocationCount(int numInvocations)
A method to set the number of times that the expected method should have been called.

Parameters:
numInvocations - The exact number of times that the method should have been invoked.
Returns:
this.

setInvocationCount

public InvocationVerifier setInvocationCount(int minNumInvocations,
                                             int maxNumInvocations)
A method to set the number of times that the expected method should have been called.

Parameters:
minNumInvocations - The minimum allowed number of invocations.
maxNumInvocations - The maximum allowed number of invocations.
Returns:
this.

setArgumentMatcher

public InvocationVerifier setArgumentMatcher(int argIndex,
                                             IArgumentMatcher argMatcher)
Sets the IArgumentMatcher to use for matching method invocations.

Parameters:
argIndex - The index of the method argument.
argMatcher - The matcher to use.
Returns:
this.

ignoreArgument

public InvocationVerifier ignoreArgument(int argIndex)
Ignores a particular argument when checking whether a method was invoked with the expected arguments.

Parameters:
argIndex - The argument index to ignore.
Returns:
this.

getInvocationCount

public int getInvocationCount()
Returns:
The number of times that the expected method was invoked.