22
33import static org .junit .Assert .assertEquals ;
44import static org .junit .Assert .assertNotNull ;
5+ import static org .junit .Assert .assertTrue ;
56
67import java .io .File ;
78import java .io .StringReader ;
89import java .util .HashMap ;
10+ import java .util .List ;
911import java .util .concurrent .ExecutionException ;
1012
1113import net .imagej .table .Table ;
1719import org .scijava .command .CommandInfo ;
1820import org .scijava .command .CommandService ;
1921import org .scijava .module .Module ;
22+ import org .scijava .module .ModuleItem ;
2023import org .scijava .module .ModuleService ;
2124import org .scijava .script .ScriptInfo ;
2225import 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