From 9520a593bddf783c4951bc1aa4d2fa382b074d3d Mon Sep 17 00:00:00 2001 From: Juergen Hoeller Date: Tue, 9 Aug 2016 12:59:54 +0200 Subject: [PATCH] Polishing --- .../aop/framework/CglibAopProxy.java | 24 +++++++++---------- .../MockMvcClientHttpRequestFactory.java | 4 ++-- .../test/web/client/RequestMatcher.java | 1 + .../RequestMatcherClientHttpRequest.java | 1 + .../client/match/ContentRequestMatchers.java | 16 ++++++------- .../client/match/JsonPathRequestMatchers.java | 3 +++ .../client/match/XpathRequestMatchers.java | 6 ++--- 7 files changed, 29 insertions(+), 26 deletions(-) diff --git a/spring-aop/src/main/java/org/springframework/aop/framework/CglibAopProxy.java b/spring-aop/src/main/java/org/springframework/aop/framework/CglibAopProxy.java index 227dfddfded..8c1e1246b17 100644 --- a/spring-aop/src/main/java/org/springframework/aop/framework/CglibAopProxy.java +++ b/spring-aop/src/main/java/org/springframework/aop/framework/CglibAopProxy.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. @@ -93,7 +93,7 @@ final class CglibAopProxy implements AopProxy, Serializable { /** Logger available to subclasses; static to optimize serialization */ - protected final static Log logger = LogFactory.getLog(CglibAopProxy.class); + protected static final Log logger = LogFactory.getLog(CglibAopProxy.class); /** Keeps track of the Classes that we have validated for final methods */ private static final Map, Boolean> validatedClasses = new WeakHashMap, Boolean>(); @@ -294,13 +294,13 @@ final class CglibAopProxy implements AopProxy, Serializable { Callback targetDispatcher = isStatic ? new StaticDispatcher(this.advised.getTargetSource().getTarget()) : new SerializableNoOp(); - Callback[] mainCallbacks = new Callback[]{ - aopInterceptor, // for normal advice - targetInterceptor, // invoke target without considering advice, if optimized - new SerializableNoOp(), // no override for methods mapped to this - targetDispatcher, this.advisedDispatcher, - new EqualsInterceptor(this.advised), - new HashCodeInterceptor(this.advised) + Callback[] mainCallbacks = new Callback[] { + aopInterceptor, // for normal advice + targetInterceptor, // invoke target without considering advice, if optimized + new SerializableNoOp(), // no override for methods mapped to this + targetDispatcher, this.advisedDispatcher, + new EqualsInterceptor(this.advised), + new HashCodeInterceptor(this.advised) }; Callback[] callbacks; @@ -678,10 +678,11 @@ final class CglibAopProxy implements AopProxy, Serializable { private final MethodProxy methodProxy; - private boolean protectedMethod; + private final boolean protectedMethod; public CglibMethodInvocation(Object proxy, Object target, Method method, Object[] arguments, Class targetClass, List interceptorsAndDynamicMethodMatchers, MethodProxy methodProxy) { + super(proxy, target, method, arguments, targetClass, interceptorsAndDynamicMethodMatchers); this.methodProxy = methodProxy; this.protectedMethod = Modifier.isProtected(method.getModifiers()); @@ -800,8 +801,7 @@ final class CglibAopProxy implements AopProxy, Serializable { if (logger.isDebugEnabled()) { logger.debug("Method has advice and optimisations are enabled: " + method); } - // We know that we are optimising so we can use the - // FixedStaticChainInterceptors. + // We know that we are optimising so we can use the FixedStaticChainInterceptors. int index = this.fixedInterceptorMap.get(key); return (index + this.fixedInterceptorOffset); } diff --git a/spring-test-mvc/src/main/java/org/springframework/test/web/client/MockMvcClientHttpRequestFactory.java b/spring-test-mvc/src/main/java/org/springframework/test/web/client/MockMvcClientHttpRequestFactory.java index 0361095c2e0..35605d116db 100644 --- a/spring-test-mvc/src/main/java/org/springframework/test/web/client/MockMvcClientHttpRequestFactory.java +++ b/spring-test-mvc/src/main/java/org/springframework/test/web/client/MockMvcClientHttpRequestFactory.java @@ -16,8 +16,6 @@ package org.springframework.test.web.client; -import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.request; - import java.io.IOException; import java.net.URI; import java.util.List; @@ -36,6 +34,8 @@ import org.springframework.test.web.servlet.MvcResult; import org.springframework.test.web.servlet.request.MockHttpServletRequestBuilder; import org.springframework.util.Assert; +import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.*; + /** * A {@link ClientHttpRequestFactory} for requests executed via {@link MockMvc}. * diff --git a/spring-test-mvc/src/main/java/org/springframework/test/web/client/RequestMatcher.java b/spring-test-mvc/src/main/java/org/springframework/test/web/client/RequestMatcher.java index a6986277143..511d3176a96 100644 --- a/spring-test-mvc/src/main/java/org/springframework/test/web/client/RequestMatcher.java +++ b/spring-test-mvc/src/main/java/org/springframework/test/web/client/RequestMatcher.java @@ -13,6 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package org.springframework.test.web.client; import java.io.IOException; diff --git a/spring-test-mvc/src/main/java/org/springframework/test/web/client/RequestMatcherClientHttpRequest.java b/spring-test-mvc/src/main/java/org/springframework/test/web/client/RequestMatcherClientHttpRequest.java index 9e2217a2164..b418614134d 100644 --- a/spring-test-mvc/src/main/java/org/springframework/test/web/client/RequestMatcherClientHttpRequest.java +++ b/spring-test-mvc/src/main/java/org/springframework/test/web/client/RequestMatcherClientHttpRequest.java @@ -13,6 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package org.springframework.test.web.client; import java.io.IOException; diff --git a/spring-test-mvc/src/main/java/org/springframework/test/web/client/match/ContentRequestMatchers.java b/spring-test-mvc/src/main/java/org/springframework/test/web/client/match/ContentRequestMatchers.java index c1f856cb0bd..47e1126088f 100644 --- a/spring-test-mvc/src/main/java/org/springframework/test/web/client/match/ContentRequestMatchers.java +++ b/spring-test-mvc/src/main/java/org/springframework/test/web/client/match/ContentRequestMatchers.java @@ -13,24 +13,24 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.springframework.test.web.client.match; -import static org.springframework.test.util.AssertionErrors.assertEquals; -import static org.springframework.test.util.AssertionErrors.assertTrue; -import static org.springframework.test.util.MatcherAssertionErrors.assertThat; +package org.springframework.test.web.client.match; import java.io.IOException; - import javax.xml.transform.Source; import javax.xml.transform.dom.DOMSource; import org.hamcrest.Matcher; +import org.w3c.dom.Node; + import org.springframework.http.MediaType; import org.springframework.http.client.ClientHttpRequest; import org.springframework.mock.http.client.MockClientHttpRequest; import org.springframework.test.util.XmlExpectationsHelper; import org.springframework.test.web.client.RequestMatcher; -import org.w3c.dom.Node; + +import static org.hamcrest.MatcherAssert.*; +import static org.springframework.test.util.AssertionErrors.*; /** * Factory for request content {@code RequestMatcher}'s. An instance of this @@ -185,8 +185,8 @@ public class ContentRequestMatchers { MockClientHttpRequest mockRequest = (MockClientHttpRequest) request; matchInternal(mockRequest); } - catch (Exception e) { - throw new AssertionError("Failed to parse expected or actual XML request content: " + e.getMessage()); + catch (Exception ex) { + throw new AssertionError("Failed to parse expected or actual XML request content: " + ex.getMessage()); } } diff --git a/spring-test-mvc/src/main/java/org/springframework/test/web/client/match/JsonPathRequestMatchers.java b/spring-test-mvc/src/main/java/org/springframework/test/web/client/match/JsonPathRequestMatchers.java index 0582929ce50..3ea820ed110 100644 --- a/spring-test-mvc/src/main/java/org/springframework/test/web/client/match/JsonPathRequestMatchers.java +++ b/spring-test-mvc/src/main/java/org/springframework/test/web/client/match/JsonPathRequestMatchers.java @@ -13,12 +13,14 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package org.springframework.test.web.client.match; import java.io.IOException; import java.text.ParseException; import org.hamcrest.Matcher; + import org.springframework.http.client.ClientHttpRequest; import org.springframework.mock.http.client.MockClientHttpRequest; import org.springframework.test.util.JsonPathExpectationsHelper; @@ -51,6 +53,7 @@ public class JsonPathRequestMatchers { this.jsonPathHelper = new JsonPathExpectationsHelper(expression, args); } + /** * Evaluate the JSONPath and assert the resulting value with the given {@code Matcher}. */ diff --git a/spring-test-mvc/src/main/java/org/springframework/test/web/client/match/XpathRequestMatchers.java b/spring-test-mvc/src/main/java/org/springframework/test/web/client/match/XpathRequestMatchers.java index 332c0d7acfe..ac5c66319a8 100644 --- a/spring-test-mvc/src/main/java/org/springframework/test/web/client/match/XpathRequestMatchers.java +++ b/spring-test-mvc/src/main/java/org/springframework/test/web/client/match/XpathRequestMatchers.java @@ -13,20 +13,19 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package org.springframework.test.web.client.match; import java.io.IOException; import java.util.Map; - import javax.xml.xpath.XPathExpressionException; import org.hamcrest.Matcher; +import org.w3c.dom.Node; + import org.springframework.http.client.ClientHttpRequest; import org.springframework.mock.http.client.MockClientHttpRequest; import org.springframework.test.util.XpathExpectationsHelper; import org.springframework.test.web.client.RequestMatcher; -import org.w3c.dom.Node; /** * Factory methods for request content {@code RequestMatcher}'s using an XPath @@ -196,7 +195,6 @@ public class XpathRequestMatchers { } protected abstract void matchInternal(MockClientHttpRequest request) throws Exception; - } }