|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectcom.google.testing.threadtester.MethodRecorder<T>
T - the type for which we want to create positions.public class MethodRecorder<T>
Provides a mechanism for creating CodePositions for a given
object-under-test, using direct method calls. Sample useage is as follows:
ClassUnderTest object = new ClassUnderTest(); MethodRecorderCallingrecorder = new MethodRecorder (object) ClassUnderTest control = recorder.getControl(); // Create a CodePosition corresponding to the start // of the call to 'aMethod' in the test object. CodePosition cp = recorder.atStart(control.aMethod()).position();
getControl() returns a dummy object that is of the same class as
the object-under-test. Methods invoked on the control object have no effect,
but the method calls are noted by the MethodRecorder, and can then be used to
create CodePositions. If the methods invoked require arguments, any argument
(including null) may be passed in.
A CodePosition can also be created relative to an internal method call. Given the following implementation:
public ClassUnderTest {
public int aMethod() {
int value = getValue();
System.out.printf("Value = %d", value);
return value;
}
A CodePosition in the method aMethod, immediately after the
call to printf, could be created as follows:
ClassUnderTest control = recorder.getControl();
PrintStream stream = recorder.createTarget(PrintStream.class);
CodePosition cp =
recorder.in(control.aMethod()).afterCalling(stream.printf("")).position();
Again, the target object is a dummy instance, and any argument may be passed
in to the method calls.
The above examples can only be used when the method in question returns a value. If it does not, then the "LastMethod" variations must be used. Given the following class:
public ClassUnderTest {
public void voidMethod() {
System.out.println("in void method");
}
A CodePosition in the method voidMethod, immediately after the
call to println, could be created as follows:
ClassUnderTest control = recorder.getControl();
PrintStream stream = recorder.createTarget(PrintStream.class);
control.voidMethod();
recorder.inLastMethod();
stream.println("");
recorder.afterCallingLastMethod();
CodePosition cp = recorder.position();
| Constructor Summary | |
|---|---|
MethodRecorder(Class<T> clss)
Creates a new MethodRecorder for the given class. |
|
MethodRecorder(T object)
Creates a new MethodRecorder for the given object. |
|
| Method Summary | ||
|---|---|---|
MethodRecorder<T> |
afterCalling(Object result)
Sets the state of the recorder to represent a position after a call to the last method invoked on the target object. |
|
MethodRecorder<T> |
afterCallingLastMethod()
Sets the state of the recorder to represent a position after a call to the last method invoked on the target object. |
|
MethodRecorder<T> |
atEndOf(Object result)
Sets the state of the recorder to represent a position at the end of the last method invoked on the control object. |
|
MethodRecorder<T> |
atEndOfLastMethod()
Sets the state of the recorder to represent a position at the end of the last method invoked on the control object. |
|
MethodRecorder<T> |
atStartOf(Object result)
Sets the state of the recorder to represent a position at the beginning of the last method invoked on the control object. |
|
MethodRecorder<T> |
atStartOfLastMethod()
Sets the state of the recorder to represent a position at the beginning of the last method invoked on the control object. |
|
MethodRecorder<T> |
beforeCalling(Object result)
Sets the state of the recorder to represent a position before a call to the last method invoked on the target object. |
|
MethodRecorder<T> |
beforeCallingLastMethod()
Sets the state of the recorder to represent a position before a call to the last method invoked on the target object. |
|
Breakpoint |
breakpoint(Thread thread)
Creates a Breakpoint for the current CodePosition in the given thread. |
|
|
createTarget(Class<T> clss)
Creates a target object of the given class. |
|
T |
getControl()
Gets the control object. |
|
MethodRecorder<T> |
in(Object result)
Sets the state of the recorder to represent a position within the last method invoked on the control object. |
|
MethodRecorder<T> |
inLastMethod()
Sets the state of the recorder to represent a position within the last method invoked on the control object. |
|
CodePosition |
position()
Creates a new CodePosition corresponding to the last methods called on the control object, and optionally on a target object. |
|
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Constructor Detail |
|---|
public MethodRecorder(T object)
Instrumentationpublic MethodRecorder(Class<T> clss)
Instrumentation| Method Detail |
|---|
public T getControl()
CodePositions.
public <T> T createTarget(Class<T> clss)
public MethodRecorder<T> in(Object result)
beforeCalling(java.lang.Object) or afterCalling(java.lang.Object) before calling position.
getControl()public MethodRecorder<T> inLastMethod()
in(java.lang.Object)public MethodRecorder<T> atStartOf(Object result)
public MethodRecorder<T> atStartOfLastMethod()
public MethodRecorder<T> atEndOf(Object result)
public MethodRecorder<T> atEndOfLastMethod()
public MethodRecorder<T> beforeCalling(Object result)
in(java.lang.Object) before
calling this method.
public MethodRecorder<T> beforeCallingLastMethod()
beforeCalling(java.lang.Object)public MethodRecorder<T> afterCalling(Object result)
in(java.lang.Object) before
calling this method.
public MethodRecorder<T> afterCallingLastMethod()
afterCalling(java.lang.Object)public CodePosition position()
IllegalStateException - if control and target methods have not been
called.getControl(),
createTarget(java.lang.Class) public Breakpoint breakpoint(Thread thread)
MethodRecorder(Class)
position
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||