Skip to content

Commit 94f8315

Browse files
committed
JavaScriptTest: ensure importClass function works
Support for this function is highly dependent on the specific JavaScript engine implementation. So let's definitely test it!
1 parent 7d91e4d commit 94f8315

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

src/test/java/org/scijava/plugins/scripting/javascript/JavaScriptTest.java

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,22 @@ public void testLoad() throws IOException, InterruptedException, ExecutionExcept
125125
assertTrue(tmp.delete());
126126
}
127127

128+
@Test
129+
public void testJavaAPI() throws InterruptedException, ExecutionException,
130+
IOException, ScriptException
131+
{
132+
final Context context = new Context(ScriptService.class);
133+
final ScriptService scriptService = context.getService(ScriptService.class);
134+
final String script = //
135+
"importClass(Packages.java.util.ArrayList);\n" //
136+
+ "var list = new ArrayList();\n" //
137+
+ "list.add(3);\n" //
138+
+ "list.add(5.5);\n" //
139+
+ "list.add(7);\n" //
140+
+ "list.get(1);\n";
141+
assertResult(5.5, scriptService.run("javaAPI.js", script, true).get());
142+
}
143+
128144
// -- Helper methods --
129145

130146
private void assertResult(final double expected, final ScriptModule m) {

0 commit comments

Comments
 (0)