40
40
41
41
import javax .script .ScriptException ;
42
42
43
+ import org .junit .After ;
44
+ import org .junit .Before ;
43
45
import org .junit .Test ;
44
46
import org .scijava .Context ;
47
+ import org .scijava .script .ScriptInfoTest .BindingSizes ;
45
48
import org .scijava .util .AppUtils ;
46
49
import org .scijava .util .ColorRGB ;
47
50
import org .scijava .util .ColorRGBA ;
53
56
*/
54
57
public class ScriptServiceTest {
55
58
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
+
56
73
/**
57
74
* Tests that the "scijava.scripts.path" system property is handled correctly.
58
75
*/
@@ -65,9 +82,6 @@ public void testSystemProperty() {
65
82
final String dir2 = root + "to" + slash + "the" + slash + "moon" ;
66
83
System .setProperty ("scijava.scripts.path" , dir1 + sep + dir2 );
67
84
68
- final Context context = new Context (ScriptService .class );
69
- final ScriptService scriptService = context .service (ScriptService .class );
70
-
71
85
final List <File > scriptDirs = scriptService .getScriptDirectories ();
72
86
assertEquals (3 , scriptDirs .size ());
73
87
@@ -80,9 +94,6 @@ public void testSystemProperty() {
80
94
81
95
@ Test
82
96
public void testBuiltInAliases () throws ScriptException {
83
- final Context ctx = new Context (ScriptService .class );
84
- final ScriptService ss = ctx .service (ScriptService .class );
85
-
86
97
final Class <?>[] builtIns = { boolean .class , byte .class , char .class ,
87
98
double .class , float .class , int .class , long .class , short .class ,
88
99
Boolean .class , Byte .class , Character .class , Double .class , Float .class ,
@@ -91,39 +102,44 @@ public void testBuiltInAliases() throws ScriptException {
91
102
String .class };
92
103
93
104
for (final Class <?> builtIn : builtIns ) {
94
- final Class <?> c = ss .lookupClass (builtIn .getSimpleName ());
105
+ final Class <?> c = scriptService .lookupClass (builtIn .getSimpleName ());
95
106
assertSame (builtIn , c );
96
107
}
97
-
98
- ctx .dispose ();
99
108
}
100
109
101
110
@ Test
102
111
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[][]" );
107
113
assertSame (int [][].class , pInt2D );
108
- final Class <?> pInt1D = ss .lookupClass ("int[]" );
114
+ final Class <?> pInt1D = scriptService .lookupClass ("int[]" );
109
115
assertSame (int [].class , pInt1D );
110
- final Class <?> pInt = ss .lookupClass ("int" );
116
+ final Class <?> pInt = scriptService .lookupClass ("int" );
111
117
assertSame (int .class , pInt );
112
118
113
- final Class <?> oInt2D = ss .lookupClass ("Integer[][]" );
119
+ final Class <?> oInt2D = scriptService .lookupClass ("Integer[][]" );
114
120
assertSame (Integer [][].class , oInt2D );
115
- final Class <?> oInt1D = ss .lookupClass ("Integer[]" );
121
+ final Class <?> oInt1D = scriptService .lookupClass ("Integer[]" );
116
122
assertSame (Integer [].class , oInt1D );
117
- final Class <?> oInt = ss .lookupClass ("Integer" );
123
+ final Class <?> oInt = scriptService .lookupClass ("Integer" );
118
124
assertSame (Integer .class , oInt );
119
125
120
- final Class <?> str2D = ss .lookupClass ("String[][]" );
126
+ final Class <?> str2D = scriptService .lookupClass ("String[][]" );
121
127
assertSame (String [][].class , str2D );
122
- final Class <?> str1D = ss .lookupClass ("String[]" );
128
+ final Class <?> str1D = scriptService .lookupClass ("String[]" );
123
129
assertSame (String [].class , str1D );
124
- final Class <?> str = ss .lookupClass ("String" );
130
+ final Class <?> str = scriptService .lookupClass ("String" );
125
131
assertSame (String .class , str );
132
+ }
126
133
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 ());
128
144
}
129
145
}
0 commit comments