com.google.testing.threadtester
Class Script<T>

java.lang.Object
  extended by com.google.testing.threadtester.Script<T>
Type Parameters:
T - the type of the object-under-test.

public class Script<T>
extends Object

A Script represents a sequence of operations carried out on an object-under-test. Several different Scripts can be created, and combined together by a Scripter. Each Script will run in a separate thread, and will have the option of yielding control to other Scripts using the releaseTo(com.google.testing.threadtester.Script) method. This allows a series of operations to be co-ordinated across multiple threads.

Author:
alasdair.mackintosh@gmail.com (Alasdair Mackintosh)

Constructor Summary
Script(Script<T> other)
          Creates a new Script that will operate on the same object-under-test as another Script.
Script(T object)
          Creates a new Script that will operate on the given object-under-test.
 
Method Summary
 void addTask(ScriptedTask<T> task)
          Adds a task to this Script.
 Script<T> afterCalling(Object result)
           
 Script<T> afterCallingLastMethod()
           
 Script<T> atEndOf(Object result)
           
 Script<T> atEndOfLastMethod()
           
 Script<T> atStartOf(Object result)
           
 Script<T> atStartOfLastMethod()
           
 Script<T> beforeCalling(Object result)
           
 Script<T> beforeCallingLastMethod()
           
<T> T
createTarget(Class<T> clss)
           
 Script<T> in(Object result)
           
 Script<T> inLastMethod()
           
 T object()
          Returns a control object that can be used to define release points in the object-under-test.
 void releaseTo(Script<T> other)
          Declares an intent to release control to another thread in the future, or performs the actual release now.
 String toString()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

Script

public Script(T object)
Creates a new Script that will operate on the given object-under-test. The tasks added to this script will normally invoke methods on this object. Note that the object's class must be instrumented.


Script

public Script(Script<T> other)
Creates a new Script that will operate on the same object-under-test as another Script. This is normally used to create secondary scripts.

See Also:
Scripter.Scripter(Script, Script)
Method Detail

object

public T object()
Returns a control object that can be used to define release points in the object-under-test. This is a dummy object, of the same type as the object-under-test, but whose methods do nothing.


createTarget

public <T> T createTarget(Class<T> clss)

addTask

public void addTask(ScriptedTask<T> task)
Adds a task to this Script. Tasks will be executed when Scripter.execute() is called. Note that this method should not be invoked after Scripter.execute() has been called.


releaseTo

public void releaseTo(Script<T> other)
Declares an intent to release control to another thread in the future, or performs the actual release now. The behaviour depends on whether a method has been invoked on the control object. (See object().) If it has, then the release is scheduled when the position represented by the control call has been reached, and the state of the control object is cleared. Otherwise, the release is performed immediately.

Releasing control will block this script, and allow the released script to start, or to resume execution. This script will remain blocked until another script releases control back to it, or until the first Script belonging to the Scripter is released.

Note that it is only possible to release to another Script that is being run by the same Scripter.


toString

public String toString()
Overrides:
toString in class Object

afterCalling

public Script<T> afterCalling(Object result)

afterCallingLastMethod

public Script<T> afterCallingLastMethod()

atEndOf

public Script<T> atEndOf(Object result)

atEndOfLastMethod

public Script<T> atEndOfLastMethod()

atStartOf

public Script<T> atStartOf(Object result)

atStartOfLastMethod

public Script<T> atStartOfLastMethod()

beforeCalling

public Script<T> beforeCalling(Object result)

beforeCallingLastMethod

public Script<T> beforeCallingLastMethod()

inLastMethod

public Script<T> inLastMethod()

in

public Script<T> in(Object result)


Copyright © 2013. All Rights Reserved.