diff -r b671ac44bc55 -r 6f964a88e6c5 vmtest/src/main/java/org/apidesign/bck2brwsr/vmtest/VMTest.java
--- a/vmtest/src/main/java/org/apidesign/bck2brwsr/vmtest/VMTest.java Mon Dec 17 17:45:08 2012 +0100
+++ b/vmtest/src/main/java/org/apidesign/bck2brwsr/vmtest/VMTest.java Mon Dec 17 17:51:05 2012 +0100
@@ -55,7 +55,7 @@
}
/** Inspects clazz
and for each {@lik Compare} method creates
- * instances of tests. Each insteance runs the test in different virtual
+ * instances of tests. Each instance runs the test in different virtual
* machine and at the end they compare the results.
*
* @param clazz the class to inspect
@@ -140,7 +140,7 @@
Object value;
private Invocable code;
private CharSequence codeSeq;
- private static final Map compiled = new WeakHashMap();
+ private static final Map compiled = new WeakHashMap<>();
private Run(Method m, boolean js) {
this.m = m;
@@ -158,17 +158,16 @@
Bck2Brwsr.generate(sb, VMTest.class.getClassLoader());
ScriptEngineManager sem = new ScriptEngineManager();
- ScriptEngine js = sem.getEngineByExtension("js");
+ ScriptEngine mach = sem.getEngineByExtension("js");
- sb.append("\nfunction initVM() {"
- + "\n return bck2brwsr("
- + "\n function(name) { return org.apidesign.bck2brwsr.vmtest.VMTest.read(name);}"
- + "\n );"
- + "\n};");
+ sb.append(
+ "\nvar vm = bck2brwsr(org.apidesign.bck2brwsr.vmtest.VMTest.read);"
+ + "\nfunction initVM() { return vm; };"
+ + "\n");
- Object res = js.eval(sb.toString());
- Assert.assertTrue(js instanceof Invocable, "It is invocable object: " + res);
- code = (Invocable) js;
+ Object res = mach.eval(sb.toString());
+ Assert.assertTrue(mach instanceof Invocable, "It is invocable object: " + res);
+ code = (Invocable) mach;
codeSeq = sb;
compiled.put(clazz, new Object[] { code, codeSeq });
}
@@ -246,9 +245,9 @@
static StringBuilder dumpJS(CharSequence sb) throws IOException {
File f = File.createTempFile("execution", ".js");
- FileWriter w = new FileWriter(f);
- w.append(sb);
- w.close();
+ try (FileWriter w = new FileWriter(f)) {
+ w.append(sb);
+ }
return new StringBuilder(f.getPath());
}
}