1
1
/*
2
- * Copyright 2002-2015 the original author or authors.
2
+ * Copyright 2002-2017 the original author or authors.
3
3
*
4
4
* Licensed under the Apache License, Version 2.0 (the "License");
5
5
* you may not use this file except in compliance with the License.
16
16
17
17
package org .springframework .scripting .bsh ;
18
18
19
+ import java .io .IOException ;
19
20
import java .util .Arrays ;
20
21
import java .util .Collection ;
21
22
47
48
public class BshScriptFactoryTests {
48
49
49
50
@ Test
50
- public void staticScript () throws Exception {
51
+ public void staticScript () {
51
52
ApplicationContext ctx = new ClassPathXmlApplicationContext ("bshContext.xml" , getClass ());
52
53
53
54
assertTrue (Arrays .asList (ctx .getBeanNamesForType (Calculator .class )).contains ("calculator" ));
@@ -75,7 +76,7 @@ public void staticScript() throws Exception {
75
76
}
76
77
77
78
@ Test
78
- public void staticScriptWithNullReturnValue () throws Exception {
79
+ public void staticScriptWithNullReturnValue () {
79
80
ApplicationContext ctx = new ClassPathXmlApplicationContext ("bshContext.xml" , getClass ());
80
81
assertTrue (Arrays .asList (ctx .getBeanNamesForType (Messenger .class )).contains ("messengerWithConfig" ));
81
82
@@ -86,7 +87,7 @@ public void staticScriptWithNullReturnValue() throws Exception {
86
87
}
87
88
88
89
@ Test
89
- public void staticScriptWithTwoInterfacesSpecified () throws Exception {
90
+ public void staticScriptWithTwoInterfacesSpecified () {
90
91
ClassPathXmlApplicationContext ctx = new ClassPathXmlApplicationContext ("bshContext.xml" , getClass ());
91
92
assertTrue (Arrays .asList (ctx .getBeanNamesForType (Messenger .class )).contains ("messengerWithConfigExtra" ));
92
93
@@ -100,7 +101,7 @@ public void staticScriptWithTwoInterfacesSpecified() throws Exception {
100
101
}
101
102
102
103
@ Test
103
- public void staticWithScriptReturningInstance () throws Exception {
104
+ public void staticWithScriptReturningInstance () {
104
105
ClassPathXmlApplicationContext ctx = new ClassPathXmlApplicationContext ("bshContext.xml" , getClass ());
105
106
assertTrue (Arrays .asList (ctx .getBeanNamesForType (Messenger .class )).contains ("messengerInstance" ));
106
107
@@ -114,7 +115,7 @@ public void staticWithScriptReturningInstance() throws Exception {
114
115
}
115
116
116
117
@ Test
117
- public void staticScriptImplementingInterface () throws Exception {
118
+ public void staticScriptImplementingInterface () {
118
119
ClassPathXmlApplicationContext ctx = new ClassPathXmlApplicationContext ("bshContext.xml" , getClass ());
119
120
assertTrue (Arrays .asList (ctx .getBeanNamesForType (Messenger .class )).contains ("messengerImpl" ));
120
121
@@ -128,7 +129,7 @@ public void staticScriptImplementingInterface() throws Exception {
128
129
}
129
130
130
131
@ Test
131
- public void staticPrototypeScript () throws Exception {
132
+ public void staticPrototypeScript () {
132
133
ApplicationContext ctx = new ClassPathXmlApplicationContext ("bshContext.xml" , getClass ());
133
134
ConfigurableMessenger messenger = (ConfigurableMessenger ) ctx .getBean ("messengerPrototype" );
134
135
ConfigurableMessenger messenger2 = (ConfigurableMessenger ) ctx .getBean ("messengerPrototype" );
@@ -147,7 +148,7 @@ public void staticPrototypeScript() throws Exception {
147
148
}
148
149
149
150
@ Test
150
- public void nonStaticScript () throws Exception {
151
+ public void nonStaticScript () {
151
152
ApplicationContext ctx = new ClassPathXmlApplicationContext ("bshRefreshableContext.xml" , getClass ());
152
153
Messenger messenger = (Messenger ) ctx .getBean ("messenger" );
153
154
@@ -165,7 +166,7 @@ public void nonStaticScript() throws Exception {
165
166
}
166
167
167
168
@ Test
168
- public void nonStaticPrototypeScript () throws Exception {
169
+ public void nonStaticPrototypeScript () {
169
170
ApplicationContext ctx = new ClassPathXmlApplicationContext ("bshRefreshableContext.xml" , getClass ());
170
171
ConfigurableMessenger messenger = (ConfigurableMessenger ) ctx .getBean ("messengerPrototype" );
171
172
ConfigurableMessenger messenger2 = (ConfigurableMessenger ) ctx .getBean ("messengerPrototype" );
@@ -189,7 +190,7 @@ public void nonStaticPrototypeScript() throws Exception {
189
190
}
190
191
191
192
@ Test
192
- public void scriptCompilationException () throws Exception {
193
+ public void scriptCompilationException () {
193
194
try {
194
195
new ClassPathXmlApplicationContext ("org/springframework/scripting/bsh/bshBrokenContext.xml" );
195
196
fail ("Must throw exception for broken script file" );
@@ -200,7 +201,7 @@ public void scriptCompilationException() throws Exception {
200
201
}
201
202
202
203
@ Test
203
- public void scriptThatCompilesButIsJustPlainBad () throws Exception {
204
+ public void scriptThatCompilesButIsJustPlainBad () throws IOException {
204
205
ScriptSource script = mock (ScriptSource .class );
205
206
final String badScript = "String getMessage() { throw new IllegalArgumentException(); }" ;
206
207
given (script .getScriptAsString ()).willReturn (badScript );
@@ -217,7 +218,7 @@ public void scriptThatCompilesButIsJustPlainBad() throws Exception {
217
218
}
218
219
219
220
@ Test
220
- public void ctorWithNullScriptSourceLocator () throws Exception {
221
+ public void ctorWithNullScriptSourceLocator () {
221
222
try {
222
223
new BshScriptFactory (null , Messenger .class );
223
224
fail ("Must have thrown exception by this point." );
@@ -227,27 +228,27 @@ public void ctorWithNullScriptSourceLocator() throws Exception {
227
228
}
228
229
229
230
@ Test
230
- public void ctorWithEmptyScriptSourceLocator () throws Exception {
231
+ public void ctorWithEmptyScriptSourceLocator () {
231
232
try {
232
- new BshScriptFactory ("" , new Class <?>[] { Messenger .class } );
233
+ new BshScriptFactory ("" , Messenger .class );
233
234
fail ("Must have thrown exception by this point." );
234
235
}
235
236
catch (IllegalArgumentException expected ) {
236
237
}
237
238
}
238
239
239
240
@ Test
240
- public void ctorWithWhitespacedScriptSourceLocator () throws Exception {
241
+ public void ctorWithWhitespacedScriptSourceLocator () {
241
242
try {
242
- new BshScriptFactory ("\n " , new Class <?>[] { Messenger .class } );
243
+ new BshScriptFactory ("\n " , Messenger .class );
243
244
fail ("Must have thrown exception by this point." );
244
245
}
245
246
catch (IllegalArgumentException expected ) {
246
247
}
247
248
}
248
249
249
250
@ Test
250
- public void resourceScriptFromTag () throws Exception {
251
+ public void resourceScriptFromTag () {
251
252
ClassPathXmlApplicationContext ctx = new ClassPathXmlApplicationContext ("bsh-with-xsd.xml" , getClass ());
252
253
TestBean testBean = (TestBean ) ctx .getBean ("testBean" );
253
254
@@ -286,7 +287,7 @@ public void resourceScriptFromTag() throws Exception {
286
287
}
287
288
288
289
@ Test
289
- public void prototypeScriptFromTag () throws Exception {
290
+ public void prototypeScriptFromTag () {
290
291
ApplicationContext ctx = new ClassPathXmlApplicationContext ("bsh-with-xsd.xml" , getClass ());
291
292
ConfigurableMessenger messenger = (ConfigurableMessenger ) ctx .getBean ("messengerPrototype" );
292
293
ConfigurableMessenger messenger2 = (ConfigurableMessenger ) ctx .getBean ("messengerPrototype" );
@@ -302,23 +303,23 @@ public void prototypeScriptFromTag() throws Exception {
302
303
}
303
304
304
305
@ Test
305
- public void inlineScriptFromTag () throws Exception {
306
+ public void inlineScriptFromTag () {
306
307
ApplicationContext ctx = new ClassPathXmlApplicationContext ("bsh-with-xsd.xml" , getClass ());
307
308
Calculator calculator = (Calculator ) ctx .getBean ("calculator" );
308
309
assertNotNull (calculator );
309
310
assertFalse (calculator instanceof Refreshable );
310
311
}
311
312
312
313
@ Test
313
- public void refreshableFromTag () throws Exception {
314
+ public void refreshableFromTag () {
314
315
ApplicationContext ctx = new ClassPathXmlApplicationContext ("bsh-with-xsd.xml" , getClass ());
315
316
Messenger messenger = (Messenger ) ctx .getBean ("refreshableMessenger" );
316
317
assertEquals ("Hello World!" , messenger .getMessage ());
317
318
assertTrue ("Messenger should be Refreshable" , messenger instanceof Refreshable );
318
319
}
319
320
320
321
@ Test
321
- public void applicationEventListener () throws Exception {
322
+ public void applicationEventListener () {
322
323
ApplicationContext ctx = new ClassPathXmlApplicationContext ("bsh-with-xsd.xml" , getClass ());
323
324
Messenger eventListener = (Messenger ) ctx .getBean ("eventListener" );
324
325
ctx .publishEvent (new MyEvent (ctx ));
0 commit comments