com.javaforge.tapestry.testng
Class Capturer<T>

java.lang.Object
  extended by com.javaforge.tapestry.testng.Capturer<T>
Type Parameters:
T - the type of object to capture
All Implemented Interfaces:
org.easymock.IArgumentMatcher

public final class Capturer<T>
extends java.lang.Object
implements org.easymock.IArgumentMatcher

An EasyMock 2.0 argument matcher that captures a method argument value. This allows an object created inside a test method to be interrogated after the method completes, even when the object is not a return value, but is merely passed as a parameter to a mock object.

Author:
Howard M. Lewis Ship

Constructor Summary
Capturer(java.lang.Class<T> matchType)
          Creates a new Capturer for the given type.
 
Method Summary
 void appendTo(java.lang.StringBuffer buffer)
           
static
<T> T
capture(Capturer<T> capturer)
          Useage (with static imports):
 T getCaptured()
          Returns the method argument value previously captured.
 boolean matches(java.lang.Object parameter)
           
static
<T> Capturer<T>
newCapturer(java.lang.Class<T> matchType)
          Factory method that invokes the normal constructor in a way that keeps Java Generics happy.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Capturer

public Capturer(java.lang.Class<T> matchType)
Creates a new Capturer for the given type. Because of Generics syntax, it is easier to use the static method.

Method Detail

newCapturer

public static <T> Capturer<T> newCapturer(java.lang.Class<T> matchType)
Factory method that invokes the normal constructor in a way that keeps Java Generics happy.


appendTo

public void appendTo(java.lang.StringBuffer buffer)
Specified by:
appendTo in interface org.easymock.IArgumentMatcher

matches

public boolean matches(java.lang.Object parameter)
Specified by:
matches in interface org.easymock.IArgumentMatcher

getCaptured

public T getCaptured()
Returns the method argument value previously captured.


capture

public static <T> T capture(Capturer<T> capturer)
Useage (with static imports):

Capturer<Type> c = newCapturer(Type.class);

mock.someMethod(capture(c));

. . .

c.getCaptured().getXXX()

The interrogation of the captured argument should occur after the test subject has invoked the method on the mock; the best time for this is typically after invoking TestBase.verify().

Remember that when you use an argument matcher for one argument of a method invocation, you must use argument matchers for all arguments of the method invocation.



Copyright © 2006 Howard M. Lewis Ship. All Rights Reserved.