org.apache.aries.unittest.mocks
Class MethodCall

java.lang.Object
  extended by org.apache.aries.unittest.mocks.MethodCall

public final class MethodCall
extends Object

This class represents a method call that has been or is expected to be made. It encapsulates the class that the call was made on, the method that was invoked and the arguments passed.


Constructor Summary
MethodCall(Class<?> clazz, String methodName, Object... arguments)
          This constructor allows a MethodCall to be created when the class can be located statically, rather than dynamically.
 
Method Summary
 boolean equals(Object obj)
          Returns true if and only if the two object represent the same call.
 Object[] getArguments()
          This method returns the arguments.
 String getClassName()
          Returns the name of the class the method was invoked or was defined on.
 Class<?>[] getInterfaces()
          This method returns the list of interfaces implemented by the class that was called.
 Object getInvokedObject()
          This method returns the invoked object.
 String getMethodName()
          Returns the name of the method that was (or will be) invoked.
 int hashCode()
          Returns the hashCode (obtained by returning the hashCode of the methodName).
static
<T> void
registerEqualsHelper(Class<T> type, Comparator<T> comparator)
          The native equals for an object may not provide the behaviour required by the tests.
static void removeEqualsHelper(Class<?> type)
          This method removes any registered comparator specified for the given type.
 String toString()
          Returns a string representation of the method call.
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Constructor Detail

MethodCall

public MethodCall(Class<?> clazz,
                  String methodName,
                  Object... arguments)
This constructor allows a MethodCall to be created when the class can be located statically, rather than dynamically.

Parameters:
clazz - The class.
methodName - The method name.
arguments - The arguments.
Method Detail

getArguments

public Object[] getArguments()
This method returns the arguments.

Returns:
The arguments.

getClassName

public String getClassName()
Returns the name of the class the method was invoked or was defined on.

Returns:
the classname.

getMethodName

public String getMethodName()
Returns the name of the method that was (or will be) invoked.

Returns:
the method name

equals

public boolean equals(Object obj)
Returns true if and only if the two object represent the same call.

Overrides:
equals in class Object
Parameters:
obj - The object to be compared.
Returns:
true if the specified object is the same as this.

hashCode

public int hashCode()
Returns the hashCode (obtained by returning the hashCode of the methodName).

Overrides:
hashCode in class Object
Returns:
The hashCode

toString

public String toString()
Returns a string representation of the method call.

Overrides:
toString in class Object
Returns:
string representation.

getInterfaces

public Class<?>[] getInterfaces()
This method returns the list of interfaces implemented by the class that was called.

Returns:
Returns the interfaces.

getInvokedObject

public Object getInvokedObject()
This method returns the invoked object.

Returns:
The object that was invoked or null if an expected call.

registerEqualsHelper

public static <T> void registerEqualsHelper(Class<T> type,
                                            Comparator<T> comparator)
The native equals for an object may not provide the behaviour required by the tests. As an example AtomicInteger does not define a .equals, but tests may wish to compare it being passed in a method call for equality. This method allows a Comparator to be specified for any type and the Comparator will be used to determine equality in place of the .equals method.

The Comparator must not throw exceptions, and must return 0 for equality or any other integer for inequality.

Type Parameters:
T - the type of the class and comparator.
Parameters:
type - the type of the class for which the comparator will be called.
comparator - the comparator to call.

removeEqualsHelper

public static void removeEqualsHelper(Class<?> type)
This method removes any registered comparator specified for the given type.

Parameters:
type - the type to remove the comparator from.


Copyright © 2009-2011 The Apache Software Foundation. All Rights Reserved.