vm/src/test/java/org/apidesign/vm4brwsr/InstanceTest.java
changeset 103 e8438996d406
parent 102 2354255a1844
child 106 346633cd13d6
     1.1 --- a/vm/src/test/java/org/apidesign/vm4brwsr/InstanceTest.java	Thu Oct 11 10:03:21 2012 -0700
     1.2 +++ b/vm/src/test/java/org/apidesign/vm4brwsr/InstanceTest.java	Thu Oct 11 10:43:17 2012 -0700
     1.3 @@ -21,6 +21,8 @@
     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 +import org.testng.annotations.BeforeTest;
     1.9  
    1.10  /**
    1.11   *
    1.12 @@ -113,19 +115,29 @@
    1.13          return "org/apidesign/vm4brwsr/Instance";
    1.14      }
    1.15      
    1.16 +    private static CharSequence codeSeq;
    1.17 +    private static Invocable code;
    1.18 +    
    1.19 +    @BeforeTest 
    1.20 +    public void compileTheCode() throws Exception {
    1.21 +        if (codeSeq == null) {
    1.22 +            StringBuilder sb = new StringBuilder();
    1.23 +            code = StaticMethodTest.compileClass(sb, startCompilationWith());
    1.24 +            codeSeq = sb;
    1.25 +        }
    1.26 +    }
    1.27 +    
    1.28      private void assertExec(
    1.29          String msg, String methodName, Object expRes, Object... args
    1.30      ) throws Exception {
    1.31 -        StringBuilder sb = new StringBuilder();
    1.32 -        Invocable i = StaticMethodTest.compileClass(sb, startCompilationWith());
    1.33 -        
    1.34 +
    1.35          Object ret = null;
    1.36          try {
    1.37 -            ret = i.invokeFunction(methodName, args);
    1.38 +            ret = code.invokeFunction(methodName, args);
    1.39          } catch (ScriptException ex) {
    1.40 -            fail("Execution failed in " + sb, ex);
    1.41 +            fail("Execution failed in\n" + codeSeq, ex);
    1.42          } catch (NoSuchMethodException ex) {
    1.43 -            fail("Cannot find method in " + sb, ex);
    1.44 +            fail("Cannot find method in\n" + codeSeq, ex);
    1.45          }
    1.46          if (ret == null && expRes == null) {
    1.47              return;
    1.48 @@ -133,7 +145,7 @@
    1.49          if (expRes.equals(ret)) {
    1.50              return;
    1.51          }
    1.52 -        assertEquals(ret, expRes, msg + "was: " + ret + "\n" + sb);
    1.53 +        assertEquals(ret, expRes, msg + "was: " + ret + "\n" + codeSeq);
    1.54          
    1.55      }
    1.56