1.1 --- a/vm/src/test/java/org/apidesign/vm4brwsr/ArrayTest.java Mon Sep 24 11:07:38 2012 +0200
1.2 +++ b/vm/src/test/java/org/apidesign/vm4brwsr/ArrayTest.java Thu Oct 11 10:43:17 2012 -0700
1.3 @@ -21,6 +21,7 @@
1.4 import javax.script.ScriptException;
1.5 import org.testng.annotations.Test;
1.6 import static org.testng.Assert.*;
1.7 +import org.testng.annotations.BeforeClass;
1.8
1.9 /**
1.10 *
1.11 @@ -28,7 +29,7 @@
1.12 */
1.13 public class ArrayTest {
1.14 @Test public void verifySimpleIntOperation() throws Exception {
1.15 - assertExec("CheckTheSum", "org_apidesign_vm4brwsr_Array_simpleI",
1.16 + assertExec("CheckTheSum", "org_apidesign_vm4brwsr_Array_simpleI",
1.17 Double.valueOf(15)
1.18 );
1.19 }
1.20 @@ -38,19 +39,25 @@
1.21 );
1.22 }
1.23
1.24 - private static void assertExec(String msg, String methodName, Object expRes, Object... args) throws Exception {
1.25 + private static CharSequence codeSeq;
1.26 + private static Invocable code;
1.27 +
1.28 + @BeforeClass
1.29 + public void compileTheCode() throws Exception {
1.30 StringBuilder sb = new StringBuilder();
1.31 - Invocable i = StaticMethodTest.compileClass(sb,
1.32 + code = StaticMethodTest.compileClass(sb,
1.33 "org/apidesign/vm4brwsr/Array"
1.34 );
1.35 -
1.36 + codeSeq = sb;
1.37 + }
1.38 + private static void assertExec(String msg, String methodName, Object expRes, Object... args) throws Exception {
1.39 Object ret = null;
1.40 try {
1.41 - ret = i.invokeFunction(methodName, args);
1.42 + ret = code.invokeFunction(methodName, args);
1.43 } catch (ScriptException ex) {
1.44 - fail("Execution failed in " + sb, ex);
1.45 + fail("Execution failed in\n" + codeSeq, ex);
1.46 } catch (NoSuchMethodException ex) {
1.47 - fail("Cannot find method in " + sb, ex);
1.48 + fail("Cannot find method in\n" + codeSeq, ex);
1.49 }
1.50 if (ret == null && expRes == null) {
1.51 return;
1.52 @@ -58,6 +65,6 @@
1.53 if (expRes.equals(ret)) {
1.54 return;
1.55 }
1.56 - assertEquals(ret, expRes, msg + "was: " + ret + "\n" + sb);
1.57 + assertEquals(ret, expRes, msg + "was: " + ret + "\n" + codeSeq);
1.58 }
1.59 }