|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectorg.apache.aries.unittest.mocks.Skeleton
public final class Skeleton
The Skeleton class is an implementation of the
java.lang.reflect.InvocationHandler
that can be used for
dynamic mock objects.
Method Summary | ||
---|---|---|
void |
assertCalled(List<MethodCall> calls,
boolean allCalls)
This method checks that the MethodCalls objects in the given list were made and throws an AssertionFailedError if they were not. |
|
void |
assertCalled(MethodCall call)
This does the same as checkCall, but throws an junit.framework.AssertionFailedError if the call did not occur. |
|
void |
assertCalledExactNumberOfTimes(MethodCall call,
int numberOfCalls)
This method asserts that the method specified in the call parameter has been called the number of times specified by numberOfCalls. |
|
void |
assertNotCalled(MethodCall call)
This method throws an junit.framework.AssertionFailedError if the specified call was invoked on the skeleton. |
|
void |
assertSkeletonNotCalled()
This method throws an junit.framework.AssertionFailedError if the skeleton has had any methods invoked on it. |
|
boolean |
checkCall(MethodCall call)
Checks that the specified method has been called on this skeleton |
|
boolean |
checkCalls(List<MethodCall> calls,
boolean allCalls)
This method checks that the calls in the list occurred. |
|
void |
clearMethodCalls()
This method clears the method calls list for the skeleton |
|
Object |
createMock(Class<?>... interfaceClasses)
Creates a new Mock using this skeleton backing it. |
|
|
createMock(Class<T> interfaceClass)
Creates a new Mock using this skeleton backing it. |
|
void |
deRegisterMethodCallHandler(MethodCall call)
This method removes a registered MethodCallHandler for the specified MethodCall. |
|
void |
deRegisterReturnTypeHandler(Class<?> clazz)
This method removes a registration for a ReturnTypeHandler for the specified class. |
|
Object |
getParameter(String key)
This method allows a parameter to be retrieved. |
|
static Skeleton |
getSkeleton(Object mock)
This method returns the Skeleton backing the supplied mock object. |
|
Object |
getTemplateObject()
|
|
Object |
invoke(Object targetObject,
Method calledMethod,
Object[] arguments)
This method is invoked by the mock objects. |
|
Object |
invokeReturnTypeHandlers(Class<?> type)
This method invokes the return type proxy for the specified class. |
|
static boolean |
isSkeleton(Object mock)
This method returns true if and only the provided object is backed by a Skeleton. |
|
static Object |
newMock(Class<?>... interfaceClazzes)
This method returns a completely new mock object backed by a new skeleton object. |
|
static
|
newMock(Class<T> interfaceClazz)
This method returns a completely new mock object backed by a new skeleton object. |
|
static
|
newMock(Object template,
Class<T> interfaceClazz)
It is often the case that only a subset of methods on an interface are needed, but those methods that are needed are quite complex. |
|
void |
registerExceptionListener(Class<?> throwableType,
ExceptionListener listener)
This method registers an ExceptionListener when the specified Exception is thrown. |
|
void |
registerMethodCallHandler(MethodCall call,
MethodCallHandler handler)
This method registers a MethodCallHandler for the specified MethodCall. |
|
void |
registerReturnTypeHandler(Class<?> clazz,
ReturnTypeHandler handler)
This method registers a ReturnTypeHandler for the specified class. |
|
void |
reset()
This method resets the skeleton to the state it was in prior just after it was constructed. |
|
void |
setDefaultHandler(DefaultInvocationHandler defaultHandler)
|
|
void |
setParameter(String key,
Object value)
This method allows a parameter to be set. |
|
void |
setReturnValue(MethodCall call,
Object value)
This is a convenience method for registering a method call handler where a specific value should be returned when a method is called, rather than some logic needs to be applied. |
|
void |
setThrows(MethodCall call,
Error thingToThrow)
This is a convenience method for registering a method call handler where a specific exception should be thrown when the method is called, rather than some logic needs to be applied. |
|
void |
setThrows(MethodCall call,
Exception thingToThrow)
This is a convenience method for registering a method call handler where a specific exception should be thrown when the method is called, rather than some logic needs to be applied. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Method Detail |
---|
public static final Object newMock(Class<?>... interfaceClazzes)
new Skeleton().createMock(interfaceClazzes)
interfaceClazzes
- the classes the mock should implement
public static final <T> T newMock(Class<T> interfaceClazz)
new Skeleton().createMock(interfaceClazzes)
T
- The object type.interfaceClazz
- the classes the mock should implement
public static final <T> T newMock(Object template, Class<T> interfaceClazz)
T
- The object type.template
- The template object for the mockinterfaceClazz
- The interface to implement
public static final Skeleton getSkeleton(Object mock) throws IllegalArgumentException
mock
- the mock object
IllegalArgumentException
- thrown if the object is not a mock.public static final boolean isSkeleton(Object mock)
mock
- the mock to test.
public Object invoke(Object targetObject, Method calledMethod, Object[] arguments) throws Throwable
invoke
in interface InvocationHandler
targetObject
- The mock object that was invoked.calledMethod
- The method that was called.arguments
- The arguments that were passed.
Throwable
- Any exception thrown.public void registerMethodCallHandler(MethodCall call, MethodCallHandler handler)
call
- The method that was called.handler
- The MethodCallHandler.public void deRegisterMethodCallHandler(MethodCall call)
call
- the specified MethodCallpublic void reset()
public void clearMethodCalls()
public void setReturnValue(MethodCall call, Object value)
call
- the method being called.value
- the value to be returned when that method is called.public void setThrows(MethodCall call, Exception thingToThrow)
call
- the method being calledthingToThrow
- the exception to throw.public void setThrows(MethodCall call, Error thingToThrow)
call
- the method being calledthingToThrow
- the exception to throw.public void registerReturnTypeHandler(Class<?> clazz, ReturnTypeHandler handler)
clazz
- The class to be handled.handler
- The ReturnTypeHandlerpublic void deRegisterReturnTypeHandler(Class<?> clazz)
clazz
- The class to deregister the handler for.public void registerExceptionListener(Class<?> throwableType, ExceptionListener listener)
throwableType
- The type of the Throwablelistener
- The listener.public void setParameter(String key, Object value)
key
- The keyvalue
- The valuepublic Object getParameter(String key)
key
- the key the parameter was set using
public Object getTemplateObject()
public void setDefaultHandler(DefaultInvocationHandler defaultHandler)
defaultHandler
- The defaultHandler to set.public boolean checkCalls(List<MethodCall> calls, boolean allCalls)
calls
- The expected calls listallCalls
- true if an exact match comparison should be performed
public boolean checkCall(MethodCall call)
call
- the call that should have been called.
public void assertCalled(List<MethodCall> calls, boolean allCalls) throws junit.framework.AssertionFailedError
calls
- the list of callsallCalls
- whether an exact match between the lists is required
junit.framework.AssertionFailedError
- if a failure has occurred.public void assertCalled(MethodCall call)
call
- the call that was expectedpublic void assertCalledExactNumberOfTimes(MethodCall call, int numberOfCalls)
call
- The call that was made.numberOfCalls
- The number of times the call should have been made.public void assertNotCalled(MethodCall call)
call
- the call to check.public void assertSkeletonNotCalled()
public Object createMock(Class<?>... interfaceClasses)
interfaceClasses
- an array of interface the mock should implement.
public <T> T createMock(Class<T> interfaceClass)
T
- The object typeinterfaceClass
- an array of interface the mock should implement.
public Object invokeReturnTypeHandlers(Class<?> type) throws Exception
type
- the type to be invoked.
Exception
- if an error occurs when invoking the return type handler.
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |