Skip to content

Commit e1b6a61

Browse files
committed
JythonTest: clean up contexts properly
1 parent c6f9b05 commit e1b6a61

File tree

1 file changed

+16
-11
lines changed

1 file changed

+16
-11
lines changed

src/test/java/org/scijava/plugins/scripting/jython/JythonTest.java

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,8 @@
4343
import javax.script.ScriptEngine;
4444
import javax.script.ScriptException;
4545

46+
import org.junit.After;
47+
import org.junit.Before;
4648
import org.junit.Test;
4749
import org.scijava.Context;
4850
import org.scijava.script.ScriptLanguage;
@@ -56,12 +58,24 @@
5658
*/
5759
public class JythonTest {
5860

61+
private Context context;
62+
private ScriptService scriptService;
63+
64+
@Before
65+
public void setUp() {
66+
context = new Context();
67+
scriptService = context.getService(ScriptService.class);
68+
}
69+
70+
@After
71+
public void tearDown() {
72+
context.dispose();
73+
}
74+
5975
@Test
6076
public void testBasic() throws InterruptedException, ExecutionException,
6177
IOException, ScriptException
6278
{
63-
final Context context = new Context();
64-
final ScriptService scriptService = context.getService(ScriptService.class);
6579
final String script = "1 + 2";
6680
final ScriptModule m = scriptService.run("add.py", script, true).get();
6781
final Object result = m.getLanguage().decode(m.getReturnValue());
@@ -71,9 +85,6 @@ public void testBasic() throws InterruptedException, ExecutionException,
7185

7286
@Test
7387
public void testLocals() throws ScriptException {
74-
final Context context = new Context();
75-
final ScriptService scriptService = context.getService(ScriptService.class);
76-
7788
final ScriptLanguage language = scriptService.getLanguageByExtension("py");
7889
final ScriptEngine engine = language.getScriptEngine();
7990
assertEquals(JythonScriptEngine.class, engine.getClass());
@@ -90,9 +101,6 @@ public void testLocals() throws ScriptException {
90101
public void testParameters() throws InterruptedException, ExecutionException,
91102
IOException, ScriptException
92103
{
93-
final Context context = new Context();
94-
final ScriptService scriptService = context.getService(ScriptService.class);
95-
96104
final String script = "" + //
97105
"# @ScriptService ss\n" + //
98106
"# @OUTPUT String language\n" + //
@@ -129,9 +137,6 @@ public void testParameters() throws InterruptedException, ExecutionException,
129137
public void testLongType() throws InterruptedException, ExecutionException,
130138
IOException, ScriptException
131139
{
132-
final Context context = new Context();
133-
final ScriptService scriptService = context.getService(ScriptService.class);
134-
135140
final String script = "" + //
136141
"# @OUTPUT String varType\n" + //
137142
"a = 10L\n" + //

0 commit comments

Comments
 (0)