From 26271fc30cc87d293ad1eab88ca70bf205b8f07f Mon Sep 17 00:00:00 2001 From: Juergen Hoeller Date: Mon, 13 Jan 2014 23:18:31 +0100 Subject: [PATCH] Polishing --- .../scripting/bsh/BshScriptFactory.java | 1 + .../groovy/GroovyAspectIntegrationTests.java | 63 +++++++++++-------- .../scripting/groovy/GroovyAspectTests.java | 34 +++++++--- .../MockHttpServletRequestBuilder.java | 4 +- 4 files changed, 64 insertions(+), 38 deletions(-) diff --git a/spring-context/src/main/java/org/springframework/scripting/bsh/BshScriptFactory.java b/spring-context/src/main/java/org/springframework/scripting/bsh/BshScriptFactory.java index d0e63c6020..07cffc510e 100644 --- a/spring-context/src/main/java/org/springframework/scripting/bsh/BshScriptFactory.java +++ b/spring-context/src/main/java/org/springframework/scripting/bsh/BshScriptFactory.java @@ -86,6 +86,7 @@ public class BshScriptFactory implements ScriptFactory, BeanClassLoaderAware { this.scriptInterfaces = scriptInterfaces; } + @Override public void setBeanClassLoader(ClassLoader classLoader) { this.beanClassLoader = classLoader; diff --git a/spring-context/src/test/java/org/springframework/scripting/groovy/GroovyAspectIntegrationTests.java b/spring-context/src/test/java/org/springframework/scripting/groovy/GroovyAspectIntegrationTests.java index b0373d46a4..f372911ac5 100644 --- a/spring-context/src/test/java/org/springframework/scripting/groovy/GroovyAspectIntegrationTests.java +++ b/spring-context/src/test/java/org/springframework/scripting/groovy/GroovyAspectIntegrationTests.java @@ -1,12 +1,28 @@ -package org.springframework.scripting.groovy; +/* + * Copyright 2002-2013 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.fail; +package org.springframework.scripting.groovy; import org.junit.After; import org.junit.Test; + import org.springframework.context.support.GenericXmlApplicationContext; +import static org.junit.Assert.*; + /** * @author Dave Syer */ @@ -14,18 +30,9 @@ public class GroovyAspectIntegrationTests { private GenericXmlApplicationContext context; - @After - public void close() { - if (context != null) { - context.close(); - } - } - @Test public void testJavaBean() { - context = new GenericXmlApplicationContext(getClass(), getClass().getSimpleName()+"-java-context.xml"); - TestService bean = context.getBean("javaBean", TestService.class); LogUserAdvice logAdvice = context.getBean(LogUserAdvice.class); @@ -33,8 +40,9 @@ public class GroovyAspectIntegrationTests { try { bean.sayHello(); fail("Expected exception"); - } catch (RuntimeException e) { - assertEquals("TestServiceImpl", e.getMessage()); + } + catch (RuntimeException ex) { + assertEquals("TestServiceImpl", ex.getMessage()); } assertEquals(1, logAdvice.getCountThrows()); @@ -43,7 +51,6 @@ public class GroovyAspectIntegrationTests { @Test public void testGroovyBeanInterface() { context = new GenericXmlApplicationContext(getClass(), getClass().getSimpleName()+"-groovy-interface-context.xml"); - TestService bean = context.getBean("groovyBean", TestService.class); LogUserAdvice logAdvice = context.getBean(LogUserAdvice.class); @@ -51,8 +58,9 @@ public class GroovyAspectIntegrationTests { try { bean.sayHello(); fail("Expected exception"); - } catch (RuntimeException e) { - assertEquals("GroovyServiceImpl", e.getMessage()); + } + catch (RuntimeException ex) { + assertEquals("GroovyServiceImpl", ex.getMessage()); } assertEquals(1, logAdvice.getCountThrows()); } @@ -60,9 +68,7 @@ public class GroovyAspectIntegrationTests { @Test public void testGroovyBeanDynamic() { - context = new GenericXmlApplicationContext(getClass(), getClass().getSimpleName()+"-groovy-dynamic-context.xml"); - TestService bean = context.getBean("groovyBean", TestService.class); LogUserAdvice logAdvice = context.getBean(LogUserAdvice.class); @@ -70,8 +76,9 @@ public class GroovyAspectIntegrationTests { try { bean.sayHello(); fail("Expected exception"); - } catch (RuntimeException e) { - assertEquals("GroovyServiceImpl", e.getMessage()); + } + catch (RuntimeException ex) { + assertEquals("GroovyServiceImpl", ex.getMessage()); } // No proxy here because the pointcut only applies to the concrete class, not the interface assertEquals(0, logAdvice.getCountThrows()); @@ -80,9 +87,7 @@ public class GroovyAspectIntegrationTests { @Test public void testGroovyBeanProxyTargetClass() { - context = new GenericXmlApplicationContext(getClass(), getClass().getSimpleName()+"-groovy-proxy-target-class-context.xml"); - TestService bean = context.getBean("groovyBean", TestService.class); LogUserAdvice logAdvice = context.getBean(LogUserAdvice.class); @@ -90,11 +95,19 @@ public class GroovyAspectIntegrationTests { try { bean.sayHello(); fail("Expected exception"); - } catch (TestException e) { - assertEquals("GroovyServiceImpl", e.getMessage()); + } + catch (TestException ex) { + assertEquals("GroovyServiceImpl", ex.getMessage()); } assertEquals(1, logAdvice.getCountBefore()); assertEquals(1, logAdvice.getCountThrows()); } + @After + public void close() { + if (context != null) { + context.close(); + } + } + } diff --git a/spring-context/src/test/java/org/springframework/scripting/groovy/GroovyAspectTests.java b/spring-context/src/test/java/org/springframework/scripting/groovy/GroovyAspectTests.java index 789cbe7624..8f5e2d00f3 100644 --- a/spring-context/src/test/java/org/springframework/scripting/groovy/GroovyAspectTests.java +++ b/spring-context/src/test/java/org/springframework/scripting/groovy/GroovyAspectTests.java @@ -1,18 +1,33 @@ -package org.springframework.scripting.groovy; +/* + * Copyright 2002-2013 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.fail; +package org.springframework.scripting.groovy; import org.junit.Test; + import org.springframework.aop.Advisor; import org.springframework.aop.aspectj.AspectJExpressionPointcut; import org.springframework.aop.framework.ProxyFactory; import org.springframework.aop.support.DefaultPointcutAdvisor; import org.springframework.core.io.ClassPathResource; -import org.springframework.scripting.groovy.GroovyScriptFactory; import org.springframework.scripting.support.ResourceScriptSource; import org.springframework.util.ClassUtils; +import static org.junit.Assert.*; + /** * @author Dave Syer */ @@ -20,7 +35,6 @@ public class GroovyAspectTests { @Test public void testManualGroovyBeanWithUnconditionalPointcut() throws Exception { - LogUserAdvice logAdvice = new LogUserAdvice(); GroovyScriptFactory scriptFactory = new GroovyScriptFactory("GroovyServiceImpl.grv"); @@ -28,7 +42,6 @@ public class GroovyAspectTests { new ClassPathResource("GroovyServiceImpl.grv", getClass()))); testAdvice(new DefaultPointcutAdvisor(logAdvice), logAdvice, target, "GroovyServiceImpl"); - } @Test @@ -46,7 +59,6 @@ public class GroovyAspectTests { @Test public void testManualGroovyBeanWithDynamicPointcut() throws Exception { - LogUserAdvice logAdvice = new LogUserAdvice(); GroovyScriptFactory scriptFactory = new GroovyScriptFactory("GroovyServiceImpl.grv"); @@ -61,7 +73,6 @@ public class GroovyAspectTests { @Test public void testManualGroovyBeanWithDynamicPointcutProxyTargetClass() throws Exception { - LogUserAdvice logAdvice = new LogUserAdvice(); GroovyScriptFactory scriptFactory = new GroovyScriptFactory("GroovyServiceImpl.grv"); @@ -76,6 +87,7 @@ public class GroovyAspectTests { private void testAdvice(Advisor advisor, LogUserAdvice logAdvice, TestService target, String message) throws Exception { + testAdvice(advisor, logAdvice, target, message, false); } @@ -93,9 +105,11 @@ public class GroovyAspectTests { try { bean.sayHello(); fail("Expected exception"); - } catch (TestException e) { - assertEquals(message, e.getMessage()); + } + catch (TestException ex) { + assertEquals(message, ex.getMessage()); } assertEquals(1, logAdvice.getCountThrows()); } + } diff --git a/spring-test/src/main/java/org/springframework/test/web/servlet/request/MockHttpServletRequestBuilder.java b/spring-test/src/main/java/org/springframework/test/web/servlet/request/MockHttpServletRequestBuilder.java index 0ed0bf79c5..46ba948461 100644 --- a/spring-test/src/main/java/org/springframework/test/web/servlet/request/MockHttpServletRequestBuilder.java +++ b/spring-test/src/main/java/org/springframework/test/web/servlet/request/MockHttpServletRequestBuilder.java @@ -367,8 +367,7 @@ public class MockHttpServletRequestBuilder implements RequestBuilder, Mergeable * requestURI and using any remaining part. If specified here, the pathInfo * must start with a "/". *

If specified, the pathInfo will be used as is. - * @see HttpServletRequest.getServletPath() + * @see HttpServletRequest.getServletPath() */ public MockHttpServletRequestBuilder pathInfo(String pathInfo) { if (StringUtils.hasText(pathInfo)) { @@ -464,7 +463,6 @@ public class MockHttpServletRequestBuilder implements RequestBuilder, Mergeable this.principal = parentBuilder.principal; } - for (String attributeName : parentBuilder.attributes.keySet()) { if (!this.attributes.containsKey(attributeName)) { this.attributes.put(attributeName, parentBuilder.attributes.get(attributeName)); -- GitLab