Logo Search packages:      
Sourcecode: jmock2 version File versions  Download package

org::jmock::lib::script::ScriptedAction Class Reference

Inheritance diagram for org::jmock::lib::script::ScriptedAction:

org::jmock::api::Action org::jmock::api::Invokable

List of all members.

Detailed Description

An Action that executes a BeanShell script. This makes it easy to implement custom actions, especially those that call back to objects passed to the mocked method as parameters.

To use a scripted action in an expectation, statically import the perform method and call it within the will(...) clause of the expectation.

The script can refer to the parameters of the mocked method by the names $0 (the first parameter), $1, $2, etc, and to the mock object that has been invoked by the name $this. You can define other script variables by calling the action's where method.

For example:

 allowing (sheep).accept(with(a(Visitor.class))); 

is equivalent to:

 allowing (sheep).accept(with(a(Visitor.class))); 
     will(perform("$0.visitSheep(s)").where("s", sheep);


Definition at line 40 of file ScriptedAction.java.

Public Member Functions

void describeTo (Description description)
Object invoke (Invocation invocation) throws Throwable
 ScriptedAction (String expression)
ScriptedAction where (String name, Object value)

Static Public Member Functions

static ScriptedAction perform (String script)

Private Member Functions

void defineParameters (Interpreter interpreter, Invocation invocation) throws EvalError

Private Attributes

final Interpreter interpreter = new Interpreter()
final String script

The documentation for this class was generated from the following file:

Generated by  Doxygen 1.6.0   Back to index