Polishing

(cherry picked from commit de91b1a)
This commit is contained in:
Juergen Hoeller 2016-08-17 20:43:41 +02:00
parent c926ec477a
commit 1932a9d729
10 changed files with 67 additions and 71 deletions

View File

@ -1,6 +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"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -29,27 +28,21 @@ public class NopInterceptor implements MethodInterceptor {
private int count; private int count;
/**
* @see org.aopalliance.intercept.MethodInterceptor#invoke(MethodInvocation)
*/
@Override @Override
public Object invoke(MethodInvocation invocation) throws Throwable { public Object invoke(MethodInvocation invocation) throws Throwable {
increment(); increment();
return invocation.proceed(); return invocation.proceed();
} }
protected void increment() {
this.count++;
}
public int getCount() { public int getCount() {
return this.count; return this.count;
} }
protected void increment() {
++count;
}
@Override
public int hashCode() {
return 0;
}
@Override @Override
public boolean equals(Object other) { public boolean equals(Object other) {
@ -62,5 +55,9 @@ public class NopInterceptor implements MethodInterceptor {
return this.count == ((NopInterceptor) other).count; return this.count == ((NopInterceptor) other).count;
} }
@Override
public int hashCode() {
return NopInterceptor.class.hashCode();
}
} }

View File

@ -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"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -28,22 +28,10 @@ import org.springframework.util.ObjectUtils;
@SuppressWarnings("serial") @SuppressWarnings("serial")
public class SerializablePerson implements Person, Serializable { public class SerializablePerson implements Person, Serializable {
private static final long serialVersionUID = 1L;
private String name; private String name;
private int age; private int age;
@Override
public int getAge() {
return age;
}
@Override
public void setAge(int age) {
this.age = age;
}
@Override @Override
public String getName() { public String getName() {
@ -55,6 +43,16 @@ public class SerializablePerson implements Person, Serializable {
this.name = name; this.name = name;
} }
@Override
public int getAge() {
return age;
}
@Override
public void setAge(int age) {
this.age = age;
}
@Override @Override
public Object echo(Object o) throws Throwable { public Object echo(Object o) throws Throwable {
if (o instanceof Throwable) { if (o instanceof Throwable) {
@ -63,10 +61,6 @@ public class SerializablePerson implements Person, Serializable {
return o; return o;
} }
@Override
public int hashCode() {
return 0;
}
@Override @Override
public boolean equals(Object other) { public boolean equals(Object other) {
@ -77,4 +71,9 @@ public class SerializablePerson implements Person, Serializable {
return p.age == age && ObjectUtils.nullSafeEquals(name, p.name); return p.age == age && ObjectUtils.nullSafeEquals(name, p.name);
} }
@Override
public int hashCode() {
return SerializablePerson.class.hashCode();
}
} }

View File

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2015 the original author or authors. * Copyright 2002-2016 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -223,7 +223,7 @@ public class TestBean implements BeanNameAware, BeanFactoryAware, ITestBean, IOt
@Override @Override
public ITestBean[] getSpouses() { public ITestBean[] getSpouses() {
return (spouse != null ? new ITestBean[]{spouse} : null); return (spouse != null ? new ITestBean[] {spouse} : null);
} }
public String getTouchy() { public String getTouchy() {

View File

@ -124,6 +124,7 @@ public class AsyncExecutionTests {
context.registerBeanDefinition("autoProxyCreator", new RootBeanDefinition(DefaultAdvisorAutoProxyCreator.class)); context.registerBeanDefinition("autoProxyCreator", new RootBeanDefinition(DefaultAdvisorAutoProxyCreator.class));
context.registerBeanDefinition("asyncAdvisor", new RootBeanDefinition(AsyncAnnotationAdvisor.class)); context.registerBeanDefinition("asyncAdvisor", new RootBeanDefinition(AsyncAnnotationAdvisor.class));
context.refresh(); context.refresh();
SimpleInterface asyncTest = context.getBean("asyncTest", SimpleInterface.class); SimpleInterface asyncTest = context.getBean("asyncTest", SimpleInterface.class);
asyncTest.doNothing(5); asyncTest.doNothing(5);
asyncTest.doSomething(10); asyncTest.doSomething(10);

View File

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2015 the original author or authors. * Copyright 2002-2016 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -33,7 +33,6 @@ import static org.junit.Assert.*;
/** /**
* @author Keith Donald * @author Keith Donald
*/ */
@SuppressWarnings({ "rawtypes", "unchecked" })
public class ToStringCreatorTests { public class ToStringCreatorTests {
private SomeObject s1, s2, s3; private SomeObject s1, s2, s3;
@ -63,20 +62,20 @@ public class ToStringCreatorTests {
@Test @Test
public void defaultStyleMap() { public void defaultStyleMap() {
final Map map = getMap(); final Map<String, String> map = getMap();
Object stringy = new Object() { Object stringy = new Object() {
@Override @Override
public String toString() { public String toString() {
return new ToStringCreator(this).append("familyFavoriteSport", map).toString(); return new ToStringCreator(this).append("familyFavoriteSport", map).toString();
} }
}; };
assertEquals("[ToStringCreatorTests.4@" + ObjectUtils.getIdentityHexString(stringy) assertEquals("[ToStringCreatorTests.4@" + ObjectUtils.getIdentityHexString(stringy) +
+ " familyFavoriteSport = map['Keri' -> 'Softball', 'Scot' -> 'Fishing', 'Keith' -> 'Flag Football']]", " familyFavoriteSport = map['Keri' -> 'Softball', 'Scot' -> 'Fishing', 'Keith' -> 'Flag Football']]",
stringy.toString()); stringy.toString());
} }
private Map getMap() { private Map<String, String> getMap() {
Map map = new LinkedHashMap(3); Map<String, String> map = new LinkedHashMap<>();
map.put("Keri", "Softball"); map.put("Keri", "Softball");
map.put("Scot", "Fishing"); map.put("Scot", "Fishing");
map.put("Keith", "Flag Football"); map.put("Keith", "Flag Football");
@ -85,22 +84,22 @@ public class ToStringCreatorTests {
@Test @Test
public void defaultStyleArray() { public void defaultStyleArray() {
SomeObject[] array = new SomeObject[] { s1, s2, s3 }; SomeObject[] array = new SomeObject[] {s1, s2, s3};
String str = new ToStringCreator(array).toString(); String str = new ToStringCreator(array).toString();
assertEquals("[@" + ObjectUtils.getIdentityHexString(array) assertEquals("[@" + ObjectUtils.getIdentityHexString(array) +
+ " array<ToStringCreatorTests.SomeObject>[A, B, C]]", str); " array<ToStringCreatorTests.SomeObject>[A, B, C]]", str);
} }
@Test @Test
public void primitiveArrays() { public void primitiveArrays() {
int[] integers = new int[] { 0, 1, 2, 3, 4 }; int[] integers = new int[] {0, 1, 2, 3, 4};
String str = new ToStringCreator(integers).toString(); String str = new ToStringCreator(integers).toString();
assertEquals("[@" + ObjectUtils.getIdentityHexString(integers) + " array<Integer>[0, 1, 2, 3, 4]]", str); assertEquals("[@" + ObjectUtils.getIdentityHexString(integers) + " array<Integer>[0, 1, 2, 3, 4]]", str);
} }
@Test @Test
public void appendList() { public void appendList() {
List list = new ArrayList(); List<SomeObject> list = new ArrayList<>();
list.add(s1); list.add(s1);
list.add(s2); list.add(s2);
list.add(s3); list.add(s3);
@ -111,28 +110,26 @@ public class ToStringCreatorTests {
@Test @Test
public void appendSet() { public void appendSet() {
Set set = new LinkedHashSet<>(3); Set<SomeObject> set = new LinkedHashSet<>();
set.add(s1); set.add(s1);
set.add(s2); set.add(s2);
set.add(s3); set.add(s3);
String str = new ToStringCreator(this).append("myLetters", set).toString(); String str = new ToStringCreator(this).append("myLetters", set).toString();
assertEquals("[ToStringCreatorTests@" + ObjectUtils.getIdentityHexString(this) + " myLetters = set[A, B, C]]", assertEquals("[ToStringCreatorTests@" + ObjectUtils.getIdentityHexString(this) + " myLetters = set[A, B, C]]", str);
str);
} }
@Test @Test
public void appendClass() { public void appendClass() {
String str = new ToStringCreator(this).append("myClass", this.getClass()).toString(); String str = new ToStringCreator(this).append("myClass", this.getClass()).toString();
assertEquals("[ToStringCreatorTests@" + ObjectUtils.getIdentityHexString(this) assertEquals("[ToStringCreatorTests@" + ObjectUtils.getIdentityHexString(this) +
+ " myClass = ToStringCreatorTests]", str); " myClass = ToStringCreatorTests]", str);
} }
@Test @Test
public void appendMethod() throws Exception { public void appendMethod() throws Exception {
String str = new ToStringCreator(this).append("myMethod", this.getClass().getMethod("appendMethod")) String str = new ToStringCreator(this).append("myMethod", this.getClass().getMethod("appendMethod")).toString();
.toString(); assertEquals("[ToStringCreatorTests@" + ObjectUtils.getIdentityHexString(this) +
assertEquals("[ToStringCreatorTests@" + ObjectUtils.getIdentityHexString(this) " myMethod = appendMethod@ToStringCreatorTests]", str);
+ " myMethod = appendMethod@ToStringCreatorTests]", str);
} }

View File

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2015 the original author or authors. * Copyright 2002-2016 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -79,7 +79,7 @@ public class MethodInvokerTests {
MethodInvoker methodInvoker = new MethodInvoker(); MethodInvoker methodInvoker = new MethodInvoker();
methodInvoker.setTargetObject(new Greeter()); methodInvoker.setTargetObject(new Greeter());
methodInvoker.setTargetMethod("greet"); methodInvoker.setTargetMethod("greet");
methodInvoker.setArguments(new Object[] { new String("no match") }); methodInvoker.setArguments(new Object[] {"no match"});
exception.expect(NoSuchMethodException.class); exception.expect(NoSuchMethodException.class);
methodInvoker.prepare(); methodInvoker.prepare();
@ -199,6 +199,7 @@ public class MethodInvokerTests {
} }
} }
@SuppressWarnings("unused") @SuppressWarnings("unused")
public static class Greeter { public static class Greeter {
@ -223,13 +224,17 @@ public class MethodInvokerTests {
} }
} }
private interface Greetable { private interface Greetable {
String getGreeting(); String getGreeting();
} }
private interface Person extends Greetable { private interface Person extends Greetable {
} }
private static class Purchaser implements Greetable { private static class Purchaser implements Greetable {
@Override @Override
@ -238,6 +243,7 @@ public class MethodInvokerTests {
} }
} }
private static class Shopper extends Purchaser implements Person { private static class Shopper extends Purchaser implements Person {
@Override @Override
@ -246,6 +252,7 @@ public class MethodInvokerTests {
} }
} }
private static class Salesman implements Person { private static class Salesman implements Person {
@Override @Override
@ -254,6 +261,7 @@ public class MethodInvokerTests {
} }
} }
private static class Customer extends Shopper { private static class Customer extends Shopper {
@Override @Override
@ -262,6 +270,7 @@ public class MethodInvokerTests {
} }
} }
private static class Regular extends Customer { private static class Regular extends Customer {
private String name; private String name;
@ -276,6 +285,7 @@ public class MethodInvokerTests {
} }
} }
private static class VIP extends Regular { private static class VIP extends Regular {
public VIP(String name) { public VIP(String name) {

View File

@ -29,8 +29,6 @@ import javax.sql.DataSource;
import org.junit.Before; import org.junit.Before;
import org.junit.Test; import org.junit.Test;
import org.springframework.beans.factory.BeanFactory;
import org.springframework.beans.factory.support.BeanDefinitionRegistry;
import org.springframework.beans.factory.support.DefaultListableBeanFactory; import org.springframework.beans.factory.support.DefaultListableBeanFactory;
import org.springframework.beans.factory.xml.XmlBeanDefinitionReader; import org.springframework.beans.factory.xml.XmlBeanDefinitionReader;
import org.springframework.core.io.ClassPathResource; import org.springframework.core.io.ClassPathResource;
@ -49,7 +47,7 @@ public class GenericSqlQueryTests {
private static final String SELECT_ID_FORENAME_NAMED_PARAMETERS_PARSED = private static final String SELECT_ID_FORENAME_NAMED_PARAMETERS_PARSED =
"select id, forename from custmr where id = ? and country = ?"; "select id, forename from custmr where id = ? and country = ?";
private BeanFactory beanFactory; private DefaultListableBeanFactory beanFactory;
private Connection connection; private Connection connection;
@ -61,7 +59,7 @@ public class GenericSqlQueryTests {
@Before @Before
public void setUp() throws Exception { public void setUp() throws Exception {
this.beanFactory = new DefaultListableBeanFactory(); this.beanFactory = new DefaultListableBeanFactory();
new XmlBeanDefinitionReader((BeanDefinitionRegistry) this.beanFactory).loadBeanDefinitions( new XmlBeanDefinitionReader(this.beanFactory).loadBeanDefinitions(
new ClassPathResource("org/springframework/jdbc/object/GenericSqlQueryTests-context.xml")); new ClassPathResource("org/springframework/jdbc/object/GenericSqlQueryTests-context.xml"));
DataSource dataSource = mock(DataSource.class); DataSource dataSource = mock(DataSource.class);
this.connection = mock(Connection.class); this.connection = mock(Connection.class);

View File

@ -1,7 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" <beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:util="http://www.springframework.org/schema/util" xmlns:util="http://www.springframework.org/schema/util"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-2.5.xsd"> http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-2.5.xsd">
<bean id="dataSource" class="org.springframework.jdbc.datasource.TestDataSourceWrapper"/> <bean id="dataSource" class="org.springframework.jdbc.datasource.TestDataSourceWrapper"/>

View File

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2015 the original author or authors. * Copyright 2002-2016 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -83,7 +83,6 @@ public class Jaxb2CollectionHttpMessageConverterTests {
public void readXmlRootElementList() throws Exception { public void readXmlRootElementList() throws Exception {
String content = "<list><rootElement><type s=\"1\"/></rootElement><rootElement><type s=\"2\"/></rootElement></list>"; String content = "<list><rootElement><type s=\"1\"/></rootElement><rootElement><type s=\"2\"/></rootElement></list>";
MockHttpInputMessage inputMessage = new MockHttpInputMessage(content.getBytes("UTF-8")); MockHttpInputMessage inputMessage = new MockHttpInputMessage(content.getBytes("UTF-8"));
List<RootElement> result = (List<RootElement>) converter.read(rootElementListType, null, inputMessage); List<RootElement> result = (List<RootElement>) converter.read(rootElementListType, null, inputMessage);
assertEquals("Invalid result", 2, result.size()); assertEquals("Invalid result", 2, result.size());
@ -96,7 +95,6 @@ public class Jaxb2CollectionHttpMessageConverterTests {
public void readXmlRootElementSet() throws Exception { public void readXmlRootElementSet() throws Exception {
String content = "<set><rootElement><type s=\"1\"/></rootElement><rootElement><type s=\"2\"/></rootElement></set>"; String content = "<set><rootElement><type s=\"1\"/></rootElement><rootElement><type s=\"2\"/></rootElement></set>";
MockHttpInputMessage inputMessage = new MockHttpInputMessage(content.getBytes("UTF-8")); MockHttpInputMessage inputMessage = new MockHttpInputMessage(content.getBytes("UTF-8"));
Set<RootElement> result = (Set<RootElement>) converter.read(rootElementSetType, null, inputMessage); Set<RootElement> result = (Set<RootElement>) converter.read(rootElementSetType, null, inputMessage);
assertEquals("Invalid result", 2, result.size()); assertEquals("Invalid result", 2, result.size());
@ -109,7 +107,6 @@ public class Jaxb2CollectionHttpMessageConverterTests {
public void readXmlTypeList() throws Exception { public void readXmlTypeList() throws Exception {
String content = "<list><foo s=\"1\"/><bar s=\"2\"/></list>"; String content = "<list><foo s=\"1\"/><bar s=\"2\"/></list>";
MockHttpInputMessage inputMessage = new MockHttpInputMessage(content.getBytes("UTF-8")); MockHttpInputMessage inputMessage = new MockHttpInputMessage(content.getBytes("UTF-8"));
List<TestType> result = (List<TestType>) converter.read(typeListType, null, inputMessage); List<TestType> result = (List<TestType>) converter.read(typeListType, null, inputMessage);
assertEquals("Invalid result", 2, result.size()); assertEquals("Invalid result", 2, result.size());
@ -122,7 +119,6 @@ public class Jaxb2CollectionHttpMessageConverterTests {
public void readXmlTypeSet() throws Exception { public void readXmlTypeSet() throws Exception {
String content = "<set><foo s=\"1\"/><bar s=\"2\"/></set>"; String content = "<set><foo s=\"1\"/><bar s=\"2\"/></set>";
MockHttpInputMessage inputMessage = new MockHttpInputMessage(content.getBytes("UTF-8")); MockHttpInputMessage inputMessage = new MockHttpInputMessage(content.getBytes("UTF-8"));
Set<TestType> result = (Set<TestType>) converter.read(typeSetType, null, inputMessage); Set<TestType> result = (Set<TestType>) converter.read(typeSetType, null, inputMessage);
assertEquals("Invalid result", 2, result.size()); assertEquals("Invalid result", 2, result.size());
@ -133,7 +129,6 @@ public class Jaxb2CollectionHttpMessageConverterTests {
@Test @Test
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
public void readXmlRootElementExternalEntityDisabled() throws Exception { public void readXmlRootElementExternalEntityDisabled() throws Exception {
Resource external = new ClassPathResource("external.txt", getClass()); Resource external = new ClassPathResource("external.txt", getClass());
String content = "<!DOCTYPE root [" + String content = "<!DOCTYPE root [" +
" <!ELEMENT external ANY >\n" + " <!ELEMENT external ANY >\n" +
@ -142,7 +137,6 @@ public class Jaxb2CollectionHttpMessageConverterTests {
MockHttpInputMessage inputMessage = new MockHttpInputMessage(content.getBytes("UTF-8")); MockHttpInputMessage inputMessage = new MockHttpInputMessage(content.getBytes("UTF-8"));
converter = new Jaxb2CollectionHttpMessageConverter<Collection<Object>>() { converter = new Jaxb2CollectionHttpMessageConverter<Collection<Object>>() {
@Override @Override
protected XMLInputFactory createXmlInputFactory() { protected XMLInputFactory createXmlInputFactory() {
XMLInputFactory inputFactory = super.createXmlInputFactory(); XMLInputFactory inputFactory = super.createXmlInputFactory();
@ -164,7 +158,6 @@ public class Jaxb2CollectionHttpMessageConverterTests {
@Test @Test
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
public void readXmlRootElementExternalEntityEnabled() throws Exception { public void readXmlRootElementExternalEntityEnabled() throws Exception {
Resource external = new ClassPathResource("external.txt", getClass()); Resource external = new ClassPathResource("external.txt", getClass());
String content = "<!DOCTYPE root [" + String content = "<!DOCTYPE root [" +
" <!ELEMENT external ANY >\n" + " <!ELEMENT external ANY >\n" +

View File

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2015 the original author or authors. * Copyright 2002-2016 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -13,6 +13,7 @@
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
*/ */
package org.springframework.web.accept; package org.springframework.web.accept;
import java.util.Collections; import java.util.Collections;