From a4743c07d423d4f088d127eb165e9ac1dbfa0d78 Mon Sep 17 00:00:00 2001 From: Juergen Hoeller Date: Tue, 19 Jul 2016 20:09:00 +0200 Subject: [PATCH] Polishing --- .../annotation/ArgumentBindingTests.java | 19 +++++++----------- .../beans/factory/xml/import.xml | 2 +- .../MethodNameBasedMBeanInfoAssembler.java | 2 +- .../autoproxy/AnnotationBindingTests.java | 9 +++++---- ...StatelessSessionProxyFactoryBeanTests.java | 8 ++++---- ...StatelessSessionProxyFactoryBeanTests.java | 11 +++++----- ...ameBasedMBeanInfoAssemblerMappedTests.java | 2 +- ...ethodNameBasedMBeanInfoAssemblerTests.java | 2 +- .../groovy/GroovyScriptFactoryTests.java | 20 ++++++------------- .../core/annotation/AnnotationAttributes.java | 3 ++- .../core/annotation/AnnotationUtils.java | 4 ++-- .../core/SerializableTypeWrapperTests.java | 2 +- .../support/MessageHeaderAccessor.java | 2 +- .../util/HtmlCharacterEntityReferences.dtd | 12 +++++------ 14 files changed, 42 insertions(+), 56 deletions(-) diff --git a/spring-aop/src/test/java/org/springframework/aop/aspectj/annotation/ArgumentBindingTests.java b/spring-aop/src/test/java/org/springframework/aop/aspectj/annotation/ArgumentBindingTests.java index 424505004d..000bf63d76 100644 --- a/spring-aop/src/test/java/org/springframework/aop/aspectj/annotation/ArgumentBindingTests.java +++ b/spring-aop/src/test/java/org/springframework/aop/aspectj/annotation/ArgumentBindingTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2013 the original author or authors. + * Copyright 2002-2016 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. @@ -37,7 +37,7 @@ import static org.junit.Assert.*; * @author Juergen Hoeller * @author Chris Beams */ -public final class ArgumentBindingTests { +public class ArgumentBindingTests { @Test(expected=IllegalArgumentException.class) public void testBindingInPointcutUsedByAdvice() { @@ -45,8 +45,8 @@ public final class ArgumentBindingTests { AspectJProxyFactory proxyFactory = new AspectJProxyFactory(tb); proxyFactory.addAspect(NamedPointcutWithArgs.class); - ITestBean proxiedTestBean = (ITestBean) proxyFactory.getProxy(); - proxiedTestBean.setName("Supercalifragalisticexpialidocious"); // should throw + ITestBean proxiedTestBean = proxyFactory.getProxy(); + proxiedTestBean.setName("Supercalifragalisticexpialidocious"); } @Test(expected=IllegalStateException.class) @@ -55,8 +55,8 @@ public final class ArgumentBindingTests { AspectJProxyFactory proxyFactory = new AspectJProxyFactory(tb); proxyFactory.addAspect(PointcutWithAnnotationArgument.class); - ITransactionalBean proxiedTestBean = (ITransactionalBean) proxyFactory.getProxy(); - proxiedTestBean.doInTransaction(); // should throw + ITransactionalBean proxiedTestBean = proxyFactory.getProxy(); + proxiedTestBean.doInTransaction(); } @Test @@ -71,6 +71,7 @@ public final class ArgumentBindingTests { assertEquals("formal", pnames[0]); } + public void methodWithOneParam(String aParam) { } @@ -100,9 +101,6 @@ public final class ArgumentBindingTests { } -/** - * @author Juergen Hoeller - */ @Aspect class PointcutWithAnnotationArgument { @@ -115,9 +113,6 @@ class PointcutWithAnnotationArgument { } -/** - * @author Adrian Colyer - */ @Aspect class NamedPointcutWithArgs { diff --git a/spring-beans/src/test/resources/org/springframework/beans/factory/xml/import.xml b/spring-beans/src/test/resources/org/springframework/beans/factory/xml/import.xml index 96446f02ba..278e5dff81 100644 --- a/spring-beans/src/test/resources/org/springframework/beans/factory/xml/import.xml +++ b/spring-beans/src/test/resources/org/springframework/beans/factory/xml/import.xml @@ -1,5 +1,5 @@ - + diff --git a/spring-context/src/main/java/org/springframework/jmx/export/assembler/MethodNameBasedMBeanInfoAssembler.java b/spring-context/src/main/java/org/springframework/jmx/export/assembler/MethodNameBasedMBeanInfoAssembler.java index b3c572984e..f36ffedfa1 100644 --- a/spring-context/src/main/java/org/springframework/jmx/export/assembler/MethodNameBasedMBeanInfoAssembler.java +++ b/spring-context/src/main/java/org/springframework/jmx/export/assembler/MethodNameBasedMBeanInfoAssembler.java @@ -72,7 +72,7 @@ public class MethodNameBasedMBeanInfoAssembler extends AbstractConfigurableMBean * @param methodNames an array of method names indicating the methods to use * @see #setMethodMappings */ - public void setManagedMethods(String[] methodNames) { + public void setManagedMethods(String... methodNames) { this.managedMethods = new HashSet<>(Arrays.asList(methodNames)); } diff --git a/spring-context/src/test/java/org/springframework/aop/aspectj/autoproxy/AnnotationBindingTests.java b/spring-context/src/test/java/org/springframework/aop/aspectj/autoproxy/AnnotationBindingTests.java index 82b20d9663..a7f24b51ba 100644 --- a/spring-context/src/test/java/org/springframework/aop/aspectj/autoproxy/AnnotationBindingTests.java +++ b/spring-context/src/test/java/org/springframework/aop/aspectj/autoproxy/AnnotationBindingTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2012 the original author or authors. + * Copyright 2002-2016 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. @@ -27,18 +27,19 @@ import static org.junit.Assert.*; * @author Adrian Colyer * @author Chris Beams */ -public final class AnnotationBindingTests { +public class AnnotationBindingTests { private AnnotatedTestBean testBean; + @Before public void setUp() { ClassPathXmlApplicationContext ctx = - new ClassPathXmlApplicationContext(getClass().getSimpleName() + "-context.xml", getClass()); - + new ClassPathXmlApplicationContext(getClass().getSimpleName() + "-context.xml", getClass()); testBean = (AnnotatedTestBean) ctx.getBean("testBean"); } + @Test public void testAnnotationBindingInAroundAdvice() { assertEquals("this value", testBean.doThis()); diff --git a/spring-context/src/test/java/org/springframework/ejb/access/LocalStatelessSessionProxyFactoryBeanTests.java b/spring-context/src/test/java/org/springframework/ejb/access/LocalStatelessSessionProxyFactoryBeanTests.java index 9fbf0bbd7d..29b40fc196 100644 --- a/spring-context/src/test/java/org/springframework/ejb/access/LocalStatelessSessionProxyFactoryBeanTests.java +++ b/spring-context/src/test/java/org/springframework/ejb/access/LocalStatelessSessionProxyFactoryBeanTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2013 the original author or authors. + * Copyright 2002-2016 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. @@ -182,19 +182,19 @@ public class LocalStatelessSessionProxyFactoryBeanTests { } - public static interface MyHome extends EJBLocalHome { + public interface MyHome extends EJBLocalHome { MyBusinessMethods create() throws CreateException; } - public static interface MyBusinessMethods { + public interface MyBusinessMethods { int getValue(); } - public static interface MyEjb extends EJBLocalObject, MyBusinessMethods { + public interface MyEjb extends EJBLocalObject, MyBusinessMethods { } } diff --git a/spring-context/src/test/java/org/springframework/ejb/access/SimpleRemoteStatelessSessionProxyFactoryBeanTests.java b/spring-context/src/test/java/org/springframework/ejb/access/SimpleRemoteStatelessSessionProxyFactoryBeanTests.java index 8efc5b5740..2d62ee7394 100644 --- a/spring-context/src/test/java/org/springframework/ejb/access/SimpleRemoteStatelessSessionProxyFactoryBeanTests.java +++ b/spring-context/src/test/java/org/springframework/ejb/access/SimpleRemoteStatelessSessionProxyFactoryBeanTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2013 the original author or authors. + * Copyright 2002-2016 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. @@ -279,26 +279,25 @@ public class SimpleRemoteStatelessSessionProxyFactoryBeanTests extends SimpleRem } - protected static interface MyHome extends EJBHome { + protected interface MyHome extends EJBHome { MyBusinessMethods create() throws CreateException, RemoteException; } - protected static interface MyBusinessMethods { + protected interface MyBusinessMethods { int getValue() throws RemoteException; } - protected static interface MyLocalBusinessMethods { + protected interface MyLocalBusinessMethods { int getValue(); } - protected static interface MyEjb extends EJBObject, MyBusinessMethods { - + protected interface MyEjb extends EJBObject, MyBusinessMethods { } } diff --git a/spring-context/src/test/java/org/springframework/jmx/export/assembler/MethodNameBasedMBeanInfoAssemblerMappedTests.java b/spring-context/src/test/java/org/springframework/jmx/export/assembler/MethodNameBasedMBeanInfoAssemblerMappedTests.java index 21efe0ba52..9b8ec774e0 100644 --- a/spring-context/src/test/java/org/springframework/jmx/export/assembler/MethodNameBasedMBeanInfoAssemblerMappedTests.java +++ b/spring-context/src/test/java/org/springframework/jmx/export/assembler/MethodNameBasedMBeanInfoAssemblerMappedTests.java @@ -47,7 +47,7 @@ public class MethodNameBasedMBeanInfoAssemblerMappedTests extends AbstractJmxAss public void testWithFallThrough() throws Exception { MethodNameBasedMBeanInfoAssembler assembler = getWithMapping("foobar", "add,myOperation,getName,setName,getAge"); - assembler.setManagedMethods(new String[]{"getNickName", "setNickName"}); + assembler.setManagedMethods("getNickName", "setNickName"); ModelMBeanInfo inf = assembler.getMBeanInfo(getBean(), getObjectName()); MBeanAttributeInfo attr = inf.getAttribute("NickName"); diff --git a/spring-context/src/test/java/org/springframework/jmx/export/assembler/MethodNameBasedMBeanInfoAssemblerTests.java b/spring-context/src/test/java/org/springframework/jmx/export/assembler/MethodNameBasedMBeanInfoAssemblerTests.java index 3b51e92bc8..dae9a8a367 100644 --- a/spring-context/src/test/java/org/springframework/jmx/export/assembler/MethodNameBasedMBeanInfoAssemblerTests.java +++ b/spring-context/src/test/java/org/springframework/jmx/export/assembler/MethodNameBasedMBeanInfoAssemblerTests.java @@ -52,7 +52,7 @@ public class MethodNameBasedMBeanInfoAssemblerTests extends AbstractJmxAssembler @Override protected MBeanInfoAssembler getAssembler() { MethodNameBasedMBeanInfoAssembler assembler = new MethodNameBasedMBeanInfoAssembler(); - assembler.setManagedMethods(new String[] {"add", "myOperation", "getName", "setName", "getAge"}); + assembler.setManagedMethods("add", "myOperation", "getName", "setName", "getAge"); return assembler; } 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 48f74e9247..ec2214629e 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 @@ -28,7 +28,6 @@ import org.springframework.aop.support.AopUtils; import org.springframework.aop.target.dynamic.Refreshable; import org.springframework.beans.factory.BeanCreationException; import org.springframework.beans.factory.FactoryBean; -import org.springframework.beans.factory.UnsatisfiedDependencyException; import org.springframework.beans.factory.config.BeanDefinition; import org.springframework.context.ApplicationContext; import org.springframework.context.support.ClassPathXmlApplicationContext; @@ -268,7 +267,7 @@ public class GroovyScriptFactoryTests { @Test public void testScriptedClassThatDoesNotHaveANoArgCtor() throws Exception { ScriptSource script = mock(ScriptSource.class); - final String badScript = "class Foo { public Foo(String foo) {}}"; + String badScript = "class Foo { public Foo(String foo) {}}"; given(script.getScriptAsString()).willReturn(badScript); given(script.suggestedClassName()).willReturn("someName"); GroovyScriptFactory factory = new GroovyScriptFactory(ScriptFactoryPostProcessor.INLINE_SCRIPT_PREFIX @@ -278,25 +277,18 @@ public class GroovyScriptFactoryTests { fail("Must have thrown a ScriptCompilationException (no public no-arg ctor in scripted class)."); } catch (ScriptCompilationException expected) { - assertTrue(expected.contains(InstantiationException.class)); + assertTrue(expected.contains(NoSuchMethodException.class)); } } @Test public void testScriptedClassThatHasNoPublicNoArgCtor() throws Exception { ScriptSource script = mock(ScriptSource.class); - final String badScript = "class Foo { protected Foo() {}}"; + String badScript = "class Foo { protected Foo() {} \n String toString() { 'X' }}"; given(script.getScriptAsString()).willReturn(badScript); given(script.suggestedClassName()).willReturn("someName"); - GroovyScriptFactory factory = new GroovyScriptFactory(ScriptFactoryPostProcessor.INLINE_SCRIPT_PREFIX - + badScript); - try { - factory.getScriptedObject(script); - fail("Must have thrown a ScriptCompilationException (no oublic no-arg ctor in scripted class)."); - } - catch (ScriptCompilationException expected) { - assertTrue(expected.contains(IllegalAccessException.class)); - } + GroovyScriptFactory factory = new GroovyScriptFactory(ScriptFactoryPostProcessor.INLINE_SCRIPT_PREFIX + badScript); + assertEquals("X", factory.getScriptedObject(script).toString()); } @Test @@ -553,7 +545,7 @@ public class GroovyScriptFactoryTests { testMetaClass("org/springframework/scripting/groovy/calculators-with-xsd.xml"); } - private void testMetaClass(final String xmlFile) { + private void testMetaClass(String xmlFile) { // expect the exception we threw in the custom metaclass to show it got invoked try { ApplicationContext ctx = new ClassPathXmlApplicationContext(xmlFile); diff --git a/spring-core/src/main/java/org/springframework/core/annotation/AnnotationAttributes.java b/spring-core/src/main/java/org/springframework/core/annotation/AnnotationAttributes.java index 9b3f0cc10e..9a53474edd 100644 --- a/spring-core/src/main/java/org/springframework/core/annotation/AnnotationAttributes.java +++ b/spring-core/src/main/java/org/springframework/core/annotation/AnnotationAttributes.java @@ -350,7 +350,8 @@ public class AnnotationAttributes extends LinkedHashMap { } private void assertAttributePresence(String attributeName, Object attributeValue) { - Assert.notNull(attributeValue, () -> String.format("Attribute '%s' not found in attributes for annotation [%s]", + Assert.notNull(attributeValue, () -> String.format( + "Attribute '%s' not found in attributes for annotation [%s]", attributeName, this.displayName)); } diff --git a/spring-core/src/main/java/org/springframework/core/annotation/AnnotationUtils.java b/spring-core/src/main/java/org/springframework/core/annotation/AnnotationUtils.java index f1ebd1d781..72b06805d3 100644 --- a/spring-core/src/main/java/org/springframework/core/annotation/AnnotationUtils.java +++ b/spring-core/src/main/java/org/springframework/core/annotation/AnnotationUtils.java @@ -1237,8 +1237,8 @@ public abstract class AnnotationUtils { (annotatedElement != null ? annotatedElement.toString() : "unknown element"); throw new AnnotationConfigurationException(String.format( "In AnnotationAttributes for annotation [%s] declared on %s, " + - "attribute '%s' and its alias '%s' are declared with values of [%s] and [%s], " + - "but only one is permitted.", annotationType.getName(), elementAsString, + "attribute '%s' and its alias '%s' are declared with values of [%s] and [%s], " + + "but only one is permitted.", annotationType.getName(), elementAsString, attributeName, aliasedAttributeName, ObjectUtils.nullSafeToString(value), ObjectUtils.nullSafeToString(aliasedValue))); } diff --git a/spring-core/src/test/java/org/springframework/core/SerializableTypeWrapperTests.java b/spring-core/src/test/java/org/springframework/core/SerializableTypeWrapperTests.java index a9853c3894..85bad142ea 100644 --- a/spring-core/src/test/java/org/springframework/core/SerializableTypeWrapperTests.java +++ b/spring-core/src/test/java/org/springframework/core/SerializableTypeWrapperTests.java @@ -80,7 +80,7 @@ public class SerializableTypeWrapperTests { } @Test - public void forTypeParamters() throws Exception { + public void forTypeParameters() throws Exception { Type type = SerializableTypeWrapper.forTypeParameters(List.class)[0]; assertThat(type.toString(), equalTo("E")); assertSerializable(type); diff --git a/spring-messaging/src/main/java/org/springframework/messaging/support/MessageHeaderAccessor.java b/spring-messaging/src/main/java/org/springframework/messaging/support/MessageHeaderAccessor.java index 976c207b41..6975c5e874 100644 --- a/spring-messaging/src/main/java/org/springframework/messaging/support/MessageHeaderAccessor.java +++ b/spring-messaging/src/main/java/org/springframework/messaging/support/MessageHeaderAccessor.java @@ -107,7 +107,7 @@ import org.springframework.util.StringUtils; * * *

Note that the above examples aim to demonstrate the general idea of using - * header accessors. The most likely usage however is through sub-classes. + * header accessors. The most likely usage however is through subclasses. * * @author Rossen Stoyanchev * @author Juergen Hoeller diff --git a/spring-web/src/test/resources/org/springframework/web/util/HtmlCharacterEntityReferences.dtd b/spring-web/src/test/resources/org/springframework/web/util/HtmlCharacterEntityReferences.dtd index 31aa2524bf..20ea159c65 100644 --- a/spring-web/src/test/resources/org/springframework/web/util/HtmlCharacterEntityReferences.dtd +++ b/spring-web/src/test/resources/org/springframework/web/util/HtmlCharacterEntityReferences.dtd @@ -1,11 +1,9 @@ - - - - + http://www.w3.org/TR/html4/charset.html. --> + - \ No newline at end of file +