|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectorg.progeeks.junit.TestInvocationHandler
public class TestInvocationHandler
A proxy invocation handler for testing that can serve as any interface and records the interface's last method invocations and its parameters. Mostly intended to be used for quickly generating listeners to test classes that fire off events. The handler supports configurable objects to return based on the name of the method that was invoked.
Nested Class Summary | |
---|---|
protected static class |
TestInvocationHandler.TestException
Class used to denote a specific method invocation should generate an exception rather than return a result. |
Constructor Summary | |
---|---|
TestInvocationHandler()
|
Method Summary | |
---|---|
static java.lang.Object |
createProxy(java.lang.Class interfaceClass)
Convenience method that creates a test proxy class with a new generic test proxy as the invocation handler. |
static java.lang.Object |
createProxy(java.lang.Class interfaceClass,
TestInvocationHandler testProxy)
Creates a test proxy class using the supplied generic test proxy as the invocation handler. |
static TestInvocationHandler |
getInvocationHandler(java.lang.Object object)
Convenience method that returns the invocation handler for the test proxy. |
java.lang.Object |
getLastArg(int index)
Convenience method for returning a given argument for the last method invoked. |
java.lang.Object[] |
getLastArgs()
Returns an array of the arguments for the last method invoked or an empty array if no method has been invoked. |
java.lang.reflect.Method |
getLastMethod()
Returns the last method invoked. |
java.lang.String |
getLastMethodName()
Convenience method that returns the name of the last method invoked or null if no method has been invoked. |
java.lang.Object |
getLastProxy()
Returns the last proxy object that had a method invoked. |
java.lang.Object |
invoke(java.lang.Object proxy,
java.lang.reflect.Method method,
java.lang.Object[] args)
Invocation handler method invoked when a call is made on the test proxy. |
boolean |
invoked()
Returns true if a method has been invoked on the proxy. |
boolean |
invoked(java.lang.String methodName)
Returns true if the method with the given method name was invoked. |
void |
reset()
Resets the proxy's last method details to the state where no method is considered to have been invoked. |
void |
setReturnException(java.lang.String methodName,
java.lang.Throwable throwable)
Sets the exception to generate for the given method's invocation. |
void |
setReturnResult(java.lang.String methodName,
java.lang.Object result)
Sets the result object to return for a given method's invocation. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
public TestInvocationHandler()
Method Detail |
---|
public static java.lang.Object createProxy(java.lang.Class interfaceClass, TestInvocationHandler testProxy)
public static java.lang.Object createProxy(java.lang.Class interfaceClass)
public static TestInvocationHandler getInvocationHandler(java.lang.Object object)
public java.lang.Object invoke(java.lang.Object proxy, java.lang.reflect.Method method, java.lang.Object[] args) throws java.lang.Throwable
invoke
in interface java.lang.reflect.InvocationHandler
java.lang.Throwable
public boolean invoked()
public boolean invoked(java.lang.String methodName)
public java.lang.Object getLastProxy()
public java.lang.reflect.Method getLastMethod()
public java.lang.String getLastMethodName()
public java.lang.Object[] getLastArgs()
public java.lang.Object getLastArg(int index)
public void reset()
public void setReturnResult(java.lang.String methodName, java.lang.Object result)
public void setReturnException(java.lang.String methodName, java.lang.Throwable throwable)
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |