vm/src/test/java/org/apidesign/vm4brwsr/StringTest.java
changeset 103 e8438996d406
parent 94 19497b4312bb
child 104 1376481f15e7
     1.1 --- a/vm/src/test/java/org/apidesign/vm4brwsr/StringTest.java	Tue Oct 09 11:11:58 2012 -0700
     1.2 +++ b/vm/src/test/java/org/apidesign/vm4brwsr/StringTest.java	Thu Oct 11 10:43:17 2012 -0700
     1.3 @@ -4,6 +4,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 @@ -36,21 +37,27 @@
    1.12      @Test public void toStringConcatenationJava() throws Exception {
    1.13          assertEquals("Hello World!5", StringSample.toStringTest(5));
    1.14      }
    1.15 +    private static CharSequence codeSeq;
    1.16 +    private static Invocable code;
    1.17      
    1.18 -    private static void assertExec(String msg, String methodName, Object expRes, Object... args) throws Exception {
    1.19 +    @BeforeClass 
    1.20 +    public void compileTheCode() throws Exception {
    1.21          StringBuilder sb = new StringBuilder();
    1.22 -        Invocable i = StaticMethodTest.compileClass(sb, 
    1.23 +        code = StaticMethodTest.compileClass(sb, 
    1.24              "org/apidesign/vm4brwsr/StringSample",
    1.25              "java/lang/String"
    1.26          );
    1.27 -        
    1.28 +        codeSeq = sb;
    1.29 +    }
    1.30 +    
    1.31 +    private static void assertExec(String msg, String methodName, Object expRes, Object... args) throws Exception {
    1.32          Object ret = null;
    1.33          try {
    1.34 -            ret = i.invokeFunction(methodName, args);
    1.35 +            ret = code.invokeFunction(methodName, args);
    1.36          } catch (ScriptException ex) {
    1.37 -            fail("Execution failed in " + sb, ex);
    1.38 +            fail("Execution failed in\n" + codeSeq, ex);
    1.39          } catch (NoSuchMethodException ex) {
    1.40 -            fail("Cannot find method in " + sb, ex);
    1.41 +            fail("Cannot find method in\n" + codeSeq, ex);
    1.42          }
    1.43          if (ret == null && expRes == null) {
    1.44              return;
    1.45 @@ -58,7 +65,7 @@
    1.46          if (expRes.equals(ret)) {
    1.47              return;
    1.48          }
    1.49 -        assertEquals(ret, expRes, msg + "was: " + ret + "\n" + sb);
    1.50 +        assertEquals(ret, expRes, msg + "was: " + ret + "\n" + codeSeq);
    1.51          
    1.52      }
    1.53