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