Files
allwpilib/networktables/java/lib/jmock/jmock-script-2.6.0-RC2.jar

158 lines
6.8 KiB
Plaintext
Raw Normal View History

PK
<00><><EFBFBD>< META-INF/<2F><>PK
<00><><EFBFBD><:<3A><>WffMETA-INF/MANIFEST.MFManifest-Version: 1.0
Ant-Version: Apache Ant 1.7.0
Created-By: 14.2-b01 (Sun Microsystems Inc.)
PK
<00><><EFBFBD><org/PK
<00><><EFBFBD><
org/jmock/PK
<00><><EFBFBD><org/jmock/lib/PK
<00><><EFBFBD><org/jmock/lib/script/PK
<00><><EFBFBD><<18>{3
3
)org/jmock/lib/script/ScriptedAction.class<73><73><EFBFBD><EFBFBD>1<00>
GH
G I J
K
L
MN
OPQR
ST
UV
W
UXY
GZ
[
\
]
U^_ `ab
cdef interpreterLbsh/Interpreter;scriptLjava/lang/String;<init>(Ljava/lang/String;)VCodeLineNumberTableLocalVariableTablethis%Lorg/jmock/lib/script/ScriptedAction;
expressioninvoke.(Lorg/jmock/api/Invocation;)Ljava/lang/Object;eLbsh/TargetError;Lbsh/EvalError;
invocationLorg/jmock/api/Invocation;
ExceptionsgdefineParameters.(Lbsh/Interpreter;Lorg/jmock/api/Invocation;)ViI
describeTo(Lorg/hamcrest/Description;)V descriptionLorg/hamcrest/Description;perform9(Ljava/lang/String;)Lorg/jmock/lib/script/ScriptedAction;whereK(Ljava/lang/String;Ljava/lang/Object;)Lorg/jmock/lib/script/ScriptedAction;namevalueLjava/lang/Object;
SourceFileScriptedAction.java %hbsh/Interpreter !" #$ ij 67 klbsh/TargetError mn bsh/EvalError"java/lang/IllegalArgumentExceptioncould not interpret script %o$thisp qr st uvjava/lang/StringBuilder$ wx wy z{ |}perform ~ <00>#org/jmock/lib/script/ScriptedAction %&invalid name bindingjava/lang/Objectorg/jmock/api/Actionjava/lang/Throwable()V setStrictJava(Z)Veval&(Ljava/lang/String;)Ljava/lang/Object; getTarget()Ljava/lang/Throwable;*(Ljava/lang/String;Ljava/lang/Throwable;)Vorg/jmock/api/InvocationgetInvokedObject()Ljava/lang/Object;set'(Ljava/lang/String;Ljava/lang/Object;)VgetParameterCount()Iappend-(Ljava/lang/String;)Ljava/lang/StringBuilder;(I)Ljava/lang/StringBuilder;toString()Ljava/lang/String; getParameter(I)Ljava/lang/Object;org/hamcrest/Description
appendText.(Ljava/lang/String;)Lorg/hamcrest/Description;! !"#$%&'a*<2A>*<2A>Y<><03>*+<2B>*<2A><04><06>(,)-./)*+,$-.'<00>'**<2A>+<2B>*<2A>*<2A><05><08>M,<2C>
<EFBFBD>M<EFBFBD> Y ,<2C><0E>  (3 4679:)*/0 /1'*+'234567'<00>7+,<2C><10>>,<2C><12>%+<2B>Y<><15><1D><17>,<1D><19><11><01><>ٱ(A
BC0B6E)* *897*+7!"7234 :;'K+<1A>*<2A><05>W<>(
HI)*+<= >?'3 <09>Y*<2A><1D>(T)  #$@A'z*<2A>+,<2C><11>N<> Y-<2D><0E>*<2A> (c g e fh)* /1*+B$CDEFPK
<00>h<EFBFBD>8m<38>_L<5F> <00> (org/jmock/lib/script/ScriptedAction.javapackage org.jmock.lib.script;
import org.hamcrest.Description;
import org.jmock.api.Action;
import org.jmock.api.Invocation;
import bsh.EvalError;
import bsh.Interpreter;
import bsh.TargetError;
/**
* <p>An {@link Action} that executes a <a href="http://www.beanshell.org">BeanShell</a> script.
* This makes it easy to implement custom actions, especially those that call back to objects
* passed to the mocked method as parameters.</p>
*
* <p>To use a scripted action in an expectation, statically import the {@link #perform(String) perform}
* method and call it within the <code>will(...)</code> clause of the expectation.</p>
*
* <p>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 {@link #where(String, Object) where} method.</p>
*
* <p>For example:</p>
* <pre>
* allowing (sheep).accept(with(a(Visitor.class)));
* will(perform("$0.visitSheep($this)");
* </pre>
*
* <p>is equivalent to:</p>
*
* <pre>
* allowing (sheep).accept(with(a(Visitor.class)));
* will(perform("$0.visitSheep(s)").where("s", sheep);
* </pre>
*
*
* @author nat
*
*/
public class ScriptedAction implements Action {
private final Interpreter interpreter = new Interpreter();
private final String script;
public ScriptedAction(String expression) {
this.script = expression;
this.interpreter.setStrictJava(true);
}
public Object invoke(Invocation invocation) throws Throwable {
try {
defineParameters(interpreter, invocation);
return interpreter.eval(script);
}
catch (TargetError e) {
throw e.getTarget();
}
catch (EvalError e) {
throw new IllegalArgumentException("could not interpret script", e);
}
}
private void defineParameters(Interpreter interpreter, Invocation invocation)
throws EvalError
{
interpreter.set("$this", invocation.getInvokedObject());
for (int i = 0; i < invocation.getParameterCount(); i++) {
interpreter.set("$" + i, invocation.getParameter(i));
}
}
public void describeTo(Description description) {
description.appendText("perform ").appendText(script);
}
/**
* Creates an action that performs the given script.
*
* @param script
* a BeanShell script.
* @return
* the new action.
*/
public static ScriptedAction perform(String script) {
return new ScriptedAction(script);
}
/**
* Defines a variable that can be referred to by the script.
*
* @param name
* the name of the variable
* @param value
* the value of the variable
* @return
* the action, so that more variables can be defined if needed
*/
public ScriptedAction where(String name, Object value) {
try {
interpreter.set(name, value);
}
catch (EvalError e) {
throw new IllegalArgumentException("invalid name binding", e);
}
return this;
}
}
PK
<00><><EFBFBD>< <00>AMETA-INF/<2F><>PK
<00><><EFBFBD><:<3A><>Wff<00><>+META-INF/MANIFEST.MFPK
<00><><EFBFBD><<00>A<EFBFBD>org/PK
<00><><EFBFBD><
<00>A<EFBFBD>org/jmock/PK
<00><><EFBFBD><<00>A org/jmock/lib/PK
<00><><EFBFBD><<00>A9org/jmock/lib/script/PK
<00><><EFBFBD><<18>{3
3
)<00><>lorg/jmock/lib/script/ScriptedAction.classPK
<00>h<EFBFBD>8m<38>_L<5F> <00> (<00><><EFBFBD> org/jmock/lib/script/ScriptedAction.javaPK<00>