diff --git a/spring-context/src/test/java/org/springframework/scripting/groovy/GroovyScriptFactoryTests.java b/spring-context/src/test/java/org/springframework/scripting/groovy/GroovyScriptFactoryTests.java index 7ced7671ce3..99c12ad0987 100644 --- a/spring-context/src/test/java/org/springframework/scripting/groovy/GroovyScriptFactoryTests.java +++ b/spring-context/src/test/java/org/springframework/scripting/groovy/GroovyScriptFactoryTests.java @@ -16,13 +16,13 @@ package org.springframework.scripting.groovy; -import groovy.lang.DelegatingMetaClass; -import groovy.lang.GroovyObject; - import java.io.FileNotFoundException; import java.util.Arrays; import java.util.Map; +import groovy.lang.DelegatingMetaClass; +import groovy.lang.GroovyObject; + import org.junit.Before; import org.junit.Ignore; import org.junit.Test; @@ -61,13 +61,9 @@ import static org.mockito.BDDMockito.*; * @author Mark Fisher * @author Chris Beams */ +@SuppressWarnings("resource") public class GroovyScriptFactoryTests { - @Before - public void setUp() { - Assume.group(TestGroup.LONG_RUNNING); - } - @Test public void testStaticScript() throws Exception { ApplicationContext ctx = new ClassPathXmlApplicationContext("groovyContext.xml", getClass()); @@ -191,7 +187,8 @@ public class GroovyScriptFactoryTests { try { new ClassPathXmlApplicationContext("org/springframework/scripting/groovy/groovyBrokenContext.xml"); fail("Should throw exception for broken script file"); - } catch (NestedRuntimeException ex) { + } + catch (NestedRuntimeException ex) { assertTrue("Wrong root cause: " + ex, ex.contains(ScriptCompilationException.class)); } } @@ -205,9 +202,10 @@ public class GroovyScriptFactoryTests { GroovyScriptFactory factory = new GroovyScriptFactory(ScriptFactoryPostProcessor.INLINE_SCRIPT_PREFIX + badScript); try { - factory.getScriptedObject(script, new Class[] {}); + factory.getScriptedObject(script); fail("Must have thrown a ScriptCompilationException (no public no-arg ctor in scripted class)."); - } catch (ScriptCompilationException expected) { + } + catch (ScriptCompilationException expected) { assertTrue(expected.contains(InstantiationException.class)); } } @@ -221,9 +219,10 @@ public class GroovyScriptFactoryTests { GroovyScriptFactory factory = new GroovyScriptFactory(ScriptFactoryPostProcessor.INLINE_SCRIPT_PREFIX + badScript); try { - factory.getScriptedObject(script, new Class[] {}); + factory.getScriptedObject(script); fail("Must have thrown a ScriptCompilationException (no oublic no-arg ctor in scripted class)."); - } catch (ScriptCompilationException expected) { + } + catch (ScriptCompilationException expected) { assertTrue(expected.contains(IllegalAccessException.class)); } } @@ -257,7 +256,8 @@ public class GroovyScriptFactoryTests { try { new GroovyScriptFactory(null); fail("Must have thrown exception by this point."); - } catch (IllegalArgumentException expected) { + } + catch (IllegalArgumentException expected) { } } @@ -266,7 +266,8 @@ public class GroovyScriptFactoryTests { try { new GroovyScriptFactory(""); fail("Must have thrown exception by this point."); - } catch (IllegalArgumentException expected) { + } + catch (IllegalArgumentException expected) { } } @@ -275,7 +276,8 @@ public class GroovyScriptFactoryTests { try { new GroovyScriptFactory("\n "); fail("Must have thrown exception by this point."); - } catch (IllegalArgumentException expected) { + } + catch (IllegalArgumentException expected) { } } @@ -284,7 +286,8 @@ public class GroovyScriptFactoryTests { try { new ClassPathXmlApplicationContext("lwspBadGroovyContext.xml", getClass()); fail("Must have thrown a BeanCreationException ('inline:' prefix was preceded by whitespace"); - } catch (BeanCreationException expected) { + } + catch (BeanCreationException expected) { assertTrue(expected.contains(FileNotFoundException.class)); } } @@ -296,7 +299,7 @@ public class GroovyScriptFactoryTests { given(script.suggestedClassName()).willReturn("someName"); GroovyScriptFactory factory = new GroovyScriptFactory("a script source locator (doesn't matter here)"); - Object scriptedObject = factory.getScriptedObject(script, null); + Object scriptedObject = factory.getScriptedObject(script); assertNotNull(scriptedObject); } @@ -304,9 +307,10 @@ public class GroovyScriptFactoryTests { public void testGetScriptedObjectDoesChokeOnNullScriptSourceBeingPassedIn() throws Exception { GroovyScriptFactory factory = new GroovyScriptFactory("a script source locator (doesn't matter here)"); try { - factory.getScriptedObject(null, null); + factory.getScriptedObject(null); fail("Must have thrown a NullPointerException as per contract ('null' ScriptSource supplied"); - } catch (NullPointerException expected) { + } + catch (NullPointerException expected) { } } @@ -395,15 +399,14 @@ public class GroovyScriptFactoryTests { public void testProxyTargetClassNotAllowedIfNotGroovy() throws Exception { try { new ClassPathXmlApplicationContext("jruby-with-xsd-proxy-target-class.xml", getClass()); - } catch (BeanCreationException e) { - assertTrue(e.getMessage().contains("Cannot use proxyTargetClass=true")); + } + catch (BeanCreationException ex) { + assertTrue(ex.getMessage().contains("Cannot use proxyTargetClass=true")); } } @Test public void testAnonymousScriptDetected() throws Exception { - Assume.group(TestGroup.LONG_RUNNING); - ApplicationContext ctx = new ClassPathXmlApplicationContext("groovy-with-xsd.xml", getClass()); Map beans = ctx.getBeansOfType(Messenger.class); assertEquals(4, beans.size()); @@ -431,7 +434,8 @@ public class GroovyScriptFactoryTests { try { ctx.getBean("bean3"); fail("Should have thrown BeanCreationException"); - } catch (BeanCreationException ex) { + } + catch (BeanCreationException ex) { // expected assertTrue(ex.contains(UnsatisfiedDependencyException.class)); } @@ -454,7 +458,8 @@ public class GroovyScriptFactoryTests { Calculator calc = (Calculator) ctx.getBean("delegatingCalculator"); calc.add(1, 2); fail("expected IllegalStateException"); - } catch (IllegalStateException ex) { + } + catch (IllegalStateException ex) { assertEquals("Gotcha", ex.getMessage()); } } @@ -479,6 +484,7 @@ public class GroovyScriptFactoryTests { assertEquals("test", result); } + public static class TestCustomizer implements GroovyObjectCustomizer { @Override @@ -486,9 +492,10 @@ public class GroovyScriptFactoryTests { DelegatingMetaClass dmc = new DelegatingMetaClass(goo.getMetaClass()) { @Override public Object invokeMethod(Object arg0, String mName, Object[] arg2) { - if (mName.indexOf("Missing") != -1) { + if (mName.contains("Missing")) { throw new IllegalStateException("Gotcha"); - } else { + } + else { return super.invokeMethod(arg0, mName, arg2); } } diff --git a/spring-context/src/test/java/org/springframework/scripting/jruby/JRubyScriptFactoryTests.java b/spring-context/src/test/java/org/springframework/scripting/jruby/JRubyScriptFactoryTests.java index 55f3016d81b..0c45266dbf8 100644 --- a/spring-context/src/test/java/org/springframework/scripting/jruby/JRubyScriptFactoryTests.java +++ b/spring-context/src/test/java/org/springframework/scripting/jruby/JRubyScriptFactoryTests.java @@ -18,11 +18,10 @@ package org.springframework.scripting.jruby; import java.util.Map; -import org.junit.Before; import org.junit.Test; + import org.springframework.aop.support.AopUtils; import org.springframework.aop.target.dynamic.Refreshable; -import org.springframework.tests.sample.beans.TestBean; import org.springframework.beans.factory.BeanCreationException; import org.springframework.context.ApplicationContext; import org.springframework.context.support.ClassPathXmlApplicationContext; @@ -31,8 +30,7 @@ import org.springframework.scripting.ConfigurableMessenger; import org.springframework.scripting.Messenger; import org.springframework.scripting.ScriptCompilationException; import org.springframework.scripting.TestBeanAwareMessenger; -import org.springframework.tests.Assume; -import org.springframework.tests.TestGroup; +import org.springframework.tests.sample.beans.TestBean; import static org.junit.Assert.*; @@ -50,10 +48,6 @@ public class JRubyScriptFactoryTests { "end\n" + "RubyBar.new"; - @Before - public void setUp() { - Assume.group(TestGroup.LONG_RUNNING); - } @Test public void testStaticScript() throws Exception { @@ -106,7 +100,7 @@ public class JRubyScriptFactoryTests { @Test public void testCtorWithNullScriptSourceLocator() throws Exception { try { - new JRubyScriptFactory(null, new Class[]{Messenger.class}); + new JRubyScriptFactory(null, Messenger.class); fail("Must have thrown exception by this point."); } catch (IllegalArgumentException expected) { @@ -116,7 +110,7 @@ public class JRubyScriptFactoryTests { @Test public void testCtorWithEmptyScriptSourceLocator() throws Exception { try { - new JRubyScriptFactory("", new Class[]{Messenger.class}); + new JRubyScriptFactory("", Messenger.class); fail("Must have thrown exception by this point."); } catch (IllegalArgumentException expected) { @@ -126,7 +120,7 @@ public class JRubyScriptFactoryTests { @Test public void testCtorWithWhitespacedScriptSourceLocator() throws Exception { try { - new JRubyScriptFactory("\n ", new Class[]{Messenger.class}); + new JRubyScriptFactory("\n ", Messenger.class); fail("Must have thrown exception by this point."); } catch (IllegalArgumentException expected) { @@ -136,7 +130,7 @@ public class JRubyScriptFactoryTests { @Test public void testCtorWithNullScriptInterfacesArray() throws Exception { try { - new JRubyScriptFactory(RUBY_SCRIPT_SOURCE_LOCATOR, null); + new JRubyScriptFactory(RUBY_SCRIPT_SOURCE_LOCATOR); fail("Must have thrown exception by this point."); } catch (IllegalArgumentException expected) { @@ -291,7 +285,7 @@ public class JRubyScriptFactoryTests { } @Test - public void testAOP() throws Exception { + public void testAop() throws Exception { ApplicationContext ctx = new ClassPathXmlApplicationContext("jruby-aop.xml", getClass()); Messenger messenger = (Messenger) ctx.getBean("messenger"); assertEquals(new StringBuffer("Hello World!").reverse().toString(), messenger.getMessage());