net.grinder.testutility
Class AbstractStubFactory<T>

java.lang.Object
  extended by junit.framework.Assert
      extended by net.grinder.testutility.CallRecorder
          extended by net.grinder.testutility.AbstractStubFactory<T>
Type Parameters:
T - Stub type.
All Implemented Interfaces:
CallAssertions
Direct Known Subclasses:
DelegatingStubFactory, RandomStubFactory

public abstract class AbstractStubFactory<T>
extends CallRecorder

Dynamic proxy based test utility class that records details of invocations and allows a controlling unit test to later enquire about which invocations occurred and in what order. Because it is based on java.lang.reflect.Proxy it can only intercept invocations which are defined by interfaces.

Author:
Philip Aston

Nested Class Summary
 
Nested classes/interfaces inherited from class net.grinder.testutility.CallRecorder
CallRecorder.MethodFilter
 
Constructor Summary
AbstractStubFactory(Class<T> stubbedInterface, InvocationHandler invocationHandler)
           
 
Method Summary
static Class<?>[] getAllInterfaces(Class<?> c)
           
protected static
<K> Class<K>
getClass(K o)
          Localise need for unchecked cast.
static AbstractStubFactory<?> getFactory(Object stub)
          Return the cached AbstractStubFactory for stub.
 T getStub()
           
 void setResult(String methodName, Object result)
           
 void setThrows(String methodName, Throwable result)
           
 
Methods inherited from class net.grinder.testutility.CallRecorder
assertException, assertException, assertException, assertException, assertNoMoreCalls, assertSuccess, assertSuccess, getCallHistory, peekFirst, record, resetCallHistory, setIgnoreCallOrder, setIgnoreMethod, setIgnoreObjectMethods, waitUntilCalled
 
Methods inherited from class junit.framework.Assert
assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertFalse, assertFalse, assertNotNull, assertNotNull, assertNotSame, assertNotSame, assertNull, assertNull, assertSame, assertSame, assertTrue, assertTrue, fail, fail, failNotEquals, failNotSame, failSame, format
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

AbstractStubFactory

public AbstractStubFactory(Class<T> stubbedInterface,
                           InvocationHandler invocationHandler)
Method Detail

getStub

public final T getStub()

setResult

public final void setResult(String methodName,
                            Object result)

setThrows

public final void setThrows(String methodName,
                            Throwable result)

getAllInterfaces

public static Class<?>[] getAllInterfaces(Class<?> c)

getFactory

public static AbstractStubFactory<?> getFactory(Object stub)
Return the cached AbstractStubFactory for stub.

Returns:
The factory, or null.

getClass

protected static <K> Class<K> getClass(K o)
Localise need for unchecked cast. I thought the compiler was meant to regarding Object.getClass() - seems the Eclipse compiler (at least) is not.

Type Parameters:
K - Parameter type.
Parameters:
o - Parameter.
Returns:
Parameter's class.


Copyright © 2000-2012. All Rights Reserved.