1616
1717package org .springframework .scripting .groovy ;
1818
19- import groovy .lang .DelegatingMetaClass ;
20- import groovy .lang .GroovyObject ;
21-
2219import java .io .FileNotFoundException ;
2320import java .util .Arrays ;
2421import java .util .Map ;
2522
23+ import groovy .lang .DelegatingMetaClass ;
24+ import groovy .lang .GroovyObject ;
25+
2626import org .junit .Before ;
2727import org .junit .Ignore ;
2828import org .junit .Test ;
6161 * @author Mark Fisher
6262 * @author Chris Beams
6363 */
64+ @ SuppressWarnings ("resource" )
6465public class GroovyScriptFactoryTests {
6566
66- @ Before
67- public void setUp () {
68- Assume .group (TestGroup .LONG_RUNNING );
69- }
70-
7167 @ Test
7268 public void testStaticScript () throws Exception {
7369 ApplicationContext ctx = new ClassPathXmlApplicationContext ("groovyContext.xml" , getClass ());
@@ -191,7 +187,8 @@ public void testScriptCompilationException() throws Exception {
191187 try {
192188 new ClassPathXmlApplicationContext ("org/springframework/scripting/groovy/groovyBrokenContext.xml" );
193189 fail ("Should throw exception for broken script file" );
194- } catch (NestedRuntimeException ex ) {
190+ }
191+ catch (NestedRuntimeException ex ) {
195192 assertTrue ("Wrong root cause: " + ex , ex .contains (ScriptCompilationException .class ));
196193 }
197194 }
@@ -205,9 +202,10 @@ public void testScriptedClassThatDoesNotHaveANoArgCtor() throws Exception {
205202 GroovyScriptFactory factory = new GroovyScriptFactory (ScriptFactoryPostProcessor .INLINE_SCRIPT_PREFIX
206203 + badScript );
207204 try {
208- factory .getScriptedObject (script , new Class <?>[] {} );
205+ factory .getScriptedObject (script );
209206 fail ("Must have thrown a ScriptCompilationException (no public no-arg ctor in scripted class)." );
210- } catch (ScriptCompilationException expected ) {
207+ }
208+ catch (ScriptCompilationException expected ) {
211209 assertTrue (expected .contains (InstantiationException .class ));
212210 }
213211 }
@@ -221,9 +219,10 @@ public void testScriptedClassThatHasNoPublicNoArgCtor() throws Exception {
221219 GroovyScriptFactory factory = new GroovyScriptFactory (ScriptFactoryPostProcessor .INLINE_SCRIPT_PREFIX
222220 + badScript );
223221 try {
224- factory .getScriptedObject (script , new Class <?>[] {} );
222+ factory .getScriptedObject (script );
225223 fail ("Must have thrown a ScriptCompilationException (no oublic no-arg ctor in scripted class)." );
226- } catch (ScriptCompilationException expected ) {
224+ }
225+ catch (ScriptCompilationException expected ) {
227226 assertTrue (expected .contains (IllegalAccessException .class ));
228227 }
229228 }
@@ -257,7 +256,8 @@ public void testCtorWithNullScriptSourceLocator() throws Exception {
257256 try {
258257 new GroovyScriptFactory (null );
259258 fail ("Must have thrown exception by this point." );
260- } catch (IllegalArgumentException expected ) {
259+ }
260+ catch (IllegalArgumentException expected ) {
261261 }
262262 }
263263
@@ -266,7 +266,8 @@ public void testCtorWithEmptyScriptSourceLocator() throws Exception {
266266 try {
267267 new GroovyScriptFactory ("" );
268268 fail ("Must have thrown exception by this point." );
269- } catch (IllegalArgumentException expected ) {
269+ }
270+ catch (IllegalArgumentException expected ) {
270271 }
271272 }
272273
@@ -275,7 +276,8 @@ public void testCtorWithWhitespacedScriptSourceLocator() throws Exception {
275276 try {
276277 new GroovyScriptFactory ("\n " );
277278 fail ("Must have thrown exception by this point." );
278- } catch (IllegalArgumentException expected ) {
279+ }
280+ catch (IllegalArgumentException expected ) {
279281 }
280282 }
281283
@@ -284,7 +286,8 @@ public void testWithInlineScriptWithLeadingWhitespace() throws Exception {
284286 try {
285287 new ClassPathXmlApplicationContext ("lwspBadGroovyContext.xml" , getClass ());
286288 fail ("Must have thrown a BeanCreationException ('inline:' prefix was preceded by whitespace" );
287- } catch (BeanCreationException expected ) {
289+ }
290+ catch (BeanCreationException expected ) {
288291 assertTrue (expected .contains (FileNotFoundException .class ));
289292 }
290293 }
@@ -296,17 +299,18 @@ public void testGetScriptedObjectDoesNotChokeOnNullInterfacesBeingPassedIn() thr
296299 given (script .suggestedClassName ()).willReturn ("someName" );
297300
298301 GroovyScriptFactory factory = new GroovyScriptFactory ("a script source locator (doesn't matter here)" );
299- Object scriptedObject = factory .getScriptedObject (script , null );
302+ Object scriptedObject = factory .getScriptedObject (script );
300303 assertNotNull (scriptedObject );
301304 }
302305
303306 @ Test
304307 public void testGetScriptedObjectDoesChokeOnNullScriptSourceBeingPassedIn () throws Exception {
305308 GroovyScriptFactory factory = new GroovyScriptFactory ("a script source locator (doesn't matter here)" );
306309 try {
307- factory .getScriptedObject (null , null );
310+ factory .getScriptedObject (null );
308311 fail ("Must have thrown a NullPointerException as per contract ('null' ScriptSource supplied" );
309- } catch (NullPointerException expected ) {
312+ }
313+ catch (NullPointerException expected ) {
310314 }
311315 }
312316
@@ -395,15 +399,14 @@ public void testRefreshableFromTagProxyTargetClass() throws Exception {
395399 public void testProxyTargetClassNotAllowedIfNotGroovy () throws Exception {
396400 try {
397401 new ClassPathXmlApplicationContext ("jruby-with-xsd-proxy-target-class.xml" , getClass ());
398- } catch (BeanCreationException e ) {
399- assertTrue (e .getMessage ().contains ("Cannot use proxyTargetClass=true" ));
402+ }
403+ catch (BeanCreationException ex ) {
404+ assertTrue (ex .getMessage ().contains ("Cannot use proxyTargetClass=true" ));
400405 }
401406 }
402407
403408 @ Test
404409 public void testAnonymousScriptDetected () throws Exception {
405- Assume .group (TestGroup .LONG_RUNNING );
406-
407410 ApplicationContext ctx = new ClassPathXmlApplicationContext ("groovy-with-xsd.xml" , getClass ());
408411 Map <?, Messenger > beans = ctx .getBeansOfType (Messenger .class );
409412 assertEquals (4 , beans .size ());
@@ -431,7 +434,8 @@ public void testCanPassInMoreThanOneProperty() {
431434 try {
432435 ctx .getBean ("bean3" );
433436 fail ("Should have thrown BeanCreationException" );
434- } catch (BeanCreationException ex ) {
437+ }
438+ catch (BeanCreationException ex ) {
435439 // expected
436440 assertTrue (ex .contains (UnsatisfiedDependencyException .class ));
437441 }
@@ -454,7 +458,8 @@ private void testMetaClass(final String xmlFile) {
454458 Calculator calc = (Calculator ) ctx .getBean ("delegatingCalculator" );
455459 calc .add (1 , 2 );
456460 fail ("expected IllegalStateException" );
457- } catch (IllegalStateException ex ) {
461+ }
462+ catch (IllegalStateException ex ) {
458463 assertEquals ("Gotcha" , ex .getMessage ());
459464 }
460465 }
@@ -479,16 +484,18 @@ public void testRefreshableFactoryBean() {
479484 assertEquals ("test" , result );
480485 }
481486
487+
482488 public static class TestCustomizer implements GroovyObjectCustomizer {
483489
484490 @ Override
485491 public void customize (GroovyObject goo ) {
486492 DelegatingMetaClass dmc = new DelegatingMetaClass (goo .getMetaClass ()) {
487493 @ Override
488494 public Object invokeMethod (Object arg0 , String mName , Object [] arg2 ) {
489- if (mName .indexOf ("Missing" ) != - 1 ) {
495+ if (mName .contains ("Missing" )) {
490496 throw new IllegalStateException ("Gotcha" );
491- } else {
497+ }
498+ else {
492499 return super .invokeMethod (arg0 , mName , arg2 );
493500 }
494501 }
0 commit comments