Browse Source

Polishing

(cherry picked from commit 1932a9d)
pull/1502/head
Juergen Hoeller 9 years ago
parent
commit
ab0d523cc0
  1. 23
      spring-aop/src/test/java/org/springframework/tests/aop/interceptor/NopInterceptor.java
  2. 31
      spring-aop/src/test/java/org/springframework/tests/sample/beans/SerializablePerson.java
  3. 4
      spring-beans/src/test/java/org/springframework/tests/sample/beans/TestBean.java
  4. 1
      spring-context/src/test/java/org/springframework/scheduling/annotation/AsyncExecutionTests.java
  5. 39
      spring-core/src/test/java/org/springframework/core/style/ToStringCreatorTests.java
  6. 14
      spring-core/src/test/java/org/springframework/util/MethodInvokerTests.java
  7. 8
      spring-jdbc/src/test/java/org/springframework/jdbc/object/GenericSqlQueryTests.java
  8. 4
      spring-jdbc/src/test/resources/org/springframework/jdbc/object/GenericSqlQueryTests-context.xml
  9. 9
      spring-web/src/test/java/org/springframework/http/converter/xml/Jaxb2CollectionHttpMessageConverterTests.java
  10. 3
      spring-web/src/test/java/org/springframework/web/accept/ContentNegotiationManagerFactoryBeanTests.java

23
spring-aop/src/test/java/org/springframework/tests/aop/interceptor/NopInterceptor.java

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

31
spring-aop/src/test/java/org/springframework/tests/sample/beans/SerializablePerson.java

@ -1,5 +1,5 @@ @@ -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.
@ -28,31 +28,29 @@ import org.springframework.util.ObjectUtils; @@ -28,31 +28,29 @@ import org.springframework.util.ObjectUtils;
@SuppressWarnings("serial")
public class SerializablePerson implements Person, Serializable {
private static final long serialVersionUID = 1L;
private String name;
private int age;
@Override
public int getAge() {
return age;
public String getName() {
return name;
}
@Override
public void setAge(int age) {
this.age = age;
public void setName(String name) {
this.name = name;
}
@Override
public String getName() {
return name;
public int getAge() {
return age;
}
@Override
public void setName(String name) {
this.name = name;
public void setAge(int age) {
this.age = age;
}
@Override
@ -63,10 +61,6 @@ public class SerializablePerson implements Person, Serializable { @@ -63,10 +61,6 @@ public class SerializablePerson implements Person, Serializable {
return o;
}
@Override
public int hashCode() {
return 0;
}
@Override
public boolean equals(Object other) {
@ -77,4 +71,9 @@ public class SerializablePerson implements Person, Serializable { @@ -77,4 +71,9 @@ public class SerializablePerson implements Person, Serializable {
return p.age == age && ObjectUtils.nullSafeEquals(name, p.name);
}
@Override
public int hashCode() {
return SerializablePerson.class.hashCode();
}
}

4
spring-beans/src/test/java/org/springframework/tests/sample/beans/TestBean.java

@ -1,5 +1,5 @@ @@ -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");
* you may not use this file except in compliance with the License.
@ -223,7 +223,7 @@ public class TestBean implements BeanNameAware, BeanFactoryAware, ITestBean, IOt @@ -223,7 +223,7 @@ public class TestBean implements BeanNameAware, BeanFactoryAware, ITestBean, IOt
@Override
public ITestBean[] getSpouses() {
return (spouse != null ? new ITestBean[]{spouse} : null);
return (spouse != null ? new ITestBean[] {spouse} : null);
}
public String getTouchy() {

1
spring-context/src/test/java/org/springframework/scheduling/annotation/AsyncExecutionTests.java

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

39
spring-core/src/test/java/org/springframework/core/style/ToStringCreatorTests.java

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

14
spring-core/src/test/java/org/springframework/util/MethodInvokerTests.java

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

8
spring-jdbc/src/test/java/org/springframework/jdbc/object/GenericSqlQueryTests.java

@ -29,8 +29,6 @@ import javax.sql.DataSource; @@ -29,8 +29,6 @@ import javax.sql.DataSource;
import org.junit.Before;
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.xml.XmlBeanDefinitionReader;
import org.springframework.core.io.ClassPathResource;
@ -44,12 +42,12 @@ import static org.mockito.BDDMockito.*; @@ -44,12 +42,12 @@ import static org.mockito.BDDMockito.*;
* @author Thomas Risberg
* @author Juergen Hoeller
*/
public class GenericSqlQueryTests {
public class GenericSqlQueryTests {
private static final String SELECT_ID_FORENAME_NAMED_PARAMETERS_PARSED =
"select id, forename from custmr where id = ? and country = ?";
private BeanFactory beanFactory;
private DefaultListableBeanFactory beanFactory;
private Connection connection;
@ -61,7 +59,7 @@ public class GenericSqlQueryTests { @@ -61,7 +59,7 @@ public class GenericSqlQueryTests {
@Before
public void setUp() throws Exception {
this.beanFactory = new DefaultListableBeanFactory();
new XmlBeanDefinitionReader((BeanDefinitionRegistry) this.beanFactory).loadBeanDefinitions(
new XmlBeanDefinitionReader(this.beanFactory).loadBeanDefinitions(
new ClassPathResource("org/springframework/jdbc/object/GenericSqlQueryTests-context.xml"));
DataSource dataSource = mock(DataSource.class);
this.connection = mock(Connection.class);

4
spring-jdbc/src/test/resources/org/springframework/jdbc/object/GenericSqlQueryTests-context.xml

@ -1,7 +1,7 @@ @@ -1,7 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<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"
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">
<bean id="dataSource" class="org.springframework.jdbc.datasource.TestDataSourceWrapper"/>
@ -47,7 +47,7 @@ @@ -47,7 +47,7 @@
</bean>
</list>
</property>
<property name="rowMapperClass" value="org.springframework.jdbc.object.CustomerMapper"/>
<property name="rowMapperClass" value="org.springframework.jdbc.object.CustomerMapper"/>
</bean>
<bean id="queryWithRowMapperBean" class="org.springframework.jdbc.object.GenericSqlQuery">

9
spring-web/src/test/java/org/springframework/http/converter/xml/Jaxb2CollectionHttpMessageConverterTests.java

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

3
spring-web/src/test/java/org/springframework/web/accept/ContentNegotiationManagerFactoryBeanTests.java

@ -1,5 +1,5 @@ @@ -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");
* you may not use this file except in compliance with the License.
@ -13,6 +13,7 @@ @@ -13,6 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.web.accept;
import java.util.Collections;

Loading…
Cancel
Save