vm/src/test/java/org/apidesign/vm4brwsr/StaticMethodTest.java
branchlazyvm
changeset 302 af9c8df8a660
parent 276 aeb9fe11cd60
child 306 f36b3c273de6
     1.1 --- a/vm/src/test/java/org/apidesign/vm4brwsr/StaticMethodTest.java	Thu Dec 06 22:02:10 2012 +0100
     1.2 +++ b/vm/src/test/java/org/apidesign/vm4brwsr/StaticMethodTest.java	Tue Dec 11 10:24:00 2012 +0100
     1.3 @@ -20,6 +20,9 @@
     1.4  import java.io.File;
     1.5  import java.io.FileWriter;
     1.6  import java.io.IOException;
     1.7 +import java.io.InputStream;
     1.8 +import java.net.URL;
     1.9 +import java.util.Enumeration;
    1.10  import javax.script.Invocable;
    1.11  import javax.script.ScriptEngine;
    1.12  import javax.script.ScriptEngineManager;
    1.13 @@ -289,7 +292,7 @@
    1.14          if (sb == null) {
    1.15              sb = new StringBuilder();
    1.16          }
    1.17 -        GenJS.compile(sb, names);
    1.18 +        Bck2Brwsr.generate(sb, new EmulationResources(), names);
    1.19          ScriptEngineManager sem = new ScriptEngineManager();
    1.20          ScriptEngine js = sem.getEngineByExtension("js");
    1.21          if (eng != null) {
    1.22 @@ -314,4 +317,21 @@
    1.23          w.close();
    1.24          return new StringBuilder(f.getPath());
    1.25      }
    1.26 +    private static class EmulationResources implements Bck2Brwsr.Resources {
    1.27 +        @Override
    1.28 +        public InputStream get(String name) throws IOException {
    1.29 +            Enumeration<URL> en = StaticMethodTest.class.getClassLoader().getResources(name);
    1.30 +            URL u = null;
    1.31 +            while (en.hasMoreElements()) {
    1.32 +                u = en.nextElement();
    1.33 +            }
    1.34 +            if (u == null) {
    1.35 +                throw new IOException("Can't find " + name);
    1.36 +            }
    1.37 +            if (u.toExternalForm().contains("rt.jar!")) {
    1.38 +                throw new IOException("No emulation for " + u);
    1.39 +            }
    1.40 +            return u.openStream();
    1.41 +        }
    1.42 +    }
    1.43  }