Encapsulation. Moving shared code into TestVM instance.
2 * Back 2 Browser Bytecode Translator
3 * Copyright (C) 2012 Jaroslav Tulach <jaroslav.tulach@apidesign.org>
5 * This program is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation, version 2 of the License.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program. Look for COPYING file in the top folder.
16 * If not, see http://opensource.org/licenses/GPL-2.0.
18 package org.apidesign.vm4brwsr;
20 import javax.script.ScriptException;
21 import static org.testng.Assert.*;
22 import org.testng.annotations.BeforeClass;
23 import org.testng.annotations.Test;
27 * @author Tomas Zezula <tzezula@netbeans.org>
29 public class ExceptionsTest {
31 public void verifyMethodWithTryCatchNoThrow() throws Exception {
35 "methodWithTryCatchNoThrow__I",
40 public void catchJavaScriptStringAsThrowable() throws Exception {
44 "catchThrowableCatchesAll__Ljava_lang_String_2",
50 public void verifyMethodWithTryCatchThrow() throws Exception {
54 "methodWithTryCatchThrow__I",
58 @Test public void createObject() throws Exception {
59 assertExec("Object created", Exceptions.class,
60 "newInstance__Ljava_lang_String_2Ljava_lang_String_2",
66 @Test public void createFloatFails() throws Exception {
67 assertExec("Float not created", Exceptions.class,
68 "newInstance__Ljava_lang_String_2Ljava_lang_String_2",
74 @Test public void createUnknownFails() throws Exception {
75 assertExec("Object created", Exceptions.class,
76 "newInstance__Ljava_lang_String_2Ljava_lang_String_2",
77 "CNFE:org.apidesign.Unknown",
78 "org.apidesign.Unknown"
82 @Test public void testThreeCalls() throws Exception {
83 Object clazz = code.loadClass("loadClass", Exceptions.class.getName());
85 String method = "readCounter__ILjava_lang_String_2";
88 Object ret = code.invokeMethod(clazz, method, "org.apidesign.Unknown");
89 fail("We expect an CNFE!");
90 } catch (ScriptException scriptException) {
91 // script exception should be OK
95 Object ret = code.invokeMethod(clazz, method, "java.lang.String");
96 assertEquals(ret, Double.valueOf(2));
100 Object ret = code.invokeMethod(clazz, method, "java.lang.Integer");
101 assertEquals(ret, Double.valueOf(3));
105 private static TestVM code;
108 public void compileTheCode() throws Exception {
109 code = TestVM.compileClass("org/apidesign/vm4brwsr/Exceptions");
111 private static void assertExec(String msg, Class clazz, String method, Object expRes, Object... args) throws Exception {
112 code.assertExec(msg, clazz, method, expRes, args);