2 * To change this template, choose Tools | Templates
3 * and open the template in the editor.
5 package org.apidesign.java4browser;
7 import javax.script.Invocable;
8 import javax.script.ScriptException;
9 import org.testng.annotations.Test;
10 import static org.testng.Assert.*;
14 * @author Jaroslav Tulach <jtulach@netbeans.org>
16 public class InstanceTest {
17 @Test public void verifyDefaultDoubleValue() throws Exception {
20 "org_apidesign_java4browser_Instance_defaultDblValueD",
24 @Test public void verifyAssignedByteValue() throws Exception {
26 "Will one thirty one",
27 "org_apidesign_java4browser_Instance_assignedByteValueB",
31 @Test public void verifyMagicOne() throws Exception {
33 "Should be three and something",
34 "org_apidesign_java4browser_Instance_magicOneD",
38 @Test public void verifyInstanceMethods() throws Exception {
40 "Should be eleven as we invoke overwritten method, plus 44",
41 "org_apidesign_java4browser_Instance_virtualBytesI",
45 @Test public void verifyInterfaceMethods() throws Exception {
47 "Retruns default value",
48 "org_apidesign_java4browser_Instance_interfaceBytesF",
53 @Test public void isNull() throws Exception {
55 "Yes, we are instance",
56 "org_apidesign_java4browser_Instance_isNullZ",
61 @Test public void isInstanceOf() throws Exception {
63 "Yes, we are instance",
64 "org_apidesign_java4browser_Instance_instanceOfZZ",
65 Double.valueOf(1.0), true
69 @Test public void notInstanceOf() throws Exception {
71 "No, we are not an instance",
72 "org_apidesign_java4browser_Instance_instanceOfZZ",
73 Double.valueOf(0.0), false
77 private static void assertExec(String msg, String methodName, Object expRes, Object... args) throws Exception {
78 StringBuilder sb = new StringBuilder();
79 Invocable i = StaticMethodTest.compileClass(sb, "Instance.class", "InstanceSub.class");
83 ret = i.invokeFunction(methodName, args);
84 } catch (ScriptException ex) {
85 fail("Execution failed in " + sb, ex);
86 } catch (NoSuchMethodException ex) {
87 fail("Cannot find method in " + sb, ex);
89 if (ret == null && expRes == null) {
92 if (expRes.equals(ret)) {
95 assertEquals(ret, expRes, msg + "was: " + ret + "\n" + sb);