com.hammingweight.hammock
Class MockMethod

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

public class MockMethod
extends java.lang.Object
implements IHammockExceptionErrors, IClassDefinitions

The MockMethod class models a method associated with a mock object (or another test double such as a spy or stub). The method is defined in some interface or class. Important attributes of the method are whether the method is abstract, how many arguments it takes, the return type, etc.

Since:
Hammock 1.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
 
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
MockMethod(java.lang.Class clazz, java.lang.String id, java.lang.Class[] argClasses, java.lang.Class[] throwableClasses, java.lang.Class retClass, boolean isAbstract)
          Constructor.
MockMethod(java.lang.String id, int numArgs, java.lang.Class retClass, boolean isAbstract)
          Constructor.
 
Method Summary
protected  java.lang.Class[] getArgumentClasses()
          Returns the classes of the method's arguments.
 java.lang.String getId()
          Gets the identifier for a method.
 java.lang.Class getMethodClass()
          Gets the Class associated with a method.
 int getNumberOfArguments()
          This method returns the number of arguments for the encapsulated method.
protected  java.lang.Class getReturnClass()
          Returns the Class of Object returned by this method.
protected  java.lang.Class[] getThrowableClasses()
          Returns the classes that the method throws.
 boolean isAbstract()
          Returns whether the method being modelled is an abstract method.
 void validateArguments(java.lang.Object[] args)
          This method checks that a list of arguments matches the signature of the method; i.e.
 void validateThrowable(java.lang.Throwable t)
          This method checks that an exception can be thrown by this method.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

MockMethod

public MockMethod(java.lang.String id,
                  int numArgs,
                  java.lang.Class retClass,
                  boolean isAbstract)
Constructor.

Parameters:
id - An identifier for the method.
numArgs - The number of arguments that the method takes.
retClass - The class of the value to be returned by the method (null if the method is void).
isAbstract - True if the method is abstract.

MockMethod

public MockMethod(java.lang.Class clazz,
                  java.lang.String id,
                  java.lang.Class[] argClasses,
                  java.lang.Class[] throwableClasses,
                  java.lang.Class retClass,
                  boolean isAbstract)
Constructor.

Parameters:
clazz - The class that the method belongs to.
id - An identifier for the method.
argClasses - The classes of the arguments of the method.
throwableClasses - The classes of the exceptions that the method might throw.
retClass - The class of the value to be returned by the method (null if the method is void).
isAbstract - True if the method is abstract.
Method Detail

getMethodClass

public java.lang.Class getMethodClass()
Gets the Class associated with a method.

Returns:
The Class that the method belongs to.

getId

public java.lang.String getId()
Gets the identifier for a method.

Returns:
The identifier for the method.

getArgumentClasses

protected java.lang.Class[] getArgumentClasses()
Returns the classes of the method's arguments.

Returns:
The classes of the method's arguments.

getThrowableClasses

protected java.lang.Class[] getThrowableClasses()
Returns the classes that the method throws.

Returns:
The classes that the method throws.

getReturnClass

protected java.lang.Class getReturnClass()
Returns the Class of Object returned by this method.

Returns:
The Class of Object returned by this method.

isAbstract

public boolean isAbstract()
Returns whether the method being modelled is an abstract method.

Returns:
true if the modelled method is abstract.

validateArguments

public void validateArguments(java.lang.Object[] args)
This method checks that a list of arguments matches the signature of the method; i.e. is the number of arguments correct and are the classes of the arguments in keeping with the method's signature.

Parameters:
args - A list of arguments.
Throws:
HammockException - if the arguments are inconsistent with the method's signature.

validateThrowable

public void validateThrowable(java.lang.Throwable t)
This method checks that an exception can be thrown by this method.

Parameters:
t - The exception or error to throw.
Throws:
HammockException - if the exception is inconsistent with the method's signature.
Since:
Hammock 2.0

getNumberOfArguments

public int getNumberOfArguments()
This method returns the number of arguments for the encapsulated method.

Returns:
The number of arguments.
Since:
Hammock 2.0