diff --git a/spring-aop/src/test/java/org/springframework/tests/aop/interceptor/NopInterceptor.java b/spring-aop/src/test/java/org/springframework/tests/aop/interceptor/NopInterceptor.java index 95dff09cc04..de49c8af7fc 100644 --- a/spring-aop/src/test/java/org/springframework/tests/aop/interceptor/NopInterceptor.java +++ b/spring-aop/src/test/java/org/springframework/tests/aop/interceptor/NopInterceptor.java @@ -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 { 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 { return this.count == ((NopInterceptor) other).count; } + @Override + public int hashCode() { + return NopInterceptor.class.hashCode(); + } } diff --git a/spring-aop/src/test/java/org/springframework/tests/sample/beans/SerializablePerson.java b/spring-aop/src/test/java/org/springframework/tests/sample/beans/SerializablePerson.java index 805dabd41ad..bfa856144a5 100644 --- a/spring-aop/src/test/java/org/springframework/tests/sample/beans/SerializablePerson.java +++ b/spring-aop/src/test/java/org/springframework/tests/sample/beans/SerializablePerson.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. @@ -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 { return o; } - @Override - public int hashCode() { - return 0; - } @Override public boolean equals(Object other) { @@ -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(); + } + } diff --git a/spring-beans/src/test/java/org/springframework/tests/sample/beans/TestBean.java b/spring-beans/src/test/java/org/springframework/tests/sample/beans/TestBean.java index da243abbc93..f1ee1d4df5d 100644 --- a/spring-beans/src/test/java/org/springframework/tests/sample/beans/TestBean.java +++ b/spring-beans/src/test/java/org/springframework/tests/sample/beans/TestBean.java @@ -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 @Override public ITestBean[] getSpouses() { - return (spouse != null ? new ITestBean[]{spouse} : null); + return (spouse != null ? new ITestBean[] {spouse} : null); } public String getTouchy() { diff --git a/spring-context/src/test/java/org/springframework/scheduling/annotation/AsyncExecutionTests.java b/spring-context/src/test/java/org/springframework/scheduling/annotation/AsyncExecutionTests.java index d431ca90bde..f02dc2a3316 100644 --- a/spring-context/src/test/java/org/springframework/scheduling/annotation/AsyncExecutionTests.java +++ b/spring-context/src/test/java/org/springframework/scheduling/annotation/AsyncExecutionTests.java @@ -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); diff --git a/spring-core/src/test/java/org/springframework/core/style/ToStringCreatorTests.java b/spring-core/src/test/java/org/springframework/core/style/ToStringCreatorTests.java index dbafa1bbf79..f5f68df7075 100644 --- a/spring-core/src/test/java/org/springframework/core/style/ToStringCreatorTests.java +++ b/spring-core/src/test/java/org/springframework/core/style/ToStringCreatorTests.java @@ -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.*; /** * @author Keith Donald */ -@SuppressWarnings({ "rawtypes", "unchecked" }) public class ToStringCreatorTests { private SomeObject s1, s2, s3; @@ -63,20 +62,20 @@ public class ToStringCreatorTests { @Test public void defaultStyleMap() { - final Map map = getMap(); + final Map 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 getMap() { + Map map = new LinkedHashMap<>(); map.put("Keri", "Softball"); map.put("Scot", "Fishing"); map.put("Keith", "Flag Football"); @@ -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[A, B, C]]", str); + assertEquals("[@" + ObjectUtils.getIdentityHexString(array) + + " array[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[0, 1, 2, 3, 4]]", str); } @Test public void appendList() { - List list = new ArrayList(); + List list = new ArrayList<>(); list.add(s1); list.add(s2); list.add(s3); @@ -111,28 +110,26 @@ public class ToStringCreatorTests { @Test public void appendSet() { - Set set = new LinkedHashSet<>(3); + Set 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); } diff --git a/spring-core/src/test/java/org/springframework/util/MethodInvokerTests.java b/spring-core/src/test/java/org/springframework/util/MethodInvokerTests.java index 4800142dfa0..b90bf3b6dc7 100644 --- a/spring-core/src/test/java/org/springframework/util/MethodInvokerTests.java +++ b/spring-core/src/test/java/org/springframework/util/MethodInvokerTests.java @@ -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 { 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 { } } + @SuppressWarnings("unused") public static class Greeter { @@ -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 { } } + private static class Shopper extends Purchaser implements Person { @Override @@ -246,6 +252,7 @@ public class MethodInvokerTests { } } + private static class Salesman implements Person { @Override @@ -254,6 +261,7 @@ public class MethodInvokerTests { } } + private static class Customer extends Shopper { @Override @@ -262,6 +270,7 @@ public class MethodInvokerTests { } } + private static class Regular extends Customer { private String name; @@ -276,6 +285,7 @@ public class MethodInvokerTests { } } + private static class VIP extends Regular { public VIP(String name) { diff --git a/spring-jdbc/src/test/java/org/springframework/jdbc/object/GenericSqlQueryTests.java b/spring-jdbc/src/test/java/org/springframework/jdbc/object/GenericSqlQueryTests.java index dda92636838..f653a073c1a 100644 --- a/spring-jdbc/src/test/java/org/springframework/jdbc/object/GenericSqlQueryTests.java +++ b/spring-jdbc/src/test/java/org/springframework/jdbc/object/GenericSqlQueryTests.java @@ -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.*; * @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 { @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); diff --git a/spring-jdbc/src/test/resources/org/springframework/jdbc/object/GenericSqlQueryTests-context.xml b/spring-jdbc/src/test/resources/org/springframework/jdbc/object/GenericSqlQueryTests-context.xml index 719502060c2..4bb3358773a 100644 --- a/spring-jdbc/src/test/resources/org/springframework/jdbc/object/GenericSqlQueryTests-context.xml +++ b/spring-jdbc/src/test/resources/org/springframework/jdbc/object/GenericSqlQueryTests-context.xml @@ -1,7 +1,7 @@ @@ -47,7 +47,7 @@ - + diff --git a/spring-web/src/test/java/org/springframework/http/converter/xml/Jaxb2CollectionHttpMessageConverterTests.java b/spring-web/src/test/java/org/springframework/http/converter/xml/Jaxb2CollectionHttpMessageConverterTests.java index 3af300d77a9..7f2c6442ae3 100644 --- a/spring-web/src/test/java/org/springframework/http/converter/xml/Jaxb2CollectionHttpMessageConverterTests.java +++ b/spring-web/src/test/java/org/springframework/http/converter/xml/Jaxb2CollectionHttpMessageConverterTests.java @@ -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 { public void readXmlRootElementList() throws Exception { String content = ""; MockHttpInputMessage inputMessage = new MockHttpInputMessage(content.getBytes("UTF-8")); - List result = (List) converter.read(rootElementListType, null, inputMessage); assertEquals("Invalid result", 2, result.size()); @@ -96,7 +95,6 @@ public class Jaxb2CollectionHttpMessageConverterTests { public void readXmlRootElementSet() throws Exception { String content = ""; MockHttpInputMessage inputMessage = new MockHttpInputMessage(content.getBytes("UTF-8")); - Set result = (Set) converter.read(rootElementSetType, null, inputMessage); assertEquals("Invalid result", 2, result.size()); @@ -109,7 +107,6 @@ public class Jaxb2CollectionHttpMessageConverterTests { public void readXmlTypeList() throws Exception { String content = ""; MockHttpInputMessage inputMessage = new MockHttpInputMessage(content.getBytes("UTF-8")); - List result = (List) converter.read(typeListType, null, inputMessage); assertEquals("Invalid result", 2, result.size()); @@ -122,7 +119,6 @@ public class Jaxb2CollectionHttpMessageConverterTests { public void readXmlTypeSet() throws Exception { String content = ""; MockHttpInputMessage inputMessage = new MockHttpInputMessage(content.getBytes("UTF-8")); - Set result = (Set) converter.read(typeSetType, null, inputMessage); assertEquals("Invalid result", 2, result.size()); @@ -133,7 +129,6 @@ public class Jaxb2CollectionHttpMessageConverterTests { @Test @SuppressWarnings("unchecked") public void readXmlRootElementExternalEntityDisabled() throws Exception { - Resource external = new ClassPathResource("external.txt", getClass()); String content = "\n" + @@ -142,7 +137,6 @@ public class Jaxb2CollectionHttpMessageConverterTests { MockHttpInputMessage inputMessage = new MockHttpInputMessage(content.getBytes("UTF-8")); converter = new Jaxb2CollectionHttpMessageConverter>() { - @Override protected XMLInputFactory createXmlInputFactory() { XMLInputFactory inputFactory = super.createXmlInputFactory(); @@ -164,7 +158,6 @@ public class Jaxb2CollectionHttpMessageConverterTests { @Test @SuppressWarnings("unchecked") public void readXmlRootElementExternalEntityEnabled() throws Exception { - Resource external = new ClassPathResource("external.txt", getClass()); String content = "\n" + diff --git a/spring-web/src/test/java/org/springframework/web/accept/ContentNegotiationManagerFactoryBeanTests.java b/spring-web/src/test/java/org/springframework/web/accept/ContentNegotiationManagerFactoryBeanTests.java index baabc764498..33b9dca29f1 100644 --- a/spring-web/src/test/java/org/springframework/web/accept/ContentNegotiationManagerFactoryBeanTests.java +++ b/spring-web/src/test/java/org/springframework/web/accept/ContentNegotiationManagerFactoryBeanTests.java @@ -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 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package org.springframework.web.accept; import java.util.Collections;