From 1ddf8ec625c9dbc733ae2a6701b5725283232523 Mon Sep 17 00:00:00 2001 From: Juergen Hoeller Date: Tue, 21 Feb 2017 00:04:08 +0100 Subject: [PATCH] Polishing --- .../web/filter/ShallowEtagHeaderFilter.java | 7 +++---- .../annotation/JacksonHintsIntegrationTests.java | 9 ++++++--- ...equestMappingDataBindingIntegrationTests.java | 7 ++++--- ...MappingExceptionHandlingIntegrationTests.java | 8 ++------ .../RequestMappingIntegrationTests.java | 10 +++++----- ...estMappingViewResolutionIntegrationTests.java | 13 ++++--------- ...ervletRequestMethodArgumentResolverTests.java | 16 +++++++++------- 7 files changed, 33 insertions(+), 37 deletions(-) diff --git a/spring-web/src/main/java/org/springframework/web/filter/ShallowEtagHeaderFilter.java b/spring-web/src/main/java/org/springframework/web/filter/ShallowEtagHeaderFilter.java index 0d89426c69c..f59da7c8058 100644 --- a/spring-web/src/main/java/org/springframework/web/filter/ShallowEtagHeaderFilter.java +++ b/spring-web/src/main/java/org/springframework/web/filter/ShallowEtagHeaderFilter.java @@ -19,7 +19,6 @@ package org.springframework.web.filter; import java.io.IOException; import java.io.InputStream; import java.io.PrintWriter; - import javax.servlet.FilterChain; import javax.servlet.ServletException; import javax.servlet.ServletOutputStream; @@ -72,8 +71,8 @@ public class ShallowEtagHeaderFilter extends OncePerRequestFilter { * Set whether the ETag value written to the response should be weak, as per RFC 7232. *

Should be configured using an {@code } for parameter name * "writeWeakETag" in the filter definition in {@code web.xml}. - * @see RFC 7232 section 2.3 * @since 4.3 + * @see RFC 7232 section 2.3 */ public void setWriteWeakETag(boolean writeWeakETag) { this.writeWeakETag = writeWeakETag; @@ -89,8 +88,8 @@ public class ShallowEtagHeaderFilter extends OncePerRequestFilter { /** - * The default value is "false" so that the filter may delay the generation of - * an ETag until the last asynchronously dispatched thread. + * The default value is {@code false} so that the filter may delay the generation + * of an ETag until the last asynchronously dispatched thread. */ @Override protected boolean shouldNotFilterAsyncDispatch() { diff --git a/spring-webflux/src/test/java/org/springframework/web/reactive/result/method/annotation/JacksonHintsIntegrationTests.java b/spring-webflux/src/test/java/org/springframework/web/reactive/result/method/annotation/JacksonHintsIntegrationTests.java index 1ddb006cc9c..deef92b6ed5 100644 --- a/spring-webflux/src/test/java/org/springframework/web/reactive/result/method/annotation/JacksonHintsIntegrationTests.java +++ b/spring-webflux/src/test/java/org/springframework/web/reactive/result/method/annotation/JacksonHintsIntegrationTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2016 the original author or authors. + * Copyright 2002-2017 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,7 +20,6 @@ import java.util.Arrays; import java.util.List; import com.fasterxml.jackson.annotation.JsonView; -import static org.junit.Assert.assertEquals; import org.junit.Test; import reactor.core.publisher.Flux; import reactor.core.publisher.Mono; @@ -36,6 +35,8 @@ import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RestController; import org.springframework.web.reactive.config.EnableWebFlux; +import static org.junit.Assert.*; + /** * @author Sebastien Deleuze */ @@ -49,6 +50,7 @@ public class JacksonHintsIntegrationTests extends AbstractRequestMappingIntegrat return wac; } + @Test public void jsonViewResponse() throws Exception { String expected = "{\"withView1\":\"with\"}"; @@ -98,6 +100,7 @@ public class JacksonHintsIntegrationTests extends AbstractRequestMappingIntegrat static class WebConfig { } + @RestController @SuppressWarnings("unused") private static class JsonViewRestController { @@ -188,4 +191,4 @@ public class JacksonHintsIntegrationTests extends AbstractRequestMappingIntegrat } } -} \ No newline at end of file +} diff --git a/spring-webflux/src/test/java/org/springframework/web/reactive/result/method/annotation/RequestMappingDataBindingIntegrationTests.java b/spring-webflux/src/test/java/org/springframework/web/reactive/result/method/annotation/RequestMappingDataBindingIntegrationTests.java index 53525a0dc72..f49ccd9c71e 100644 --- a/spring-webflux/src/test/java/org/springframework/web/reactive/result/method/annotation/RequestMappingDataBindingIntegrationTests.java +++ b/spring-webflux/src/test/java/org/springframework/web/reactive/result/method/annotation/RequestMappingDataBindingIntegrationTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2016 the original author or authors. + * Copyright 2002-2017 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. @@ -42,8 +42,7 @@ import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.bind.annotation.RestController; import org.springframework.web.reactive.config.EnableWebFlux; -import static org.junit.Assert.assertEquals; - +import static org.junit.Assert.*; /** * Data binding and type conversion related integration tests for @@ -89,6 +88,7 @@ public class RequestMappingDataBindingIntegrationTests extends AbstractRequestMa static class WebConfig { } + @RestController @SuppressWarnings({"unused", "OptionalUsedAsFieldOrParameterType"}) private static class TestController { @@ -120,6 +120,7 @@ public class RequestMappingDataBindingIntegrationTests extends AbstractRequestMa } } + private static class Foo { private final Long id; diff --git a/spring-webflux/src/test/java/org/springframework/web/reactive/result/method/annotation/RequestMappingExceptionHandlingIntegrationTests.java b/spring-webflux/src/test/java/org/springframework/web/reactive/result/method/annotation/RequestMappingExceptionHandlingIntegrationTests.java index 89cc782a086..2ac7301ccce 100644 --- a/spring-webflux/src/test/java/org/springframework/web/reactive/result/method/annotation/RequestMappingExceptionHandlingIntegrationTests.java +++ b/spring-webflux/src/test/java/org/springframework/web/reactive/result/method/annotation/RequestMappingExceptionHandlingIntegrationTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2016 the original author or authors. + * Copyright 2002-2017 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. @@ -31,8 +31,7 @@ import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.RestController; import org.springframework.web.reactive.config.EnableWebFlux; -import static org.junit.Assert.assertEquals; - +import static org.junit.Assert.*; /** * {@code @RequestMapping} integration tests with exception handling scenarios. @@ -41,7 +40,6 @@ import static org.junit.Assert.assertEquals; */ public class RequestMappingExceptionHandlingIntegrationTests extends AbstractRequestMappingIntegrationTests { - @Override protected ApplicationContext initApplicationContext() { AnnotationConfigApplicationContext wac = new AnnotationConfigApplicationContext(); @@ -69,7 +67,6 @@ public class RequestMappingExceptionHandlingIntegrationTests extends AbstractReq @ComponentScan(resourcePattern = "**/RequestMappingExceptionHandlingIntegrationTests$*.class") @SuppressWarnings({"unused", "WeakerAccess"}) static class WebConfig { - } @@ -96,7 +93,6 @@ public class RequestMappingExceptionHandlingIntegrationTests extends AbstractReq public ResponseEntity> handleStateException(IllegalStateException ex) { return ResponseEntity.ok(Mono.just("Recovered from error: " + ex.getMessage())); } - } } diff --git a/spring-webflux/src/test/java/org/springframework/web/reactive/result/method/annotation/RequestMappingIntegrationTests.java b/spring-webflux/src/test/java/org/springframework/web/reactive/result/method/annotation/RequestMappingIntegrationTests.java index 0a479d3c9d4..df9f75a9c68 100644 --- a/spring-webflux/src/test/java/org/springframework/web/reactive/result/method/annotation/RequestMappingIntegrationTests.java +++ b/spring-webflux/src/test/java/org/springframework/web/reactive/result/method/annotation/RequestMappingIntegrationTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2016 the original author or authors. + * Copyright 2002-2017 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. @@ -31,9 +31,7 @@ import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.bind.annotation.RestController; import org.springframework.web.reactive.config.EnableWebFlux; -import static org.junit.Assert.assertArrayEquals; -import static org.junit.Assert.assertEquals; - +import static org.junit.Assert.*; /** * Integration tests with {@code @RequestMapping} handler methods. @@ -54,6 +52,7 @@ public class RequestMappingIntegrationTests extends AbstractRequestMappingIntegr return wac; } + @Test public void handleWithParam() throws Exception { String expected = "Hello George!"; @@ -86,6 +85,7 @@ public class RequestMappingIntegrationTests extends AbstractRequestMappingIntegr static class WebConfig { } + @RestController @SuppressWarnings("unused") private static class TestRestController { @@ -104,9 +104,9 @@ public class RequestMappingIntegrationTests extends AbstractRequestMappingIntegr public Publisher objectStreamResponseBody() { return Flux.just(new Foo("bar")); } - } + private static class Foo { private String name; diff --git a/spring-webflux/src/test/java/org/springframework/web/reactive/result/method/annotation/RequestMappingViewResolutionIntegrationTests.java b/spring-webflux/src/test/java/org/springframework/web/reactive/result/method/annotation/RequestMappingViewResolutionIntegrationTests.java index 2986c518b5e..66e4063d702 100644 --- a/spring-webflux/src/test/java/org/springframework/web/reactive/result/method/annotation/RequestMappingViewResolutionIntegrationTests.java +++ b/spring-webflux/src/test/java/org/springframework/web/reactive/result/method/annotation/RequestMappingViewResolutionIntegrationTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2016 the original author or authors. + * Copyright 2002-2017 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. @@ -39,10 +39,7 @@ import org.springframework.web.reactive.config.WebFluxConfigurationSupport; import org.springframework.web.reactive.result.view.freemarker.FreeMarkerConfigurer; import org.springframework.web.server.ServerWebExchange; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNull; -import static org.springframework.http.RequestEntity.get; - +import static org.junit.Assert.*; /** * {@code @RequestMapping} integration tests with view resolution scenarios. @@ -51,7 +48,6 @@ import static org.springframework.http.RequestEntity.get; */ public class RequestMappingViewResolutionIntegrationTests extends AbstractRequestMappingIntegrationTests { - @Override protected ApplicationContext initApplicationContext() { AnnotationConfigApplicationContext wac = new AnnotationConfigApplicationContext(); @@ -70,7 +66,7 @@ public class RequestMappingViewResolutionIntegrationTests extends AbstractReques @Test public void etagCheckWithNotModifiedResponse() throws Exception { URI uri = new URI("http://localhost:" + this.port + "/html"); - RequestEntity request = get(uri).ifNoneMatch("\"deadb33f8badf00d\"").build(); + RequestEntity request = RequestEntity.get(uri).ifNoneMatch("\"deadb33f8badf00d\"").build(); ResponseEntity response = getRestTemplate().exchange(request, String.class); assertEquals(HttpStatus.NOT_MODIFIED, response.getStatusCode()); @@ -95,9 +91,9 @@ public class RequestMappingViewResolutionIntegrationTests extends AbstractReques configurer.setTemplateLoaderPath("classpath*:org/springframework/web/reactive/view/freemarker/"); return configurer; } - } + @Controller @SuppressWarnings("unused") private static class TestController { @@ -112,7 +108,6 @@ public class RequestMappingViewResolutionIntegrationTests extends AbstractReques model.addAttribute("hello", "Hello: " + name.orElse("") + "!"); return "test"; } - } } diff --git a/spring-webmvc/src/test/java/org/springframework/web/servlet/mvc/method/annotation/ServletRequestMethodArgumentResolverTests.java b/spring-webmvc/src/test/java/org/springframework/web/servlet/mvc/method/annotation/ServletRequestMethodArgumentResolverTests.java index 3daeb1eaec8..490780e2490 100644 --- a/spring-webmvc/src/test/java/org/springframework/web/servlet/mvc/method/annotation/ServletRequestMethodArgumentResolverTests.java +++ b/spring-webmvc/src/test/java/org/springframework/web/servlet/mvc/method/annotation/ServletRequestMethodArgumentResolverTests.java @@ -50,25 +50,27 @@ import static org.junit.Assert.*; */ public class ServletRequestMethodArgumentResolverTests { - private final ServletRequestMethodArgumentResolver resolver = new ServletRequestMethodArgumentResolver(); - - private Method method; + private ServletRequestMethodArgumentResolver resolver; private ModelAndViewContainer mavContainer; + private MockHttpServletRequest servletRequest; + private ServletWebRequest webRequest; - private MockHttpServletRequest servletRequest; + private Method method; @Before public void setup() throws Exception { - method = getClass().getMethod("supportedParams", ServletRequest.class, MultipartRequest.class, - HttpSession.class, Principal.class, Locale.class, InputStream.class, Reader.class, - WebRequest.class, TimeZone.class, ZoneId.class, HttpMethod.class); + resolver = new ServletRequestMethodArgumentResolver(); mavContainer = new ModelAndViewContainer(); servletRequest = new MockHttpServletRequest("GET", ""); webRequest = new ServletWebRequest(servletRequest, new MockHttpServletResponse()); + + method = getClass().getMethod("supportedParams", ServletRequest.class, MultipartRequest.class, + HttpSession.class, Principal.class, Locale.class, InputStream.class, Reader.class, + WebRequest.class, TimeZone.class, ZoneId.class, HttpMethod.class); }