Skip to content

Commit b24bd0d

Browse files
committed
ScriptEngineTest: dispose contexts properly
1 parent d90c367 commit b24bd0d

File tree

1 file changed

+19
-4
lines changed

1 file changed

+19
-4
lines changed

src/test/java/org/scijava/script/ScriptEngineTest.java

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,8 @@
4646
import javax.script.ScriptEngine;
4747
import javax.script.ScriptException;
4848

49+
import org.junit.After;
50+
import org.junit.Before;
4951
import org.junit.Test;
5052
import org.scijava.Context;
5153
import org.scijava.plugin.Plugin;
@@ -54,13 +56,28 @@
5456
* Basic tests for the {@link ScriptService}.
5557
*
5658
* @author Johannes Schindelin
59+
* @author Curtis Rueden
5760
*/
5861
public class ScriptEngineTest {
5962

63+
private Context context;
64+
private ScriptService scriptService;
65+
66+
@Before
67+
public void setUp() {
68+
context = new Context(ScriptService.class);
69+
scriptService = context.getService(ScriptService.class);
70+
}
71+
72+
@After
73+
public void tearDown() {
74+
context.dispose();
75+
context = null;
76+
scriptService = null;
77+
}
78+
6079
@Test
6180
public void testRot13() throws Exception {
62-
final Context context = new Context(ScriptService.class);
63-
final ScriptService scriptService = context.getService(ScriptService.class);
6481
final ScriptLanguage hello = scriptService.getLanguageByName("Hello");
6582
assertNotNull(hello);
6683
final ScriptLanguage rot13 = scriptService.getLanguageByName("Rot13");
@@ -70,8 +87,6 @@ public void testRot13() throws Exception {
7087

7188
@Test
7289
public void testScriptModuleValue() throws Exception {
73-
final Context context = new Context(ScriptService.class);
74-
final ScriptService scriptService = context.getService(ScriptService.class);
7590
final ScriptModule module =
7691
scriptService.run("test.rot13", ScriptModule.class.getName(), false,
7792
(Map<String, Object>) null).get();

0 commit comments

Comments
 (0)