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,27 +28,21 @@ 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(); } + protected void increment() { + this.count++; + } + public int getCount() { return this.count; } - protected void increment() { - ++count; - } - - @Override - public int hashCode() { - return 0; - } @Override public boolean equals(Object other) { @@ -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,22 +28,10 @@ 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; - } - - @Override - public void setAge(int age) { - this.age = age; - } @Override public String getName() { @@ -55,6 +43,16 @@ public class SerializablePerson implements Person, Serializable { this.name = name; } + @Override + public int getAge() { + return age; + } + + @Override + public void setAge(int age) { + this.age = age; + } + @Override public Object echo(Object o) throws Throwable { if (o instanceof Throwable) { @@ -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 0d55ec7a20c..afc56975e01 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 ed32b628ad8..1d4311d44ae 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 @@ -1,5 +1,5 @@ /* - * Copyright 2002-2014 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. @@ -16,7 +16,6 @@ package org.springframework.jdbc.object; - import java.sql.Connection; import java.sql.PreparedStatement; import java.sql.ResultSet; @@ -30,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; @@ -43,13 +40,14 @@ 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 = ?"; + "select id, forename from custmr where id = ? and country = ?"; - private BeanFactory beanFactory; + private DefaultListableBeanFactory beanFactory; private Connection connection; @@ -57,10 +55,11 @@ public class GenericSqlQueryTests { private ResultSet resultSet; + @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); @@ -72,13 +71,13 @@ public class GenericSqlQueryTests { } @Test - public void testPlaceHoldersCustomerQuery() throws SQLException { - SqlQuery query = (SqlQuery) beanFactory.getBean("queryWithPlaceHolders"); + public void testCustomerQueryWithPlaceholders() throws SQLException { + SqlQuery query = (SqlQuery) beanFactory.getBean("queryWithPlaceholders"); doTestCustomerQuery(query, false); } @Test - public void testNamedParameterCustomerQuery() throws SQLException { + public void testCustomerQueryWithNamedParameters() throws SQLException { SqlQuery query = (SqlQuery) beanFactory.getBean("queryWithNamedParameters"); doTestCustomerQuery(query, true); } 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 908653e3fd0..e3711a096f8 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,12 +1,12 @@ - + @@ -47,7 +47,7 @@ - + \ No newline at end of file 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 e9d95c2a13a..f4e564f440d 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; @@ -30,10 +31,11 @@ import org.springframework.web.HttpMediaTypeNotAcceptableException; import org.springframework.web.context.request.NativeWebRequest; import org.springframework.web.context.request.ServletWebRequest; -import static org.junit.Assert.assertEquals; +import static org.junit.Assert.*; /** * Test fixture for {@link ContentNegotiationManagerFactoryBean} tests. + * * @author Rossen Stoyanchev */ public class ContentNegotiationManagerFactoryBeanTests { @@ -119,9 +121,7 @@ public class ContentNegotiationManagerFactoryBeanTests { assertEquals(Collections.emptyList(), manager.resolveMediaTypes(this.webRequest)); } - // SPR-10170 - - @Test(expected = HttpMediaTypeNotAcceptableException.class) + @Test(expected = HttpMediaTypeNotAcceptableException.class) // SPR-10170 public void favorPathWithIgnoreUnknownPathExtensionTurnedOff() throws Exception { this.factoryBean.setFavorPathExtension(true); this.factoryBean.setIgnoreUnknownPathExtensions(false); @@ -152,9 +152,7 @@ public class ContentNegotiationManagerFactoryBeanTests { manager.resolveMediaTypes(this.webRequest)); } - // SPR-10170 - - @Test(expected = HttpMediaTypeNotAcceptableException.class) + @Test(expected = HttpMediaTypeNotAcceptableException.class) // SPR-10170 public void favorParameterWithUnknownMediaType() throws HttpMediaTypeNotAcceptableException { this.factoryBean.setFavorParameter(true); this.factoryBean.afterPropertiesSet(); @@ -188,16 +186,12 @@ public class ContentNegotiationManagerFactoryBeanTests { manager.resolveMediaTypes(this.webRequest)); // SPR-10513 - this.servletRequest.addHeader("Accept", MediaType.ALL_VALUE); - assertEquals(Collections.singletonList(MediaType.APPLICATION_JSON), manager.resolveMediaTypes(this.webRequest)); } - // SPR-12286 - - @Test + @Test // SPR-12286 public void setDefaultContentTypeWithStrategy() throws Exception { this.factoryBean.setDefaultContentTypeStrategy(new FixedContentNegotiationStrategy(MediaType.APPLICATION_JSON)); this.factoryBean.afterPropertiesSet();