From 42f033e43903731f611f911078e0745aa71f5a3c Mon Sep 17 00:00:00 2001 From: Sam Brannen Date: Thu, 18 Jul 2019 15:25:33 +0200 Subject: [PATCH] Polish MockMvc internals regarding "effectively final" --- .../test/web/servlet/MockMvc.java | 4 +-- .../web/servlet/TestDispatcherServlet.java | 2 +- .../ConfigurableSmartRequestBuilder.java | 4 +-- .../MockHttpServletRequestBuilder.java | 4 +-- .../request/MockMvcRequestBuilders.java | 4 +-- .../servlet/result/ContentResultMatchers.java | 24 ++++++------- .../servlet/result/CookieResultMatchers.java | 34 +++++++++---------- .../result/FlashAttributeResultMatchers.java | 10 +++--- .../servlet/result/HandlerResultMatchers.java | 12 +++---- .../servlet/result/HeaderResultMatchers.java | 16 ++++----- .../servlet/result/MockMvcResultHandlers.java | 4 +-- .../servlet/result/ModelResultMatchers.java | 30 ++++++++-------- .../servlet/result/RequestResultMatchers.java | 14 ++++---- .../servlet/result/StatusResultMatchers.java | 12 +++---- .../servlet/result/ViewResultMatchers.java | 6 ++-- .../servlet/result/XpathResultMatchers.java | 18 +++++----- .../setup/StandaloneMockMvcBuilder.java | 4 +-- 17 files changed, 101 insertions(+), 101 deletions(-) diff --git a/spring-test/src/main/java/org/springframework/test/web/servlet/MockMvc.java b/spring-test/src/main/java/org/springframework/test/web/servlet/MockMvc.java index d436cd51d9..69c0ea41c7 100644 --- a/spring-test/src/main/java/org/springframework/test/web/servlet/MockMvc.java +++ b/spring-test/src/main/java/org/springframework/test/web/servlet/MockMvc.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2018 the original author or authors. + * Copyright 2002-2019 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. @@ -172,7 +172,7 @@ public final class MockMvc { request = ((SmartRequestBuilder) requestBuilder).postProcessRequest(request); } - final MvcResult mvcResult = new DefaultMvcResult(request, mockResponse); + MvcResult mvcResult = new DefaultMvcResult(request, mockResponse); request.setAttribute(MVC_RESULT_ATTRIBUTE, mvcResult); RequestAttributes previousAttributes = RequestContextHolder.getRequestAttributes(); diff --git a/spring-test/src/main/java/org/springframework/test/web/servlet/TestDispatcherServlet.java b/spring-test/src/main/java/org/springframework/test/web/servlet/TestDispatcherServlet.java index 15c12de393..020634e6f3 100644 --- a/spring-test/src/main/java/org/springframework/test/web/servlet/TestDispatcherServlet.java +++ b/spring-test/src/main/java/org/springframework/test/web/servlet/TestDispatcherServlet.java @@ -91,7 +91,7 @@ final class TestDispatcherServlet extends DispatcherServlet { } } - private void registerAsyncResultInterceptors(final HttpServletRequest request) { + private void registerAsyncResultInterceptors(HttpServletRequest request) { WebAsyncUtils.getAsyncManager(request).registerCallableInterceptor(KEY, new CallableProcessingInterceptor() { diff --git a/spring-test/src/main/java/org/springframework/test/web/servlet/request/ConfigurableSmartRequestBuilder.java b/spring-test/src/main/java/org/springframework/test/web/servlet/request/ConfigurableSmartRequestBuilder.java index 307c3652c3..5aac8ae7ed 100644 --- a/spring-test/src/main/java/org/springframework/test/web/servlet/request/ConfigurableSmartRequestBuilder.java +++ b/spring-test/src/main/java/org/springframework/test/web/servlet/request/ConfigurableSmartRequestBuilder.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2018 the original author or authors. + * Copyright 2002-2019 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,11 +13,11 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package org.springframework.test.web.servlet.request; import org.springframework.test.web.servlet.SmartRequestBuilder; - /** * An extension of {@link org.springframework.test.web.servlet.SmartRequestBuilder * SmartRequestBuilder} that can be configured with {@link RequestPostProcessor RequestPostProcessors}. diff --git a/spring-test/src/main/java/org/springframework/test/web/servlet/request/MockHttpServletRequestBuilder.java b/spring-test/src/main/java/org/springframework/test/web/servlet/request/MockHttpServletRequestBuilder.java index ba29310fdd..c1f044d6f8 100644 --- a/spring-test/src/main/java/org/springframework/test/web/servlet/request/MockHttpServletRequestBuilder.java +++ b/spring-test/src/main/java/org/springframework/test/web/servlet/request/MockHttpServletRequestBuilder.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2018 the original author or authors. + * Copyright 2002-2019 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. @@ -713,7 +713,7 @@ public class MockHttpServletRequestBuilder })); } - private MultiValueMap parseFormData(final MediaType mediaType) { + private MultiValueMap parseFormData(MediaType mediaType) { HttpInputMessage message = new HttpInputMessage() { @Override public InputStream getBody() { diff --git a/spring-test/src/main/java/org/springframework/test/web/servlet/request/MockMvcRequestBuilders.java b/spring-test/src/main/java/org/springframework/test/web/servlet/request/MockMvcRequestBuilders.java index 9bf7c2982b..a7804a8fce 100644 --- a/spring-test/src/main/java/org/springframework/test/web/servlet/request/MockMvcRequestBuilders.java +++ b/spring-test/src/main/java/org/springframework/test/web/servlet/request/MockMvcRequestBuilders.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2018 the original author or authors. + * Copyright 2002-2019 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. @@ -263,7 +263,7 @@ public abstract class MockMvcRequestBuilders { * * @param mvcResult the result from the request that started async processing */ - public static RequestBuilder asyncDispatch(final MvcResult mvcResult) { + public static RequestBuilder asyncDispatch(MvcResult mvcResult) { // There must be an async result before dispatching mvcResult.getAsyncResult(); diff --git a/spring-test/src/main/java/org/springframework/test/web/servlet/result/ContentResultMatchers.java b/spring-test/src/main/java/org/springframework/test/web/servlet/result/ContentResultMatchers.java index b0cec4d267..c3510b2970 100644 --- a/spring-test/src/main/java/org/springframework/test/web/servlet/result/ContentResultMatchers.java +++ b/spring-test/src/main/java/org/springframework/test/web/servlet/result/ContentResultMatchers.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2018 the original author or authors. + * Copyright 2002-2019 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. @@ -74,7 +74,7 @@ public class ContentResultMatchers { * parameters. For checking only the type and sub-type see * {@link #contentTypeCompatibleWith(MediaType)}. */ - public ResultMatcher contentType(final MediaType contentType) { + public ResultMatcher contentType(MediaType contentType) { return result -> { String actual = result.getResponse().getContentType(); assertTrue("Content type not set", actual != null); @@ -96,7 +96,7 @@ public class ContentResultMatchers { * Assert the ServletResponse content type is compatible with the given * content type as defined by {@link MediaType#isCompatibleWith(MediaType)}. */ - public ResultMatcher contentTypeCompatibleWith(final MediaType contentType) { + public ResultMatcher contentTypeCompatibleWith(MediaType contentType) { return result -> { String actual = result.getResponse().getContentType(); assertTrue("Content type not set", actual != null); @@ -112,7 +112,7 @@ public class ContentResultMatchers { * Assert the character encoding in the ServletResponse. * @see HttpServletResponse#getCharacterEncoding() */ - public ResultMatcher encoding(final String characterEncoding) { + public ResultMatcher encoding(String characterEncoding) { return result -> { String actual = result.getResponse().getCharacterEncoding(); assertEquals("Character encoding", characterEncoding, actual); @@ -126,21 +126,21 @@ public class ContentResultMatchers { * .andExpect(content().string(containsString("text"))); * */ - public ResultMatcher string(final Matcher matcher) { + public ResultMatcher string(Matcher matcher) { return result -> assertThat("Response content", result.getResponse().getContentAsString(), matcher); } /** * Assert the response body content as a String. */ - public ResultMatcher string(final String expectedContent) { + public ResultMatcher string(String expectedContent) { return result -> assertEquals("Response content", expectedContent, result.getResponse().getContentAsString()); } /** * Assert the response body content as a byte array. */ - public ResultMatcher bytes(final byte[] expectedContent) { + public ResultMatcher bytes(byte[] expectedContent) { return result -> assertEquals("Response content", expectedContent, result.getResponse().getContentAsByteArray()); } @@ -154,7 +154,7 @@ public class ContentResultMatchers { * @see MockMvcResultMatchers#xpath(String, Object...) * @see MockMvcResultMatchers#xpath(String, Map, Object...) */ - public ResultMatcher xml(final String xmlContent) { + public ResultMatcher xml(String xmlContent) { return result -> { String content = result.getResponse().getContentAsString(); this.xmlHelper.assertXmlEqual(xmlContent, content); @@ -165,7 +165,7 @@ public class ContentResultMatchers { * Parse the response content as {@link Node} and apply the given Hamcrest * {@link Matcher}. */ - public ResultMatcher node(final Matcher matcher) { + public ResultMatcher node(Matcher matcher) { return result -> { String content = result.getResponse().getContentAsString(); this.xmlHelper.assertNode(content, matcher); @@ -177,7 +177,7 @@ public class ContentResultMatchers { * Hamcrest {@link Matcher}. * @see xml-matchers */ - public ResultMatcher source(final Matcher matcher) { + public ResultMatcher source(Matcher matcher) { return result -> { String content = result.getResponse().getContentAsString(); this.xmlHelper.assertSource(content, matcher); @@ -192,7 +192,7 @@ public class ContentResultMatchers { * @param jsonContent the expected JSON content * @since 4.1 */ - public ResultMatcher json(final String jsonContent) { + public ResultMatcher json(String jsonContent) { return json(jsonContent, false); } @@ -210,7 +210,7 @@ public class ContentResultMatchers { * @param strict enables strict checking * @since 4.2 */ - public ResultMatcher json(final String jsonContent, final boolean strict) { + public ResultMatcher json(String jsonContent, boolean strict) { return result -> { String content = result.getResponse().getContentAsString(); this.jsonHelper.assertJsonEqual(jsonContent, content, strict); diff --git a/spring-test/src/main/java/org/springframework/test/web/servlet/result/CookieResultMatchers.java b/spring-test/src/main/java/org/springframework/test/web/servlet/result/CookieResultMatchers.java index ffd9cb0343..9c7eea203e 100644 --- a/spring-test/src/main/java/org/springframework/test/web/servlet/result/CookieResultMatchers.java +++ b/spring-test/src/main/java/org/springframework/test/web/servlet/result/CookieResultMatchers.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2018 the original author or authors. + * Copyright 2002-2019 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. @@ -51,7 +51,7 @@ public class CookieResultMatchers { /** * Assert a cookie value with the given Hamcrest {@link Matcher}. */ - public ResultMatcher value(final String name, final Matcher matcher) { + public ResultMatcher value(String name, Matcher matcher) { return result -> { Cookie cookie = getCookie(result, name); assertThat("Response cookie '" + name + "'", cookie.getValue(), matcher); @@ -61,7 +61,7 @@ public class CookieResultMatchers { /** * Assert a cookie value. */ - public ResultMatcher value(final String name, final String expectedValue) { + public ResultMatcher value(String name, String expectedValue) { return result -> { Cookie cookie = getCookie(result, name); assertEquals("Response cookie", expectedValue, cookie.getValue()); @@ -72,7 +72,7 @@ public class CookieResultMatchers { * Assert a cookie exists. The existence check is irrespective of whether * max age is 0 (i.e. expired). */ - public ResultMatcher exists(final String name) { + public ResultMatcher exists(String name) { return result -> getCookie(result, name); } @@ -80,7 +80,7 @@ public class CookieResultMatchers { * Assert a cookie does not exist. Note that the existence check is * irrespective of whether max age is 0, i.e. expired. */ - public ResultMatcher doesNotExist(final String name) { + public ResultMatcher doesNotExist(String name) { return result -> { Cookie cookie = result.getResponse().getCookie(name); assertTrue("Unexpected cookie with name '" + name + "'", cookie == null); @@ -90,7 +90,7 @@ public class CookieResultMatchers { /** * Assert a cookie's maxAge with a Hamcrest {@link Matcher}. */ - public ResultMatcher maxAge(final String name, final Matcher matcher) { + public ResultMatcher maxAge(String name, Matcher matcher) { return result -> { Cookie cookie = getCookie(result, name); assertThat("Response cookie '" + name + "' maxAge", cookie.getMaxAge(), matcher); @@ -100,7 +100,7 @@ public class CookieResultMatchers { /** * Assert a cookie's maxAge value. */ - public ResultMatcher maxAge(final String name, final int maxAge) { + public ResultMatcher maxAge(String name, int maxAge) { return result -> { Cookie cookie = getCookie(result, name); assertEquals("Response cookie '" + name + "' maxAge", maxAge, cookie.getMaxAge()); @@ -110,14 +110,14 @@ public class CookieResultMatchers { /** * Assert a cookie path with a Hamcrest {@link Matcher}. */ - public ResultMatcher path(final String name, final Matcher matcher) { + public ResultMatcher path(String name, Matcher matcher) { return result -> { Cookie cookie = getCookie(result, name); assertThat("Response cookie '" + name + "' path", cookie.getPath(), matcher); }; } - public ResultMatcher path(final String name, final String path) { + public ResultMatcher path(String name, String path) { return result -> { Cookie cookie = getCookie(result, name); assertEquals("Response cookie '" + name + "' path", path, cookie.getPath()); @@ -127,7 +127,7 @@ public class CookieResultMatchers { /** * Assert a cookie's domain with a Hamcrest {@link Matcher}. */ - public ResultMatcher domain(final String name, final Matcher matcher) { + public ResultMatcher domain(String name, Matcher matcher) { return result -> { Cookie cookie = getCookie(result, name); assertThat("Response cookie '" + name + "' domain", cookie.getDomain(), matcher); @@ -137,7 +137,7 @@ public class CookieResultMatchers { /** * Assert a cookie's domain value. */ - public ResultMatcher domain(final String name, final String domain) { + public ResultMatcher domain(String name, String domain) { return result -> { Cookie cookie = getCookie(result, name); assertEquals("Response cookie '" + name + "' domain", domain, cookie.getDomain()); @@ -147,7 +147,7 @@ public class CookieResultMatchers { /** * Assert a cookie's comment with a Hamcrest {@link Matcher}. */ - public ResultMatcher comment(final String name, final Matcher matcher) { + public ResultMatcher comment(String name, Matcher matcher) { return result -> { Cookie cookie = getCookie(result, name); assertThat("Response cookie '" + name + "' comment", cookie.getComment(), matcher); @@ -157,7 +157,7 @@ public class CookieResultMatchers { /** * Assert a cookie's comment value. */ - public ResultMatcher comment(final String name, final String comment) { + public ResultMatcher comment(String name, String comment) { return result -> { Cookie cookie = getCookie(result, name); assertEquals("Response cookie '" + name + "' comment", comment, cookie.getComment()); @@ -167,7 +167,7 @@ public class CookieResultMatchers { /** * Assert a cookie's version with a Hamcrest {@link Matcher}. */ - public ResultMatcher version(final String name, final Matcher matcher) { + public ResultMatcher version(String name, Matcher matcher) { return result -> { Cookie cookie = getCookie(result, name); assertThat("Response cookie '" + name + "' version", cookie.getVersion(), matcher); @@ -177,7 +177,7 @@ public class CookieResultMatchers { /** * Assert a cookie's version value. */ - public ResultMatcher version(final String name, final int version) { + public ResultMatcher version(String name, int version) { return result -> { Cookie cookie = getCookie(result, name); assertEquals("Response cookie '" + name + "' version", version, cookie.getVersion()); @@ -187,7 +187,7 @@ public class CookieResultMatchers { /** * Assert whether the cookie must be sent over a secure protocol or not. */ - public ResultMatcher secure(final String name, final boolean secure) { + public ResultMatcher secure(String name, boolean secure) { return result -> { Cookie cookie = getCookie(result, name); assertEquals("Response cookie '" + name + "' secure", secure, cookie.getSecure()); @@ -198,7 +198,7 @@ public class CookieResultMatchers { * Assert whether the cookie must be HTTP only. * @since 4.3.9 */ - public ResultMatcher httpOnly(final String name, final boolean httpOnly) { + public ResultMatcher httpOnly(String name, boolean httpOnly) { return result -> { Cookie cookie = getCookie(result, name); assertEquals("Response cookie '" + name + "' httpOnly", httpOnly, cookie.isHttpOnly()); diff --git a/spring-test/src/main/java/org/springframework/test/web/servlet/result/FlashAttributeResultMatchers.java b/spring-test/src/main/java/org/springframework/test/web/servlet/result/FlashAttributeResultMatchers.java index 435d0f7b35..ab3571a5e0 100644 --- a/spring-test/src/main/java/org/springframework/test/web/servlet/result/FlashAttributeResultMatchers.java +++ b/spring-test/src/main/java/org/springframework/test/web/servlet/result/FlashAttributeResultMatchers.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2018 the original author or authors. + * Copyright 2002-2019 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. @@ -47,21 +47,21 @@ public class FlashAttributeResultMatchers { * Assert a flash attribute's value with the given Hamcrest {@link Matcher}. */ @SuppressWarnings("unchecked") - public ResultMatcher attribute(final String name, final Matcher matcher) { + public ResultMatcher attribute(String name, Matcher matcher) { return result -> assertThat("Flash attribute '" + name + "'", (T) result.getFlashMap().get(name), matcher); } /** * Assert a flash attribute's value. */ - public ResultMatcher attribute(final String name, final Object value) { + public ResultMatcher attribute(String name, Object value) { return result -> assertEquals("Flash attribute '" + name + "'", value, result.getFlashMap().get(name)); } /** * Assert the existence of the given flash attributes. */ - public ResultMatcher attributeExists(final String... names) { + public ResultMatcher attributeExists(String... names) { return result -> { for (String name : names) { assertTrue("Flash attribute '" + name + "' does not exist", result.getFlashMap().get(name) != null); @@ -72,7 +72,7 @@ public class FlashAttributeResultMatchers { /** * Assert the number of flash attributes. */ - public ResultMatcher attributeCount(final int count) { + public ResultMatcher attributeCount(int count) { return result -> assertEquals("FlashMap size must be " + count, count, result.getFlashMap().size()); } diff --git a/spring-test/src/main/java/org/springframework/test/web/servlet/result/HandlerResultMatchers.java b/spring-test/src/main/java/org/springframework/test/web/servlet/result/HandlerResultMatchers.java index be2c608fa1..750e0197bd 100644 --- a/spring-test/src/main/java/org/springframework/test/web/servlet/result/HandlerResultMatchers.java +++ b/spring-test/src/main/java/org/springframework/test/web/servlet/result/HandlerResultMatchers.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2018 the original author or authors. + * Copyright 2002-2019 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. @@ -62,7 +62,7 @@ public class HandlerResultMatchers { /** * Assert the type of the handler that processed the request. */ - public ResultMatcher handlerType(final Class type) { + public ResultMatcher handlerType(Class type) { return result -> { Object handler = result.getHandler(); assertTrue("No handler", handler != null); @@ -100,7 +100,7 @@ public class HandlerResultMatchers { * @param obj either the value returned from a "mock" controller invocation * or the "mock" controller itself after an invocation */ - public ResultMatcher methodCall(final Object obj) { + public ResultMatcher methodCall(Object obj) { return result -> { if (!(obj instanceof MethodInvocationInfo)) { fail(String.format("The supplied object [%s] is not an instance of %s. " + @@ -118,7 +118,7 @@ public class HandlerResultMatchers { * Assert the name of the controller method used to process the request * using the given Hamcrest {@link Matcher}. */ - public ResultMatcher methodName(final Matcher matcher) { + public ResultMatcher methodName(Matcher matcher) { return result -> { HandlerMethod handlerMethod = getHandlerMethod(result); assertThat("Handler method", handlerMethod.getMethod().getName(), matcher); @@ -128,7 +128,7 @@ public class HandlerResultMatchers { /** * Assert the name of the controller method used to process the request. */ - public ResultMatcher methodName(final String name) { + public ResultMatcher methodName(String name) { return result -> { HandlerMethod handlerMethod = getHandlerMethod(result); assertEquals("Handler method", name, handlerMethod.getMethod().getName()); @@ -138,7 +138,7 @@ public class HandlerResultMatchers { /** * Assert the controller method used to process the request. */ - public ResultMatcher method(final Method method) { + public ResultMatcher method(Method method) { return result -> { HandlerMethod handlerMethod = getHandlerMethod(result); assertEquals("Handler method", method, handlerMethod.getMethod()); diff --git a/spring-test/src/main/java/org/springframework/test/web/servlet/result/HeaderResultMatchers.java b/spring-test/src/main/java/org/springframework/test/web/servlet/result/HeaderResultMatchers.java index 846a36ddad..e26a777f65 100644 --- a/spring-test/src/main/java/org/springframework/test/web/servlet/result/HeaderResultMatchers.java +++ b/spring-test/src/main/java/org/springframework/test/web/servlet/result/HeaderResultMatchers.java @@ -55,7 +55,7 @@ public class HeaderResultMatchers { * Assert the primary value of the response header with the given Hamcrest * String {@code Matcher}. */ - public ResultMatcher string(final String name, final Matcher matcher) { + public ResultMatcher string(String name, Matcher matcher) { return result -> assertThat("Response header '" + name + "'", result.getResponse().getHeader(name), matcher); } @@ -64,7 +64,7 @@ public class HeaderResultMatchers { * Iterable {@link Matcher}. * @since 4.3 */ - public ResultMatcher stringValues(final String name, final Matcher> matcher) { + public ResultMatcher stringValues(String name, Matcher> matcher) { return result -> { List values = result.getResponse().getHeaders(name); assertThat("Response header '" + name + "'", values, matcher); @@ -74,7 +74,7 @@ public class HeaderResultMatchers { /** * Assert the primary value of the response header as a String value. */ - public ResultMatcher string(final String name, final String value) { + public ResultMatcher string(String name, String value) { return result -> assertEquals("Response header '" + name + "'", value, result.getResponse().getHeader(name)); } @@ -82,7 +82,7 @@ public class HeaderResultMatchers { * Assert the values of the response header as String values. * @since 4.3 */ - public ResultMatcher stringValues(final String name, final String... values) { + public ResultMatcher stringValues(String name, String... values) { return result -> { List actual = result.getResponse().getHeaderValues(name); assertEquals("Response header '" + name + "'", Arrays.asList(values), actual); @@ -93,7 +93,7 @@ public class HeaderResultMatchers { * Assert that the named response header exists. * @since 5.0.3 */ - public ResultMatcher exists(final String name) { + public ResultMatcher exists(String name) { return result -> assertTrue("Response should contain header '" + name + "'", result.getResponse().containsHeader(name)); } @@ -102,7 +102,7 @@ public class HeaderResultMatchers { * Assert that the named response header does not exist. * @since 4.0 */ - public ResultMatcher doesNotExist(final String name) { + public ResultMatcher doesNotExist(String name) { return result -> assertTrue("Response should not contain header '" + name + "'", !result.getResponse().containsHeader(name)); } @@ -113,7 +113,7 @@ public class HeaderResultMatchers { * {@link AssertionError} if the response does not contain the specified * header, or if the supplied {@code value} does not match the primary value. */ - public ResultMatcher longValue(final String name, final long value) { + public ResultMatcher longValue(String name, long value) { return result -> { MockHttpServletResponse response = result.getResponse(); assertTrue("Response does not contain header '" + name + "'", response.containsHeader(name)); @@ -133,7 +133,7 @@ public class HeaderResultMatchers { * @since 4.2 * @see Section 7.1.1.1 of RFC 7231 */ - public ResultMatcher dateValue(final String name, final long value) { + public ResultMatcher dateValue(String name, long value) { return result -> { MockHttpServletResponse response = result.getResponse(); String headerValue = response.getHeader(name); diff --git a/spring-test/src/main/java/org/springframework/test/web/servlet/result/MockMvcResultHandlers.java b/spring-test/src/main/java/org/springframework/test/web/servlet/result/MockMvcResultHandlers.java index e201ee86c9..f03d6c6ef3 100644 --- a/spring-test/src/main/java/org/springframework/test/web/servlet/result/MockMvcResultHandlers.java +++ b/spring-test/src/main/java/org/springframework/test/web/servlet/result/MockMvcResultHandlers.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2017 the original author or authors. + * Copyright 2002-2019 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. @@ -97,7 +97,7 @@ public abstract class MockMvcResultHandlers { */ private static class PrintWriterPrintingResultHandler extends PrintingResultHandler { - public PrintWriterPrintingResultHandler(final PrintWriter writer) { + public PrintWriterPrintingResultHandler(PrintWriter writer) { super(new ResultValuePrinter() { @Override public void printHeading(String heading) { diff --git a/spring-test/src/main/java/org/springframework/test/web/servlet/result/ModelResultMatchers.java b/spring-test/src/main/java/org/springframework/test/web/servlet/result/ModelResultMatchers.java index 38f17a90eb..813889d41b 100644 --- a/spring-test/src/main/java/org/springframework/test/web/servlet/result/ModelResultMatchers.java +++ b/spring-test/src/main/java/org/springframework/test/web/servlet/result/ModelResultMatchers.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2018 the original author or authors. + * Copyright 2002-2019 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. @@ -54,7 +54,7 @@ public class ModelResultMatchers { * Assert a model attribute value with the given Hamcrest {@link Matcher}. */ @SuppressWarnings("unchecked") - public ResultMatcher attribute(final String name, final Matcher matcher) { + public ResultMatcher attribute(String name, Matcher matcher) { return result -> { ModelAndView mav = getModelAndView(result); assertThat("Model attribute '" + name + "'", (T) mav.getModel().get(name), matcher); @@ -64,7 +64,7 @@ public class ModelResultMatchers { /** * Assert a model attribute value. */ - public ResultMatcher attribute(final String name, final Object value) { + public ResultMatcher attribute(String name, Object value) { return result -> { ModelAndView mav = getModelAndView(result); assertEquals("Model attribute '" + name + "'", value, mav.getModel().get(name)); @@ -74,7 +74,7 @@ public class ModelResultMatchers { /** * Assert the given model attributes exist. */ - public ResultMatcher attributeExists(final String... names) { + public ResultMatcher attributeExists(String... names) { return result -> { ModelAndView mav = getModelAndView(result); for (String name : names) { @@ -86,7 +86,7 @@ public class ModelResultMatchers { /** * Assert the given model attributes do not exist. */ - public ResultMatcher attributeDoesNotExist(final String... names) { + public ResultMatcher attributeDoesNotExist(String... names) { return result -> { ModelAndView mav = getModelAndView(result); for (String name : names) { @@ -98,7 +98,7 @@ public class ModelResultMatchers { /** * Assert the given model attribute(s) have errors. */ - public ResultMatcher attributeErrorCount(final String name, final int expectedCount) { + public ResultMatcher attributeErrorCount(String name, int expectedCount) { return result -> { ModelAndView mav = getModelAndView(result); Errors errors = getBindingResult(mav, name); @@ -110,7 +110,7 @@ public class ModelResultMatchers { /** * Assert the given model attribute(s) have errors. */ - public ResultMatcher attributeHasErrors(final String... names) { + public ResultMatcher attributeHasErrors(String... names) { return mvcResult -> { ModelAndView mav = getModelAndView(mvcResult); for (String name : names) { @@ -123,7 +123,7 @@ public class ModelResultMatchers { /** * Assert the given model attribute(s) do not have errors. */ - public ResultMatcher attributeHasNoErrors(final String... names) { + public ResultMatcher attributeHasNoErrors(String... names) { return mvcResult -> { ModelAndView mav = getModelAndView(mvcResult); for (String name : names) { @@ -137,12 +137,12 @@ public class ModelResultMatchers { /** * Assert the given model attribute field(s) have errors. */ - public ResultMatcher attributeHasFieldErrors(final String name, final String... fieldNames) { + public ResultMatcher attributeHasFieldErrors(String name, String... fieldNames) { return mvcResult -> { ModelAndView mav = getModelAndView(mvcResult); BindingResult result = getBindingResult(mav, name); assertTrue("No errors for attribute '" + name + "'", result.hasErrors()); - for (final String fieldName : fieldNames) { + for (String fieldName : fieldNames) { boolean hasFieldErrors = result.hasFieldErrors(fieldName); assertTrue("No errors for field '" + fieldName + "' of attribute '" + name + "'", hasFieldErrors); } @@ -153,7 +153,7 @@ public class ModelResultMatchers { * Assert a field error code for a model attribute using exact String match. * @since 4.1 */ - public ResultMatcher attributeHasFieldErrorCode(final String name, final String fieldName, final String error) { + public ResultMatcher attributeHasFieldErrorCode(String name, String fieldName, String error) { return mvcResult -> { ModelAndView mav = getModelAndView(mvcResult); BindingResult result = getBindingResult(mav, name); @@ -171,8 +171,8 @@ public class ModelResultMatchers { * Assert a field error code for a model attribute using a {@link org.hamcrest.Matcher}. * @since 4.1 */ - public ResultMatcher attributeHasFieldErrorCode(final String name, final String fieldName, - final Matcher matcher) { + public ResultMatcher attributeHasFieldErrorCode(String name, String fieldName, + Matcher matcher) { return mvcResult -> { ModelAndView mav = getModelAndView(mvcResult); @@ -190,7 +190,7 @@ public class ModelResultMatchers { /** * Assert the total number of errors in the model. */ - public ResultMatcher errorCount(final int expectedCount) { + public ResultMatcher errorCount(int expectedCount) { return result -> { int actualCount = getErrorCount(getModelAndView(result).getModelMap()); assertEquals("Binding/validation error count", expectedCount, actualCount); @@ -224,7 +224,7 @@ public class ModelResultMatchers { /** * Assert the number of model attributes. */ - public ResultMatcher size(final int size) { + public ResultMatcher size(int size) { return result -> { ModelAndView mav = getModelAndView(result); int actual = 0; diff --git a/spring-test/src/main/java/org/springframework/test/web/servlet/result/RequestResultMatchers.java b/spring-test/src/main/java/org/springframework/test/web/servlet/result/RequestResultMatchers.java index 40b9c892a4..a114c14235 100644 --- a/spring-test/src/main/java/org/springframework/test/web/servlet/result/RequestResultMatchers.java +++ b/spring-test/src/main/java/org/springframework/test/web/servlet/result/RequestResultMatchers.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2018 the original author or authors. + * Copyright 2002-2019 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. @@ -84,7 +84,7 @@ public class RequestResultMatchers { * or {@link WebAsyncTask}. */ @SuppressWarnings("unchecked") - public ResultMatcher asyncResult(final Matcher matcher) { + public ResultMatcher asyncResult(Matcher matcher) { return result -> { HttpServletRequest request = result.getRequest(); assertAsyncStarted(request); @@ -98,7 +98,7 @@ public class RequestResultMatchers { * or {@link WebAsyncTask}. The value matched is the value returned from the * {@code Callable} or the exception raised. */ - public ResultMatcher asyncResult(final Object expectedResult) { + public ResultMatcher asyncResult(Object expectedResult) { return result -> { HttpServletRequest request = result.getRequest(); assertAsyncStarted(request); @@ -110,7 +110,7 @@ public class RequestResultMatchers { * Assert a request attribute value with the given Hamcrest {@link Matcher}. */ @SuppressWarnings("unchecked") - public ResultMatcher attribute(final String name, final Matcher matcher) { + public ResultMatcher attribute(String name, Matcher matcher) { return result -> { T value = (T) result.getRequest().getAttribute(name); assertThat("Request attribute '" + name + "'", value, matcher); @@ -120,7 +120,7 @@ public class RequestResultMatchers { /** * Assert a request attribute value. */ - public ResultMatcher attribute(final String name, final Object expectedValue) { + public ResultMatcher attribute(String name, Object expectedValue) { return result -> assertEquals("Request attribute '" + name + "'", expectedValue, result.getRequest().getAttribute(name)); } @@ -129,7 +129,7 @@ public class RequestResultMatchers { * Assert a session attribute value with the given Hamcrest {@link Matcher}. */ @SuppressWarnings("unchecked") - public ResultMatcher sessionAttribute(final String name, final Matcher matcher) { + public ResultMatcher sessionAttribute(String name, Matcher matcher) { return result -> { HttpSession session = result.getRequest().getSession(); Assert.state(session != null, "No HttpSession"); @@ -141,7 +141,7 @@ public class RequestResultMatchers { /** * Assert a session attribute value. */ - public ResultMatcher sessionAttribute(final String name, final Object value) { + public ResultMatcher sessionAttribute(String name, Object value) { return result -> { HttpSession session = result.getRequest().getSession(); Assert.state(session != null, "No HttpSession"); diff --git a/spring-test/src/main/java/org/springframework/test/web/servlet/result/StatusResultMatchers.java b/spring-test/src/main/java/org/springframework/test/web/servlet/result/StatusResultMatchers.java index 166a1170e5..be08dae5a6 100644 --- a/spring-test/src/main/java/org/springframework/test/web/servlet/result/StatusResultMatchers.java +++ b/spring-test/src/main/java/org/springframework/test/web/servlet/result/StatusResultMatchers.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2018 the original author or authors. + * Copyright 2002-2019 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. @@ -51,7 +51,7 @@ public class StatusResultMatchers { * Assert the response status code with the given Hamcrest {@link Matcher}. * Use the {@code StatusResultMatchers.isEqualTo} extension in Kotlin. */ - public ResultMatcher is(final Matcher matcher) { + public ResultMatcher is(Matcher matcher) { return result -> assertThat("Response status", result.getResponse().getStatus(), matcher); } @@ -59,7 +59,7 @@ public class StatusResultMatchers { * Assert the response status code is equal to an integer value. * Use the {@code StatusResultMatchers.isEqualTo} extension in Kotlin. */ - public ResultMatcher is(final int status) { + public ResultMatcher is(int status) { return result -> assertEquals("Response status", status, result.getResponse().getStatus()); } @@ -112,14 +112,14 @@ public class StatusResultMatchers { /** * Assert the Servlet response error message with the given Hamcrest {@link Matcher}. */ - public ResultMatcher reason(final Matcher matcher) { + public ResultMatcher reason(Matcher matcher) { return result -> assertThat("Response status reason", result.getResponse().getErrorMessage(), matcher); } /** * Assert the Servlet response error message. */ - public ResultMatcher reason(final String reason) { + public ResultMatcher reason(String reason) { return result -> assertEquals("Response status reason", reason, result.getResponse().getErrorMessage()); } @@ -615,7 +615,7 @@ public class StatusResultMatchers { /** * Match the expected response status to that of the HttpServletResponse. */ - private ResultMatcher matcher(final HttpStatus status) { + private ResultMatcher matcher(HttpStatus status) { return result -> assertEquals("Status", status.value(), result.getResponse().getStatus()); } diff --git a/spring-test/src/main/java/org/springframework/test/web/servlet/result/ViewResultMatchers.java b/spring-test/src/main/java/org/springframework/test/web/servlet/result/ViewResultMatchers.java index 51d374d8e7..af88cb202e 100644 --- a/spring-test/src/main/java/org/springframework/test/web/servlet/result/ViewResultMatchers.java +++ b/spring-test/src/main/java/org/springframework/test/web/servlet/result/ViewResultMatchers.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2018 the original author or authors. + * Copyright 2002-2019 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. @@ -47,7 +47,7 @@ public class ViewResultMatchers { /** * Assert the selected view name with the given Hamcrest {@link Matcher}. */ - public ResultMatcher name(final Matcher matcher) { + public ResultMatcher name(Matcher matcher) { return result -> { ModelAndView mav = result.getModelAndView(); if (mav == null) { @@ -60,7 +60,7 @@ public class ViewResultMatchers { /** * Assert the selected view name. */ - public ResultMatcher name(final String expectedViewName) { + public ResultMatcher name(String expectedViewName) { return result -> { ModelAndView mav = result.getModelAndView(); if (mav == null) { diff --git a/spring-test/src/main/java/org/springframework/test/web/servlet/result/XpathResultMatchers.java b/spring-test/src/main/java/org/springframework/test/web/servlet/result/XpathResultMatchers.java index 4c8e5776f8..42624a4586 100644 --- a/spring-test/src/main/java/org/springframework/test/web/servlet/result/XpathResultMatchers.java +++ b/spring-test/src/main/java/org/springframework/test/web/servlet/result/XpathResultMatchers.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2018 the original author or authors. + * Copyright 2002-2019 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. @@ -61,7 +61,7 @@ public class XpathResultMatchers { * Evaluate the XPath and assert the {@link Node} content found with the * given Hamcrest {@link Matcher}. */ - public ResultMatcher node(final Matcher matcher) { + public ResultMatcher node(Matcher matcher) { return result -> { MockHttpServletResponse response = result.getResponse(); this.xpathHelper.assertNode(response.getContentAsByteArray(), getDefinedEncoding(response), matcher); @@ -100,7 +100,7 @@ public class XpathResultMatchers { * Evaluate the XPath and assert the number of nodes found with the given * Hamcrest {@link Matcher}. */ - public ResultMatcher nodeCount(final Matcher matcher) { + public ResultMatcher nodeCount(Matcher matcher) { return result -> { MockHttpServletResponse response = result.getResponse(); this.xpathHelper.assertNodeCount(response.getContentAsByteArray(), getDefinedEncoding(response), matcher); @@ -110,7 +110,7 @@ public class XpathResultMatchers { /** * Evaluate the XPath and assert the number of nodes found. */ - public ResultMatcher nodeCount(final int expectedCount) { + public ResultMatcher nodeCount(int expectedCount) { return result -> { MockHttpServletResponse response = result.getResponse(); this.xpathHelper.assertNodeCount(response.getContentAsByteArray(), getDefinedEncoding(response), expectedCount); @@ -121,7 +121,7 @@ public class XpathResultMatchers { * Apply the XPath and assert the {@link String} value found with the given * Hamcrest {@link Matcher}. */ - public ResultMatcher string(final Matcher matcher) { + public ResultMatcher string(Matcher matcher) { return result -> { MockHttpServletResponse response = result.getResponse(); this.xpathHelper.assertString(response.getContentAsByteArray(), getDefinedEncoding(response), matcher); @@ -131,7 +131,7 @@ public class XpathResultMatchers { /** * Apply the XPath and assert the {@link String} value found. */ - public ResultMatcher string(final String expectedValue) { + public ResultMatcher string(String expectedValue) { return result -> { MockHttpServletResponse response = result.getResponse(); this.xpathHelper.assertString(response.getContentAsByteArray(), getDefinedEncoding(response), expectedValue); @@ -142,7 +142,7 @@ public class XpathResultMatchers { * Evaluate the XPath and assert the {@link Double} value found with the * given Hamcrest {@link Matcher}. */ - public ResultMatcher number(final Matcher matcher) { + public ResultMatcher number(Matcher matcher) { return result -> { MockHttpServletResponse response = result.getResponse(); this.xpathHelper.assertNumber(response.getContentAsByteArray(), getDefinedEncoding(response), matcher); @@ -152,7 +152,7 @@ public class XpathResultMatchers { /** * Evaluate the XPath and assert the {@link Double} value found. */ - public ResultMatcher number(final Double expectedValue) { + public ResultMatcher number(Double expectedValue) { return result -> { MockHttpServletResponse response = result.getResponse(); this.xpathHelper.assertNumber(response.getContentAsByteArray(), getDefinedEncoding(response), expectedValue); @@ -162,7 +162,7 @@ public class XpathResultMatchers { /** * Evaluate the XPath and assert the {@link Boolean} value found. */ - public ResultMatcher booleanValue(final Boolean value) { + public ResultMatcher booleanValue(Boolean value) { return result -> { MockHttpServletResponse response = result.getResponse(); this.xpathHelper.assertBoolean(response.getContentAsByteArray(), getDefinedEncoding(response), value); diff --git a/spring-test/src/main/java/org/springframework/test/web/servlet/setup/StandaloneMockMvcBuilder.java b/spring-test/src/main/java/org/springframework/test/web/servlet/setup/StandaloneMockMvcBuilder.java index f03f8f5527..1b9d3bf56f 100644 --- a/spring-test/src/main/java/org/springframework/test/web/servlet/setup/StandaloneMockMvcBuilder.java +++ b/spring-test/src/main/java/org/springframework/test/web/servlet/setup/StandaloneMockMvcBuilder.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2018 the original author or authors. + * Copyright 2002-2019 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. @@ -546,7 +546,7 @@ public class StandaloneMockMvcBuilder extends AbstractMockMvcBuilder values) { + public StaticStringValueResolver(Map values) { this.helper = new PropertyPlaceholderHelper("${", "}", ":", false); this.resolver = values::get; } -- GitLab