jaroslav@372: /** jaroslav@372: * Back 2 Browser Bytecode Translator jaroslav@372: * Copyright (C) 2012 Jaroslav Tulach jaroslav@372: * jaroslav@372: * This program is free software: you can redistribute it and/or modify jaroslav@372: * it under the terms of the GNU General Public License as published by jaroslav@372: * the Free Software Foundation, version 2 of the License. jaroslav@372: * jaroslav@372: * This program is distributed in the hope that it will be useful, jaroslav@372: * but WITHOUT ANY WARRANTY; without even the implied warranty of jaroslav@372: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the jaroslav@372: * GNU General Public License for more details. jaroslav@372: * jaroslav@372: * You should have received a copy of the GNU General Public License jaroslav@372: * along with this program. Look for COPYING file in the top folder. jaroslav@372: * If not, see http://opensource.org/licenses/GPL-2.0. jaroslav@372: */ jaroslav@372: package org.apidesign.bck2brwsr.vmtest.impl; jaroslav@372: jaroslav@372: import java.lang.reflect.Method; jaroslav@372: import java.util.Map; jaroslav@372: import java.util.WeakHashMap; jaroslav@372: import javax.script.Invocable; jaroslav@372: import org.apidesign.bck2brwsr.launcher.MethodInvocation; jaroslav@372: import org.testng.ITest; jaroslav@372: import org.testng.annotations.Test; jaroslav@372: jaroslav@372: /** jaroslav@372: * jaroslav@372: * @author Jaroslav Tulach jaroslav@372: */ jaroslav@372: public final class Bck2BrwsrCase implements ITest { jaroslav@372: private final Method m; jaroslav@383: private final LaunchSetup l; jaroslav@383: private final String type; jaroslav@372: Object value; jaroslav@372: private Invocable code; jaroslav@372: private CharSequence codeSeq; jaroslav@372: private static final Map compiled = new WeakHashMap<>(); jaroslav@372: private Object inst; jaroslav@372: jaroslav@383: Bck2BrwsrCase(Method m, String type, LaunchSetup l) { jaroslav@372: this.l = l; jaroslav@372: this.m = m; jaroslav@372: this.type = type; jaroslav@372: } jaroslav@372: jaroslav@372: @Test(groups = "run") jaroslav@372: public void executeCode() throws Throwable { jaroslav@383: if (l != null) { jaroslav@383: MethodInvocation c = l.invokeMethod(m.getDeclaringClass(), m.getName()); jaroslav@372: value = c.toString(); jaroslav@372: } else { jaroslav@372: value = m.invoke(m.getDeclaringClass().newInstance()); jaroslav@372: } jaroslav@372: } jaroslav@372: jaroslav@372: @Override jaroslav@372: public String getTestName() { jaroslav@372: return m.getName() + "[" + typeName() + "]"; jaroslav@372: } jaroslav@372: jaroslav@372: final String typeName() { jaroslav@383: return type; jaroslav@372: } jaroslav@372: }