1.1 --- a/vm/src/test/java/org/apidesign/vm4brwsr/StaticMethodTest.java Thu Oct 11 04:11:42 2012 -0700
1.2 +++ b/vm/src/test/java/org/apidesign/vm4brwsr/StaticMethodTest.java Thu Oct 11 10:43:17 2012 -0700
1.3 @@ -23,6 +23,7 @@
1.4 import javax.script.ScriptEngineManager;
1.5 import javax.script.ScriptException;
1.6 import static org.testng.Assert.*;
1.7 +import org.testng.annotations.BeforeClass;
1.8 import org.testng.annotations.Test;
1.9
1.10 /** Checks the basic behavior of the translator.
1.11 @@ -193,17 +194,27 @@
1.12 );
1.13 }
1.14
1.15 + private static CharSequence codeSeq;
1.16 + private static Invocable code;
1.17 +
1.18 + @BeforeClass
1.19 + public void compileTheCode() throws Exception {
1.20 + StringBuilder sb = new StringBuilder();
1.21 + code = compileClass(sb, "org/apidesign/vm4brwsr/StaticMethod");
1.22 + codeSeq = sb;
1.23 + }
1.24 +
1.25 +
1.26 private static void assertExec(String msg, String methodName, Object expRes, Object... args) throws Exception {
1.27 StringBuilder sb = new StringBuilder();
1.28 - Invocable i = compileClass(sb, "org/apidesign/vm4brwsr/StaticMethod");
1.29
1.30 Object ret = null;
1.31 try {
1.32 - ret = i.invokeFunction(methodName, args);
1.33 + ret = code.invokeFunction(methodName, args);
1.34 } catch (ScriptException ex) {
1.35 - fail("Execution failed in " + sb, ex);
1.36 + fail("Execution failed in\n" + codeSeq, ex);
1.37 } catch (NoSuchMethodException ex) {
1.38 - fail("Cannot find method in " + sb, ex);
1.39 + fail("Cannot find method in\n" + codeSeq, ex);
1.40 }
1.41 if (ret == null && expRes == null) {
1.42 return;
1.43 @@ -211,7 +222,7 @@
1.44 if (expRes != null && expRes.equals(ret)) {
1.45 return;
1.46 }
1.47 - assertEquals(ret, expRes, msg + "was: " + ret + "\n" + sb);
1.48 + assertEquals(ret, expRes, msg + "was: " + ret + "\n" + codeSeq);
1.49
1.50 }
1.51