diff --git a/spring-aop/src/main/java/org/springframework/aop/aspectj/annotation/AspectJProxyFactory.java b/spring-aop/src/main/java/org/springframework/aop/aspectj/annotation/AspectJProxyFactory.java index c174cee97f3..7d6c243bb47 100644 --- a/spring-aop/src/main/java/org/springframework/aop/aspectj/annotation/AspectJProxyFactory.java +++ b/spring-aop/src/main/java/org/springframework/aop/aspectj/annotation/AspectJProxyFactory.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2012 the original author or authors. + * Copyright 2002-2015 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. @@ -76,7 +76,7 @@ public class AspectJProxyFactory extends ProxyCreatorSupport { * Create a new {@code AspectJProxyFactory}. * No target, only interfaces. Must add interceptors. */ - public AspectJProxyFactory(Class[] interfaces) { + public AspectJProxyFactory(Class... interfaces) { setInterfaces(interfaces); } diff --git a/spring-aop/src/test/java/org/springframework/aop/aspectj/annotation/AspectProxyFactoryTests.java b/spring-aop/src/test/java/org/springframework/aop/aspectj/annotation/AspectProxyFactoryTests.java index 29fc1b79fac..c0d4076232c 100644 --- a/spring-aop/src/test/java/org/springframework/aop/aspectj/annotation/AspectProxyFactoryTests.java +++ b/spring-aop/src/test/java/org/springframework/aop/aspectj/annotation/AspectProxyFactoryTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2013 the original author or authors. + * Copyright 2002-2015 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. @@ -32,9 +32,9 @@ import static org.junit.Assert.*; * @author Juergen Hoeller * @author Chris Beams */ -public final class AspectProxyFactoryTests { +public class AspectProxyFactoryTests { - @Test(expected=IllegalArgumentException.class) + @Test(expected = IllegalArgumentException.class) public void testWithNonAspect() { AspectJProxyFactory proxyFactory = new AspectJProxyFactory(new TestBean()); proxyFactory.addAspect(TestBean.class); @@ -70,7 +70,7 @@ public final class AspectProxyFactoryTests { assertEquals(2, proxy1.getAge()); } - @Test(expected=IllegalArgumentException.class) + @Test(expected = IllegalArgumentException.class) public void testWithInstanceWithNonAspect() throws Exception { AspectJProxyFactory pf = new AspectJProxyFactory(); pf.addAspect(new TestBean()); @@ -96,14 +96,14 @@ public final class AspectProxyFactoryTests { assertEquals(target.getAge() * multiple, serializedProxy.getAge()); } - @Test(expected=IllegalArgumentException.class) + @Test(expected = IllegalArgumentException.class) public void testWithNonSingletonAspectInstance() throws Exception { AspectJProxyFactory pf = new AspectJProxyFactory(); pf.addAspect(new PerThisAspect()); } - public static interface ITestBean { + public interface ITestBean { int getAge(); } diff --git a/spring-beans/src/main/java/org/springframework/beans/factory/config/YamlProcessor.java b/spring-beans/src/main/java/org/springframework/beans/factory/config/YamlProcessor.java index 2d34e5a5ee0..4680bb56932 100644 --- a/spring-beans/src/main/java/org/springframework/beans/factory/config/YamlProcessor.java +++ b/spring-beans/src/main/java/org/springframework/beans/factory/config/YamlProcessor.java @@ -393,17 +393,14 @@ public abstract class YamlProcessor { */ protected static class StrictMapAppenderConstructor extends Constructor { - public StrictMapAppenderConstructor() { - super(); - } - @Override protected Map constructMapping(MappingNode node) { try { return super.constructMapping(node); - } catch (IllegalStateException e) { + } + catch (IllegalStateException ex) { throw new ParserException("while parsing MappingNode", - node.getStartMark(), e.getMessage(), node.getEndMark()); + node.getStartMark(), ex.getMessage(), node.getEndMark()); } } @@ -414,7 +411,7 @@ public abstract class YamlProcessor { @Override public Object put(Object key, Object value) { if (delegate.containsKey(key)) { - throw new IllegalStateException("duplicate key: " + key); + throw new IllegalStateException("Duplicate key: " + key); } return delegate.put(key, value); } diff --git a/spring-context/src/test/java/org/springframework/aop/framework/CglibProxyTests.java b/spring-context/src/test/java/org/springframework/aop/framework/CglibProxyTests.java index af22633fbd4..de19919d483 100644 --- a/spring-context/src/test/java/org/springframework/aop/framework/CglibProxyTests.java +++ b/spring-context/src/test/java/org/springframework/aop/framework/CglibProxyTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2014 the original author or authors. + * Copyright 2002-2015 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. @@ -49,7 +49,7 @@ import static org.junit.Assert.*; * @author Chris Beams */ @SuppressWarnings("serial") -public final class CglibProxyTests extends AbstractAopProxyTests implements Serializable { +public class CglibProxyTests extends AbstractAopProxyTests implements Serializable { private static final String DEPENDENCY_CHECK_CONTEXT = CglibProxyTests.class.getSimpleName() + "-with-dependency-checking.xml"; @@ -74,6 +74,7 @@ public final class CglibProxyTests extends AbstractAopProxyTests implements Seri return true; } + @Test public void testNullConfig() { try { diff --git a/spring-context/src/test/java/org/springframework/aop/framework/JdkDynamicProxyTests.java b/spring-context/src/test/java/org/springframework/aop/framework/JdkDynamicProxyTests.java index 7ed664bf506..47d3b776986 100644 --- a/spring-context/src/test/java/org/springframework/aop/framework/JdkDynamicProxyTests.java +++ b/spring-context/src/test/java/org/springframework/aop/framework/JdkDynamicProxyTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2013 the original author or authors. + * Copyright 2002-2015 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. @@ -20,6 +20,7 @@ import java.io.Serializable; import org.aopalliance.intercept.MethodInterceptor; import org.aopalliance.intercept.MethodInvocation; +import org.junit.Test; import org.springframework.aop.interceptor.ExposeInvocationInterceptor; import org.springframework.aop.support.AopUtils; @@ -28,7 +29,6 @@ import org.springframework.tests.sample.beans.ITestBean; import org.springframework.tests.sample.beans.TestBean; import static org.junit.Assert.*; -import static org.mockito.BDDMockito.*; /** * @since 13.03.2003 @@ -37,7 +37,7 @@ import static org.mockito.BDDMockito.*; * @author Chris Beams */ @SuppressWarnings("serial") -public final class JdkDynamicProxyTests extends AbstractAopProxyTests implements Serializable { +public class JdkDynamicProxyTests extends AbstractAopProxyTests implements Serializable { @Override protected Object createProxy(ProxyCreatorSupport as) { @@ -52,6 +52,8 @@ public final class JdkDynamicProxyTests extends AbstractAopProxyTests implements return new JdkDynamicAopProxy(as); } + + @Test public void testNullConfig() { try { new JdkDynamicAopProxy(null); @@ -62,6 +64,7 @@ public final class JdkDynamicProxyTests extends AbstractAopProxyTests implements } } + @Test public void testProxyIsJustInterface() throws Throwable { TestBean raw = new TestBean(); raw.setAge(32); @@ -74,32 +77,32 @@ public final class JdkDynamicProxyTests extends AbstractAopProxyTests implements assertTrue(!(proxy instanceof TestBean)); } + @Test public void testInterceptorIsInvokedWithNoTarget() throws Throwable { // Test return value - int age = 25; - MethodInterceptor mi = mock(MethodInterceptor.class); + final Integer age = 25; + MethodInterceptor mi = (invocation -> age); - AdvisedSupport pc = new AdvisedSupport(new Class[] { ITestBean.class }); + AdvisedSupport pc = new AdvisedSupport(new Class[] {ITestBean.class}); pc.addAdvice(mi); AopProxy aop = createAopProxy(pc); - given(mi.invoke(null)).willReturn(age); - ITestBean tb = (ITestBean) aop.getProxy(); assertTrue("correct return value", tb.getAge() == age); } + @Test public void testTargetCanGetInvocationWithPrivateClass() throws Throwable { final ExposedInvocationTestBean expectedTarget = new ExposedInvocationTestBean() { @Override protected void assertions(MethodInvocation invocation) { assertTrue(invocation.getThis() == this); assertTrue("Invocation should be on ITestBean: " + invocation.getMethod(), - invocation.getMethod().getDeclaringClass() == ITestBean.class); + invocation.getMethod().getDeclaringClass() == ITestBean.class); } }; - AdvisedSupport pc = new AdvisedSupport(new Class[] { ITestBean.class, IOther.class }); + AdvisedSupport pc = new AdvisedSupport(new Class[] {ITestBean.class, IOther.class}); pc.addAdvice(ExposeInvocationInterceptor.INSTANCE); TrapTargetInterceptor tii = new TrapTargetInterceptor() { @Override @@ -126,10 +129,11 @@ public final class JdkDynamicProxyTests extends AbstractAopProxyTests implements //assertTrue(target.invocation == tii.invocation); } + @Test public void testProxyNotWrappedIfIncompatible() { FooBar bean = new FooBar(); ProxyCreatorSupport as = new ProxyCreatorSupport(); - as.setInterfaces(new Class[] {Foo.class}); + as.setInterfaces(Foo.class); as.setTarget(bean); Foo proxy = (Foo) createProxy(as); @@ -138,6 +142,7 @@ public final class JdkDynamicProxyTests extends AbstractAopProxyTests implements } + @Test public void testEqualsAndHashCodeDefined() throws Exception { AdvisedSupport as = new AdvisedSupport(new Class[]{Named.class}); as.setTarget(new Person()); @@ -149,7 +154,7 @@ public final class JdkDynamicProxyTests extends AbstractAopProxyTests implements } - public static interface Foo { + public interface Foo { Bar getBarThis(); @@ -157,8 +162,7 @@ public final class JdkDynamicProxyTests extends AbstractAopProxyTests implements } - public static interface Bar { - + public interface Bar { } @@ -176,7 +180,7 @@ public final class JdkDynamicProxyTests extends AbstractAopProxyTests implements } - public static interface Named { + public interface Named { String getName(); @@ -201,11 +205,8 @@ public final class JdkDynamicProxyTests extends AbstractAopProxyTests implements public boolean equals(Object o) { if (this == o) return true; if (o == null || getClass() != o.getClass()) return false; - - final Person person = (Person) o; - + Person person = (Person) o; if (!name.equals(person.name)) return false; - return true; } diff --git a/spring-expression/src/main/java/org/springframework/expression/spel/support/ReflectiveMethodExecutor.java b/spring-expression/src/main/java/org/springframework/expression/spel/support/ReflectiveMethodExecutor.java index 637385fdb66..b2798c3ddab 100644 --- a/spring-expression/src/main/java/org/springframework/expression/spel/support/ReflectiveMethodExecutor.java +++ b/spring-expression/src/main/java/org/springframework/expression/spel/support/ReflectiveMethodExecutor.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2014 the original author or authors. + * Copyright 2002-2015 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. @@ -35,11 +35,11 @@ import org.springframework.util.ReflectionUtils; public class ReflectiveMethodExecutor implements MethodExecutor { private final Method method; - + private final Integer varargsPosition; private boolean computedPublicDeclaringClass = false; - + private Class publicDeclaringClass; private boolean argumentConversionOccurred = false; @@ -58,10 +58,10 @@ public class ReflectiveMethodExecutor implements MethodExecutor { public Method getMethod() { return this.method; } - + /** * Find the first public class in the methods declaring class hierarchy that declares this method. - * Sometimes the reflective method discovery logic finds a suitable method that can easily be + * Sometimes the reflective method discovery logic finds a suitable method that can easily be * called via reflection but cannot be called from generated code when compiling the expression * because of visibility restrictions. For example if a non public class overrides toString(), this * helper method will walk up the type hierarchy to find the first public type that declares the @@ -80,20 +80,21 @@ public class ReflectiveMethodExecutor implements MethodExecutor { try { clazz.getDeclaredMethod(method.getName(), method.getParameterTypes()); return clazz; - } catch (NoSuchMethodException nsme) { - + } + catch (NoSuchMethodException ex) { + // Continue below... } } - Class[] intfaces = clazz.getInterfaces(); - for (Class intface: intfaces) { - discoverPublicClass(method, intface); + Class[] ifcs = clazz.getInterfaces(); + for (Class ifc: ifcs) { + discoverPublicClass(method, ifc); } if (clazz.getSuperclass() != null) { return discoverPublicClass(method, clazz.getSuperclass()); } return null; } - + public boolean didArgumentConversionOccur() { return this.argumentConversionOccurred; } diff --git a/spring-messaging/src/main/java/org/springframework/messaging/simp/stomp/StompDecoder.java b/spring-messaging/src/main/java/org/springframework/messaging/simp/stomp/StompDecoder.java index d279aa59e8e..4925c140965 100644 --- a/spring-messaging/src/main/java/org/springframework/messaging/simp/stomp/StompDecoder.java +++ b/spring-messaging/src/main/java/org/springframework/messaging/simp/stomp/StompDecoder.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2014 the original author or authors. + * Copyright 2002-2015 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. @@ -58,9 +58,8 @@ public class StompDecoder { /** - * Configure a - * {@link org.springframework.messaging.support.MessageHeaderInitializer MessageHeaderInitializer} - * to apply to the headers of {@link Message}s from decoded STOMP frames. + * Configure a {@link MessageHeaderInitializer} to apply to the headers of + * {@link Message}s from decoded STOMP frames. */ public void setHeaderInitializer(MessageHeaderInitializer headerInitializer) { this.headerInitializer = headerInitializer; diff --git a/spring-test/src/test/java/org/springframework/test/web/servlet/samples/standalone/ResponseBodyTests.java b/spring-test/src/test/java/org/springframework/test/web/servlet/samples/standalone/ResponseBodyTests.java index 60f82cd1c33..6f2e6467bd8 100644 --- a/spring-test/src/test/java/org/springframework/test/web/servlet/samples/standalone/ResponseBodyTests.java +++ b/spring-test/src/test/java/org/springframework/test/web/servlet/samples/standalone/ResponseBodyTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2012 the original author or authors. + * Copyright 2002-2015 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. @@ -38,22 +38,21 @@ public class ResponseBodyTests { @Test public void json() throws Exception { - standaloneSetup(new PersonController()).build() - .perform(get("/person/Lee").accept(MediaType.APPLICATION_JSON)) + .perform(get("/person/Lee").accept(MediaType.APPLICATION_JSON)) .andExpect(status().isOk()) .andExpect(content().contentType("application/json;charset=UTF-8")) .andExpect(jsonPath("$.name").value("Lee")); } + @Controller private class PersonController { @RequestMapping(value="/person/{name}") @ResponseBody public Person get(@PathVariable String name) { - Person person = new Person(name); - return person; + return new Person(name); } } diff --git a/spring-web/src/main/java/org/springframework/web/accept/ContentNegotiationManagerFactoryBean.java b/spring-web/src/main/java/org/springframework/web/accept/ContentNegotiationManagerFactoryBean.java index 3449fd26888..0c6e6ed1df9 100644 --- a/spring-web/src/main/java/org/springframework/web/accept/ContentNegotiationManagerFactoryBean.java +++ b/spring-web/src/main/java/org/springframework/web/accept/ContentNegotiationManagerFactoryBean.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2014 the original author or authors. + * Copyright 2002-2015 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. @@ -234,7 +234,7 @@ public class ContentNegotiationManagerFactoryBean strategies.add(new HeaderContentNegotiationStrategy()); } - if(this.defaultNegotiationStrategy != null) { + if (this.defaultNegotiationStrategy != null) { strategies.add(defaultNegotiationStrategy); } diff --git a/spring-web/src/main/java/org/springframework/web/client/HttpMessageConverterExtractor.java b/spring-web/src/main/java/org/springframework/web/client/HttpMessageConverterExtractor.java index 6abe7c97ba0..7eada90cec6 100644 --- a/spring-web/src/main/java/org/springframework/web/client/HttpMessageConverterExtractor.java +++ b/spring-web/src/main/java/org/springframework/web/client/HttpMessageConverterExtractor.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2012 the original author or authors. + * Copyright 2002-2015 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. @@ -23,7 +23,6 @@ import java.util.List; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; -import org.springframework.http.HttpStatus; import org.springframework.http.MediaType; import org.springframework.http.client.ClientHttpResponse; import org.springframework.http.converter.GenericHttpMessageConverter; @@ -31,12 +30,12 @@ import org.springframework.http.converter.HttpMessageConverter; import org.springframework.util.Assert; /** - * Response extractor that uses the given {@linkplain HttpMessageConverter entity - * converters} to convert the response into a type {@code T}. + * Response extractor that uses the given {@linkplain HttpMessageConverter entity converters} + * to convert the response into a type {@code T}. * * @author Arjen Poutsma - * @see RestTemplate * @since 3.0 + * @see RestTemplate */ public class HttpMessageConverterExtractor implements ResponseExtractor { @@ -48,19 +47,18 @@ public class HttpMessageConverterExtractor implements ResponseExtractor { private final Log logger; + /** - * Creates a new instance of the {@code HttpMessageConverterExtractor} with the given - * response type and message converters. The given converters must support the response - * type. + * Create a new instance of the {@code HttpMessageConverterExtractor} with the given response + * type and message converters. The given converters must support the response type. */ public HttpMessageConverterExtractor(Class responseType, List> messageConverters) { this((Type) responseType, messageConverters); } /** - * Creates a new instance of the {@code HttpMessageConverterExtractor} with the given - * response type and message converters. The given converters must support the response - * type. + * Creates a new instance of the {@code HttpMessageConverterExtractor} with the given response + * type and message converters. The given converters must support the response type. */ public HttpMessageConverterExtractor(Type responseType, List> messageConverters) { this(responseType, messageConverters, LogFactory.getLog(HttpMessageConverterExtractor.class)); @@ -76,12 +74,12 @@ public class HttpMessageConverterExtractor implements ResponseExtractor { this.logger = logger; } + @Override - @SuppressWarnings({ "unchecked", "rawtypes" }) + @SuppressWarnings({"unchecked", "rawtypes"}) public T extractData(ClientHttpResponse response) throws IOException { - MessageBodyClientHttpResponseWrapper responseWrapper = new MessageBodyClientHttpResponseWrapper(response); - if(!responseWrapper.hasMessageBody() || responseWrapper.hasEmptyMessageBody()) { + if (!responseWrapper.hasMessageBody() || responseWrapper.hasEmptyMessageBody()) { return null; } MediaType contentType = getContentType(responseWrapper); @@ -107,9 +105,9 @@ public class HttpMessageConverterExtractor implements ResponseExtractor { } } } - throw new RestClientException( - "Could not extract response: no suitable HttpMessageConverter found for response type [" + - this.responseType + "] and content type [" + contentType + "]"); + + throw new RestClientException("Could not extract response: no suitable HttpMessageConverter found " + + "for response type [" + this.responseType + "] and content type [" + contentType + "]"); } private MediaType getContentType(ClientHttpResponse response) { diff --git a/spring-web/src/main/java/org/springframework/web/client/MessageBodyClientHttpResponseWrapper.java b/spring-web/src/main/java/org/springframework/web/client/MessageBodyClientHttpResponseWrapper.java index b36e37d885e..8b732d8b64a 100644 --- a/spring-web/src/main/java/org/springframework/web/client/MessageBodyClientHttpResponseWrapper.java +++ b/spring-web/src/main/java/org/springframework/web/client/MessageBodyClientHttpResponseWrapper.java @@ -61,7 +61,7 @@ class MessageBodyClientHttpResponseWrapper implements ClientHttpResponse { responseStatus == HttpStatus.NOT_MODIFIED) { return false; } - else if(this.getHeaders().getContentLength() == 0) { + else if (this.getHeaders().getContentLength() == 0) { return false; } return true;