Skip to content

Commit 41582b5

Browse files
committed
BeanshellTest: clean up the code
* Clean up the application contexts we create. * Clean up throws clauses to remove irrelevant exceptions.
1 parent 0244cef commit 41582b5

1 file changed

Lines changed: 23 additions & 21 deletions

File tree

‎src/test/java/org/scijava/plugins/scripting/beanshell/BeanshellTest.java‎

Lines changed: 23 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,8 @@
4141
import javax.script.ScriptEngine;
4242
import javax.script.ScriptException;
4343

44+
import org.junit.After;
45+
import org.junit.Before;
4446
import org.junit.Test;
4547
import org.scijava.Context;
4648
import org.scijava.script.AbstractScriptLanguageTest;
@@ -51,24 +53,37 @@
5153
import bsh.BshScriptEngine;
5254

5355
/**
54-
* Unit tests for the Beanshell support.
56+
* Unit tests for the BeanShell support.
5557
*
5658
* @author Johannes Schindelin
5759
* @author Curtis Rueden
5860
*/
5961
public class BeanshellTest extends AbstractScriptLanguageTest {
6062

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+
73+
@After
74+
public void tearDown() {
75+
context.dispose();
76+
context = null;
77+
scriptService = null;
78+
}
79+
6180
@Test
6281
public void testDiscovery() {
6382
assertDiscovered(BeanshellScriptLanguage.class);
6483
}
6584

6685
@Test
67-
public void testBasic() throws InterruptedException, ExecutionException,
68-
IOException, ScriptException
69-
{
70-
final Context context = new Context(ScriptService.class);
71-
final ScriptService scriptService = context.getService(ScriptService.class);
86+
public void testBasic() throws InterruptedException, ExecutionException {
7287
final String script = "x = 1 + 2;";
7388
final ScriptModule m = scriptService.run("add.bsh", script, true).get();
7489
final Integer result = (Integer) m.getReturnValue();
@@ -77,9 +92,6 @@ public void testBasic() throws InterruptedException, ExecutionException,
7792

7893
@Test
7994
public void testLocals() throws ScriptException {
80-
final Context context = new Context(ScriptService.class);
81-
final ScriptService scriptService = context.getService(ScriptService.class);
82-
8395
final ScriptLanguage language = scriptService.getLanguageByExtension("bsh");
8496
final ScriptEngine engine = language.getScriptEngine();
8597
assertEquals(BshScriptEngine.class, engine.getClass());
@@ -93,12 +105,7 @@ public void testLocals() throws ScriptException {
93105
}
94106

95107
@Test
96-
public void testParameters() throws InterruptedException, ExecutionException,
97-
IOException, ScriptException
98-
{
99-
final Context context = new Context(ScriptService.class);
100-
final ScriptService scriptService = context.getService(ScriptService.class);
101-
108+
public void testParameters() throws InterruptedException, ExecutionException {
102109
final String script = "" + //
103110
"#@ ScriptService ss\n" + //
104111
"#@output String language\n" + //
@@ -115,12 +122,7 @@ public void testParameters() throws InterruptedException, ExecutionException,
115122
}
116123

117124
@Test
118-
public void testNull() throws InterruptedException, ExecutionException,
119-
IOException, ScriptException
120-
{
121-
final Context context = new Context(ScriptService.class);
122-
final ScriptService scriptService = context.getService(ScriptService.class);
123-
125+
public void testNull() throws InterruptedException, ExecutionException {
124126
final String script = "" + //
125127
"#@ ScriptService ss\n" + //
126128
"#@output String ternary\n" + //

0 commit comments

Comments
 (0)