4040
4141import javax .script .ScriptException ;
4242
43+ import org .junit .After ;
44+ import org .junit .Before ;
4345import org .junit .Test ;
4446import org .scijava .Context ;
47+ import org .scijava .script .ScriptInfoTest .BindingSizes ;
4548import org .scijava .util .AppUtils ;
4649import org .scijava .util .ColorRGB ;
4750import org .scijava .util .ColorRGBA ;
5356 */
5457public class ScriptServiceTest {
5558
59+ private Context context ;
60+ private ScriptService scriptService ;
61+
62+ @ Before
63+ public void setUp () {
64+ context = new Context (ScriptService .class );
65+ scriptService = context .service (ScriptService .class );
66+ }
67+
68+ @ After
69+ public void tearDown () {
70+ context .dispose ();
71+ }
72+
5673 /**
5774 * Tests that the "scijava.scripts.path" system property is handled correctly.
5875 */
@@ -65,9 +82,6 @@ public void testSystemProperty() {
6582 final String dir2 = root + "to" + slash + "the" + slash + "moon" ;
6683 System .setProperty ("scijava.scripts.path" , dir1 + sep + dir2 );
6784
68- final Context context = new Context (ScriptService .class );
69- final ScriptService scriptService = context .service (ScriptService .class );
70-
7185 final List <File > scriptDirs = scriptService .getScriptDirectories ();
7286 assertEquals (3 , scriptDirs .size ());
7387
@@ -80,9 +94,6 @@ public void testSystemProperty() {
8094
8195 @ Test
8296 public void testBuiltInAliases () throws ScriptException {
83- final Context ctx = new Context (ScriptService .class );
84- final ScriptService ss = ctx .service (ScriptService .class );
85-
8697 final Class <?>[] builtIns = { boolean .class , byte .class , char .class ,
8798 double .class , float .class , int .class , long .class , short .class ,
8899 Boolean .class , Byte .class , Character .class , Double .class , Float .class ,
@@ -91,39 +102,44 @@ public void testBuiltInAliases() throws ScriptException {
91102 String .class };
92103
93104 for (final Class <?> builtIn : builtIns ) {
94- final Class <?> c = ss .lookupClass (builtIn .getSimpleName ());
105+ final Class <?> c = scriptService .lookupClass (builtIn .getSimpleName ());
95106 assertSame (builtIn , c );
96107 }
97-
98- ctx .dispose ();
99108 }
100109
101110 @ Test
102111 public void testArrayAliases () throws ScriptException {
103- final Context ctx = new Context (ScriptService .class );
104- final ScriptService ss = ctx .service (ScriptService .class );
105-
106- final Class <?> pInt2D = ss .lookupClass ("int[][]" );
112+ final Class <?> pInt2D = scriptService .lookupClass ("int[][]" );
107113 assertSame (int [][].class , pInt2D );
108- final Class <?> pInt1D = ss .lookupClass ("int[]" );
114+ final Class <?> pInt1D = scriptService .lookupClass ("int[]" );
109115 assertSame (int [].class , pInt1D );
110- final Class <?> pInt = ss .lookupClass ("int" );
116+ final Class <?> pInt = scriptService .lookupClass ("int" );
111117 assertSame (int .class , pInt );
112118
113- final Class <?> oInt2D = ss .lookupClass ("Integer[][]" );
119+ final Class <?> oInt2D = scriptService .lookupClass ("Integer[][]" );
114120 assertSame (Integer [][].class , oInt2D );
115- final Class <?> oInt1D = ss .lookupClass ("Integer[]" );
121+ final Class <?> oInt1D = scriptService .lookupClass ("Integer[]" );
116122 assertSame (Integer [].class , oInt1D );
117- final Class <?> oInt = ss .lookupClass ("Integer" );
123+ final Class <?> oInt = scriptService .lookupClass ("Integer" );
118124 assertSame (Integer .class , oInt );
119125
120- final Class <?> str2D = ss .lookupClass ("String[][]" );
126+ final Class <?> str2D = scriptService .lookupClass ("String[][]" );
121127 assertSame (String [][].class , str2D );
122- final Class <?> str1D = ss .lookupClass ("String[]" );
128+ final Class <?> str1D = scriptService .lookupClass ("String[]" );
123129 assertSame (String [].class , str1D );
124- final Class <?> str = ss .lookupClass ("String" );
130+ final Class <?> str = scriptService .lookupClass ("String" );
125131 assertSame (String .class , str );
132+ }
126133
127- ctx .dispose ();
134+ @ Test
135+ public void testGetScript () {
136+ String script = "#@ String name\n " +
137+ "#@output String greeting\n " +
138+ "greeting = \" Hello, \" + name + \" !\" " ;
139+ // see ScriptInfoTest for the .bsizes ScriptLanguage used here
140+ ScriptInfo scriptInfo = scriptService .getScript (".bsizes" , script );
141+ assertEquals (BindingSizes .class , scriptInfo .getLanguage ().getClass ());
142+ assertEquals ("name" , scriptInfo .inputs ().iterator ().next ().getName ());
143+ assertEquals ("greeting" , scriptInfo .outputs ().iterator ().next ().getName ());
128144 }
129145}
0 commit comments