src/test/java/org/apidesign/java4browser/InstanceTest.java
author Jaroslav Tulach <jaroslav.tulach@apidesign.org>
Sat, 15 Sep 2012 22:12:49 +0200
changeset 8 82772c96ec57
child 10 e84d9314f1bc
permissions -rw-r--r--
Few more instructions, but not all of them are well implemented
     1 /*
     2  * To change this template, choose Tools | Templates
     3  * and open the template in the editor.
     4  */
     5 package org.apidesign.java4browser;
     6 
     7 import javax.script.Invocable;
     8 import javax.script.ScriptException;
     9 import org.testng.annotations.Test;
    10 import static org.testng.Assert.*;
    11 
    12 /**
    13  *
    14  * @author Jaroslav Tulach <jtulach@netbeans.org>
    15  */
    16 public class InstanceTest {
    17     @Test public void verifyMagicOne() throws Exception {
    18         assertExec(
    19             "Should be seven",
    20             "org_apidesign_java4browser_Instance_magicOneD",
    21             Double.valueOf(3.3)
    22         );
    23     }
    24     
    25     private static void assertExec(String msg, String methodName, Object expRes, Object... args) throws Exception {
    26         StringBuilder sb = new StringBuilder();
    27         Invocable i = StaticMethodTest.compileClass("Instance.class", sb);
    28         
    29         Object ret = null;
    30         try {
    31             ret = i.invokeFunction(methodName, args);
    32         } catch (ScriptException ex) {
    33             fail("Execution failed in " + sb, ex);
    34         } catch (NoSuchMethodException ex) {
    35             fail("Cannot find method in " + sb, ex);
    36         }
    37         if (ret == null && expRes == null) {
    38             return;
    39         }
    40         if (expRes.equals(ret)) {
    41             return;
    42         }
    43         assertEquals(ret, expRes, msg + "was: " + ret + "\n" + sb);
    44         
    45     }
    46     
    47 }