Skip to content

Commit 11c21f7

Browse files
committed
Add tests for batchable inputs
1 parent 95db9b2 commit 11c21f7

File tree

1 file changed

+42
-3
lines changed

1 file changed

+42
-3
lines changed

src/test/java/org/scijava/batch/BatchServiceTest.java

Lines changed: 42 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,12 @@
22

33
import static org.junit.Assert.assertEquals;
44
import static org.junit.Assert.assertNotNull;
5+
import static org.junit.Assert.assertTrue;
56

67
import java.io.File;
78
import java.io.StringReader;
89
import java.util.HashMap;
10+
import java.util.List;
911
import java.util.concurrent.ExecutionException;
1012

1113
import net.imagej.table.Table;
@@ -17,6 +19,7 @@
1719
import org.scijava.command.CommandInfo;
1820
import org.scijava.command.CommandService;
1921
import org.scijava.module.Module;
22+
import org.scijava.module.ModuleItem;
2023
import org.scijava.module.ModuleService;
2124
import org.scijava.script.ScriptInfo;
2225
import org.scijava.service.SciJavaService;
@@ -44,6 +47,37 @@ public void testContext() {
4447
.getService(BatchService.class);
4548
assertNotNull(batchService);
4649
}
50+
51+
@Test
52+
public void testBatchableFileInputs() {
53+
String script = "" //
54+
+ "#@ File fileInput\n" //
55+
+ "#@ String stringInput\n" //
56+
+ "#@ Integer integerInput\n" //
57+
+ "#@ Double doubleInput\n" //
58+
+ "";
59+
ScriptInfo scriptInfo = createInfo(script);
60+
BatchService batchService = context.getService(BatchService.class);
61+
List<ModuleItem<?>> compatibleInputs = batchService.batchableInputs(
62+
scriptInfo);
63+
assertEquals("Wrong number of batchable inputs", 1, compatibleInputs
64+
.size());
65+
}
66+
67+
@Test
68+
public void testNoCompatibleInputs() {
69+
String script = "" //
70+
+ "#@ String stringInput\n" //
71+
+ "#@ Integer integerInput\n" //
72+
+ "#@ Double doubleInput\n" //
73+
+ "";
74+
ScriptInfo scriptInfo = createInfo(script);
75+
BatchService batchService = context.getService(BatchService.class);
76+
List<ModuleItem<?>> compatibleInputs = batchService.batchableInputs(
77+
scriptInfo);
78+
assertTrue("Wrong inputs found to be compatible", compatibleInputs
79+
.isEmpty());
80+
}
4781

4882
@Test
4983
public void testModuleBatchProcessor() {
@@ -52,9 +86,7 @@ public void testModuleBatchProcessor() {
5286
+ "#@output result\n" //
5387
+ "" //
5488
+ "result = input";
55-
StringReader scriptReader = new StringReader(script);
56-
ScriptInfo scriptInfo = new ScriptInfo(context, "Foo.groovy",
57-
scriptReader);
89+
ScriptInfo scriptInfo = createInfo(script);
5890

5991
assertEquals("Wrong script language", "Groovy", scriptInfo
6092
.getLanguage().getLanguageName());
@@ -90,4 +122,11 @@ public void testModuleBatchProcessor() {
90122
outputs.getColumnHeader(0));
91123
assertEquals("Wrong file name", "quo.txt", outputs.getRowHeader(2));
92124
}
125+
126+
/* --- Helper methods --- */
127+
128+
private ScriptInfo createInfo(String script) {
129+
StringReader scriptReader = new StringReader(script);
130+
return new ScriptInfo(context, "Foo.groovy", scriptReader);
131+
}
93132
}

0 commit comments

Comments
 (0)