1.1 --- a/vmtest/src/main/java/org/apidesign/bck2brwsr/vmtest/impl/Bck2BrwsrCase.java Tue Dec 25 15:31:58 2012 +0100
1.2 +++ b/vmtest/src/main/java/org/apidesign/bck2brwsr/vmtest/impl/Bck2BrwsrCase.java Tue Dec 25 17:46:21 2012 +0100
1.3 @@ -21,6 +21,7 @@
1.4 import java.util.Map;
1.5 import java.util.WeakHashMap;
1.6 import javax.script.Invocable;
1.7 +import org.apidesign.bck2brwsr.launcher.Launcher;
1.8 import org.apidesign.bck2brwsr.launcher.MethodInvocation;
1.9 import org.testng.ITest;
1.10 import org.testng.annotations.Test;
1.11 @@ -31,7 +32,7 @@
1.12 */
1.13 public final class Bck2BrwsrCase implements ITest {
1.14 private final Method m;
1.15 - private final LaunchSetup l;
1.16 + private final Launcher l;
1.17 private final String type;
1.18 Object value;
1.19 private Invocable code;
1.20 @@ -39,7 +40,7 @@
1.21 private static final Map<Class, Object[]> compiled = new WeakHashMap<>();
1.22 private Object inst;
1.23
1.24 - Bck2BrwsrCase(Method m, String type, LaunchSetup l) {
1.25 + Bck2BrwsrCase(Method m, String type, Launcher l) {
1.26 this.l = l;
1.27 this.m = m;
1.28 this.type = type;
2.1 --- a/vmtest/src/main/java/org/apidesign/bck2brwsr/vmtest/impl/CompareCase.java Tue Dec 25 15:31:58 2012 +0100
2.2 +++ b/vmtest/src/main/java/org/apidesign/bck2brwsr/vmtest/impl/CompareCase.java Tue Dec 25 17:46:21 2012 +0100
2.3 @@ -24,6 +24,7 @@
2.4 import java.lang.reflect.Method;
2.5 import java.util.ArrayList;
2.6 import java.util.List;
2.7 +import org.apidesign.bck2brwsr.launcher.Launcher;
2.8 import org.testng.Assert;
2.9 import org.testng.ITest;
2.10 import org.testng.annotations.Factory;
2.11 @@ -59,7 +60,7 @@
2.12 Method[] arr = clazz.getMethods();
2.13 List<Object> ret = new ArrayList<>();
2.14
2.15 - final LaunchSetup l = LaunchSetup.javaScript();
2.16 + final LaunchSetup l = LaunchSetup.INSTANCE;
2.17 ret.add(l);
2.18
2.19 String[] brwsr;
2.20 @@ -78,13 +79,13 @@
2.21 continue;
2.22 }
2.23 final Bck2BrwsrCase real = new Bck2BrwsrCase(m, "Java", null);
2.24 - final Bck2BrwsrCase js = new Bck2BrwsrCase(m, "JavaScript", l);
2.25 + final Bck2BrwsrCase js = new Bck2BrwsrCase(m, "JavaScript", l.javaScript());
2.26 ret.add(real);
2.27 ret.add(js);
2.28 ret.add(new CompareCase(m, real, js));
2.29
2.30 for (String b : brwsr) {
2.31 - final LaunchSetup s = LaunchSetup.brwsr(b);
2.32 + final Launcher s = l.brwsr(b);
2.33 ret.add(s);
2.34 final Bck2BrwsrCase cse = new Bck2BrwsrCase(m, b, s);
2.35 ret.add(cse);
3.1 --- a/vmtest/src/main/java/org/apidesign/bck2brwsr/vmtest/impl/LaunchSetup.java Tue Dec 25 15:31:58 2012 +0100
3.2 +++ b/vmtest/src/main/java/org/apidesign/bck2brwsr/vmtest/impl/LaunchSetup.java Tue Dec 25 17:46:21 2012 +0100
3.3 @@ -21,7 +21,6 @@
3.4 import java.util.LinkedHashMap;
3.5 import java.util.Map;
3.6 import org.apidesign.bck2brwsr.launcher.Launcher;
3.7 -import org.apidesign.bck2brwsr.launcher.MethodInvocation;
3.8 import org.testng.annotations.AfterGroups;
3.9 import org.testng.annotations.BeforeGroups;
3.10
3.11 @@ -30,39 +29,40 @@
3.12 * @author Jaroslav Tulach <jtulach@netbeans.org>
3.13 */
3.14 public final class LaunchSetup {
3.15 - private static final LaunchSetup JS = new LaunchSetup(Launcher.createJavaScript());
3.16 - private static final Map<String,LaunchSetup> BRWSRS = new LinkedHashMap<>();
3.17 + static LaunchSetup INSTANCE = new LaunchSetup();
3.18
3.19 - private final Launcher launcher;
3.20 + private final Launcher js = Launcher.createJavaScript();
3.21 + private final Map<String,Launcher> brwsrs = new LinkedHashMap<>();
3.22
3.23 - private LaunchSetup(Launcher l) {
3.24 - launcher = l;
3.25 + private LaunchSetup() {
3.26 }
3.27
3.28 - public static LaunchSetup javaScript() {
3.29 - return JS;
3.30 + public Launcher javaScript() {
3.31 + return js;
3.32 }
3.33
3.34 - public static synchronized LaunchSetup brwsr(String cmd) {
3.35 - LaunchSetup s = BRWSRS.get(cmd);
3.36 + public synchronized Launcher brwsr(String cmd) {
3.37 + Launcher s = brwsrs.get(cmd);
3.38 if (s == null) {
3.39 - s = new LaunchSetup(Launcher.createBrowser(cmd));
3.40 - BRWSRS.put(cmd, s);
3.41 + s = Launcher.createBrowser(cmd);
3.42 + brwsrs.put(cmd, s);
3.43 }
3.44 return s;
3.45 }
3.46
3.47 @BeforeGroups("run")
3.48 public void initializeLauncher() throws IOException {
3.49 - launcher.initialize();
3.50 + js.initialize();
3.51 + for (Launcher launcher : brwsrs.values()) {
3.52 + launcher.initialize();
3.53 + }
3.54 }
3.55
3.56 @AfterGroups("run")
3.57 public void shutDownLauncher() throws IOException, InterruptedException {
3.58 - launcher.shutdown();
3.59 - }
3.60 -
3.61 - public MethodInvocation invokeMethod(Class<?> clazz, String name) throws IOException {
3.62 - return launcher.invokeMethod(clazz, name);
3.63 + js.shutdown();
3.64 + for (Launcher launcher : brwsrs.values()) {
3.65 + launcher.shutdown();
3.66 + }
3.67 }
3.68 }