From 77ab88b1441dd71341e6070d677b265f314407d1 Mon Sep 17 00:00:00 2001 From: Juergen Hoeller Date: Fri, 23 Nov 2018 13:56:02 +0100 Subject: [PATCH] Polishing --- .../reactive/CookieIntegrationTests.java | 15 +++++------ .../reactive/EchoHandlerIntegrationTests.java | 10 ++++--- .../ErrorHandlerIntegrationTests.java | 6 ++++- .../RandomHandlerIntegrationTests.java | 5 +++- .../ServerHttpRequestIntegrationTests.java | 4 +++ .../WriteOnlyHandlerIntegrationTests.java | 14 ++++------ .../reactive/ZeroCopyIntegrationTests.java | 12 ++++----- .../session/WebSessionIntegrationTests.java | 17 +++--------- .../function/MultipartIntegrationTests.java | 5 ++++ .../SseHandlerFunctionIntegrationTests.java | 12 ++++----- .../DispatcherHandlerIntegrationTests.java | 2 +- ...mpleUrlHandlerMappingIntegrationTests.java | 9 +++---- ...bstractRequestMappingIntegrationTests.java | 7 +++-- .../ControllerInputIntegrationTests.java | 9 ++++--- ...CrossOriginAnnotationIntegrationTests.java | 24 ++++++++--------- .../annotation/ProtobufIntegrationTests.java | 23 +++++++++------- ...pingExceptionHandlingIntegrationTests.java | 8 +++--- ...MappingViewResolutionIntegrationTests.java | 8 +++--- .../annotation/SseIntegrationTests.java | 2 +- ...LocaleContextResolverIntegrationTests.java | 26 +++++++++---------- 20 files changed, 113 insertions(+), 105 deletions(-) diff --git a/spring-web/src/test/java/org/springframework/http/server/reactive/CookieIntegrationTests.java b/spring-web/src/test/java/org/springframework/http/server/reactive/CookieIntegrationTests.java index d39d60a45cb..be544021697 100644 --- a/spring-web/src/test/java/org/springframework/http/server/reactive/CookieIntegrationTests.java +++ b/spring-web/src/test/java/org/springframework/http/server/reactive/CookieIntegrationTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2015 the original author or authors. + * Copyright 2002-2018 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.http.server.reactive; import java.net.URI; @@ -27,15 +28,13 @@ import reactor.core.publisher.Mono; import org.springframework.http.HttpCookie; import org.springframework.http.RequestEntity; -import org.springframework.http.ResponseEntity; import org.springframework.http.ResponseCookie; +import org.springframework.http.ResponseEntity; import org.springframework.web.client.RestTemplate; import static org.hamcrest.CoreMatchers.equalTo; -import static org.hamcrest.Matchers.containsInAnyOrder; -import static org.hamcrest.Matchers.equalToIgnoringCase; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertThat; +import static org.hamcrest.Matchers.*; +import static org.junit.Assert.*; /** * @author Rossen Stoyanchev @@ -43,11 +42,11 @@ import static org.junit.Assert.assertThat; @RunWith(Parameterized.class) public class CookieIntegrationTests extends AbstractHttpHandlerIntegrationTests { - private CookieHandler cookieHandler; + private final CookieHandler cookieHandler = new CookieHandler(); + @Override protected HttpHandler createHttpHandler() { - this.cookieHandler = new CookieHandler(); return this.cookieHandler; } diff --git a/spring-web/src/test/java/org/springframework/http/server/reactive/EchoHandlerIntegrationTests.java b/spring-web/src/test/java/org/springframework/http/server/reactive/EchoHandlerIntegrationTests.java index dd0a4a5ea1a..cc9f16d4b5f 100644 --- a/spring-web/src/test/java/org/springframework/http/server/reactive/EchoHandlerIntegrationTests.java +++ b/spring-web/src/test/java/org/springframework/http/server/reactive/EchoHandlerIntegrationTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2016 the original author or authors. + * Copyright 2002-2018 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. @@ -26,14 +26,16 @@ import org.springframework.http.RequestEntity; import org.springframework.http.ResponseEntity; import org.springframework.web.client.RestTemplate; -import static org.junit.Assert.assertArrayEquals; - +import static org.junit.Assert.*; +/** + * @author Arjen Poutsma + */ public class EchoHandlerIntegrationTests extends AbstractHttpHandlerIntegrationTests { private static final int REQUEST_SIZE = 4096 * 3; - private Random rnd = new Random(); + private final Random rnd = new Random(); @Override diff --git a/spring-web/src/test/java/org/springframework/http/server/reactive/ErrorHandlerIntegrationTests.java b/spring-web/src/test/java/org/springframework/http/server/reactive/ErrorHandlerIntegrationTests.java index 74e50001cae..c30279eebd3 100644 --- a/spring-web/src/test/java/org/springframework/http/server/reactive/ErrorHandlerIntegrationTests.java +++ b/spring-web/src/test/java/org/springframework/http/server/reactive/ErrorHandlerIntegrationTests.java @@ -34,13 +34,15 @@ import static org.junit.Assert.*; */ public class ErrorHandlerIntegrationTests extends AbstractHttpHandlerIntegrationTests { - private ErrorHandler handler = new ErrorHandler(); + private final ErrorHandler handler = new ErrorHandler(); + @Override protected HttpHandler createHttpHandler() { return handler; } + @Test public void responseBodyError() throws Exception { RestTemplate restTemplate = new RestTemplate(); @@ -75,6 +77,7 @@ public class ErrorHandlerIntegrationTests extends AbstractHttpHandlerIntegration assertEquals(HttpStatus.OK, response.getStatusCode()); } + private static class ErrorHandler implements HttpHandler { @Override @@ -93,6 +96,7 @@ public class ErrorHandlerIntegrationTests extends AbstractHttpHandlerIntegration } } + private static final ResponseErrorHandler NO_OP_ERROR_HANDLER = new ResponseErrorHandler() { @Override diff --git a/spring-web/src/test/java/org/springframework/http/server/reactive/RandomHandlerIntegrationTests.java b/spring-web/src/test/java/org/springframework/http/server/reactive/RandomHandlerIntegrationTests.java index 59789517842..94b4697153a 100644 --- a/spring-web/src/test/java/org/springframework/http/server/reactive/RandomHandlerIntegrationTests.java +++ b/spring-web/src/test/java/org/springframework/http/server/reactive/RandomHandlerIntegrationTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2016 the original author or authors. + * Copyright 2002-2018 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,6 +33,9 @@ import org.springframework.web.client.RestTemplate; import static org.junit.Assert.*; +/** + * @author Arjen Poutsma + */ public class RandomHandlerIntegrationTests extends AbstractHttpHandlerIntegrationTests { public static final int REQUEST_SIZE = 4096 * 3; diff --git a/spring-web/src/test/java/org/springframework/http/server/reactive/ServerHttpRequestIntegrationTests.java b/spring-web/src/test/java/org/springframework/http/server/reactive/ServerHttpRequestIntegrationTests.java index 41efd1a7527..367e5ea2561 100644 --- a/spring-web/src/test/java/org/springframework/http/server/reactive/ServerHttpRequestIntegrationTests.java +++ b/spring-web/src/test/java/org/springframework/http/server/reactive/ServerHttpRequestIntegrationTests.java @@ -28,6 +28,9 @@ import org.springframework.web.client.RestTemplate; import static org.junit.Assert.*; +/** + * @author Sebastien Deleuze + */ public class ServerHttpRequestIntegrationTests extends AbstractHttpHandlerIntegrationTests { @Override @@ -58,4 +61,5 @@ public class ServerHttpRequestIntegrationTests extends AbstractHttpHandlerIntegr return Mono.empty(); } } + } diff --git a/spring-web/src/test/java/org/springframework/http/server/reactive/WriteOnlyHandlerIntegrationTests.java b/spring-web/src/test/java/org/springframework/http/server/reactive/WriteOnlyHandlerIntegrationTests.java index b7bafdfe420..bc2c8fdc512 100644 --- a/spring-web/src/test/java/org/springframework/http/server/reactive/WriteOnlyHandlerIntegrationTests.java +++ b/spring-web/src/test/java/org/springframework/http/server/reactive/WriteOnlyHandlerIntegrationTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2016 the original author or authors. + * Copyright 2002-2018 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. @@ -21,19 +21,16 @@ import java.nio.charset.StandardCharsets; import java.util.Random; import org.junit.Test; +import reactor.core.publisher.Flux; +import reactor.core.publisher.Mono; + import org.springframework.core.io.buffer.DataBuffer; import org.springframework.http.RequestEntity; import org.springframework.http.ResponseEntity; -import org.springframework.http.server.reactive.HttpHandler; -import org.springframework.http.server.reactive.ServerHttpRequest; -import org.springframework.http.server.reactive.ServerHttpResponse; import org.springframework.web.client.RestTemplate; import static org.junit.Assert.*; -import reactor.core.publisher.Flux; -import reactor.core.publisher.Mono; - /** * @author Violeta Georgieva * @since 5.0 @@ -52,7 +49,6 @@ public class WriteOnlyHandlerIntegrationTests extends AbstractHttpHandlerIntegra return new WriteOnlyHandler(); } - @Test public void writeOnly() throws Exception { RestTemplate restTemplate = new RestTemplate(); @@ -66,7 +62,6 @@ public class WriteOnlyHandlerIntegrationTests extends AbstractHttpHandlerIntegra assertArrayEquals(body, response.getBody()); } - private byte[] randomBytes() { byte[] buffer = new byte[REQUEST_SIZE]; rnd.nextBytes(buffer); @@ -83,4 +78,5 @@ public class WriteOnlyHandlerIntegrationTests extends AbstractHttpHandlerIntegra return response.writeAndFlushWith(Flux.just(Flux.just(buffer))); } } + } diff --git a/spring-web/src/test/java/org/springframework/http/server/reactive/ZeroCopyIntegrationTests.java b/spring-web/src/test/java/org/springframework/http/server/reactive/ZeroCopyIntegrationTests.java index 050388decc4..445d52f8151 100644 --- a/spring-web/src/test/java/org/springframework/http/server/reactive/ZeroCopyIntegrationTests.java +++ b/spring-web/src/test/java/org/springframework/http/server/reactive/ZeroCopyIntegrationTests.java @@ -32,9 +32,8 @@ import org.springframework.http.server.reactive.bootstrap.ReactorHttpServer; import org.springframework.http.server.reactive.bootstrap.UndertowHttpServer; import org.springframework.web.client.RestTemplate; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertTrue; -import static org.junit.Assume.assumeTrue; +import static org.junit.Assert.*; +import static org.junit.Assume.*; /** * @author Arjen Poutsma @@ -43,14 +42,15 @@ public class ZeroCopyIntegrationTests extends AbstractHttpHandlerIntegrationTest private final ZeroCopyHandler handler = new ZeroCopyHandler(); + @Override protected HttpHandler createHttpHandler() { - return handler; + return this.handler; } + @Test public void zeroCopy() throws Exception { - // Zero-copy only does not support servlet assumeTrue(server instanceof ReactorHttpServer || server instanceof UndertowHttpServer); @@ -64,9 +64,9 @@ public class ZeroCopyIntegrationTests extends AbstractHttpHandlerIntegrationTest assertEquals(logo.contentLength(), response.getHeaders().getContentLength()); assertEquals(logo.contentLength(), response.getBody().length); assertEquals(MediaType.IMAGE_PNG, response.getHeaders().getContentType()); - } + private static class ZeroCopyHandler implements HttpHandler { @Override diff --git a/spring-web/src/test/java/org/springframework/web/server/session/WebSessionIntegrationTests.java b/spring-web/src/test/java/org/springframework/web/server/session/WebSessionIntegrationTests.java index 102756f56d6..f5d6f2ac752 100644 --- a/spring-web/src/test/java/org/springframework/web/server/session/WebSessionIntegrationTests.java +++ b/spring-web/src/test/java/org/springframework/web/server/session/WebSessionIntegrationTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2016 the original author or authors. + * Copyright 2002-2018 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,31 +38,22 @@ import org.springframework.web.server.WebHandler; import org.springframework.web.server.WebSession; import org.springframework.web.server.adapter.WebHttpHandlerBuilder; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotEquals; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertNull; -import static org.junit.Assert.assertTrue; +import static org.junit.Assert.*; /** * Integration tests for with a server-side session. + * * @author Rossen Stoyanchev */ public class WebSessionIntegrationTests extends AbstractHttpHandlerIntegrationTests { - private RestTemplate restTemplate; + private final RestTemplate restTemplate = new RestTemplate(); private DefaultWebSessionManager sessionManager; private TestWebHandler handler; - @Override - public void setup() throws Exception { - super.setup(); - this.restTemplate = new RestTemplate(); - } - @Override protected HttpHandler createHttpHandler() { this.sessionManager = new DefaultWebSessionManager(); diff --git a/spring-webflux/src/test/java/org/springframework/web/reactive/function/MultipartIntegrationTests.java b/spring-webflux/src/test/java/org/springframework/web/reactive/function/MultipartIntegrationTests.java index 1231b83646f..1f8d4ddbf31 100644 --- a/spring-webflux/src/test/java/org/springframework/web/reactive/function/MultipartIntegrationTests.java +++ b/spring-webflux/src/test/java/org/springframework/web/reactive/function/MultipartIntegrationTests.java @@ -41,10 +41,14 @@ import static org.junit.Assert.*; import static org.springframework.web.reactive.function.server.RequestPredicates.*; import static org.springframework.web.reactive.function.server.RouterFunctions.*; +/** + * @author Sebastien Deleuze + */ public class MultipartIntegrationTests extends AbstractRouterFunctionIntegrationTests { private final WebClient webClient = WebClient.create(); + @Test public void multipartData() { Mono result = webClient @@ -87,6 +91,7 @@ public class MultipartIntegrationTests extends AbstractRouterFunctionIntegration .andRoute(POST("/parts"), multipartHandler::parts); } + private static class MultipartHandler { public Mono multipartData(ServerRequest request) { diff --git a/spring-webflux/src/test/java/org/springframework/web/reactive/function/server/SseHandlerFunctionIntegrationTests.java b/spring-webflux/src/test/java/org/springframework/web/reactive/function/server/SseHandlerFunctionIntegrationTests.java index 3300875611e..8ea48c3a2c6 100644 --- a/spring-webflux/src/test/java/org/springframework/web/reactive/function/server/SseHandlerFunctionIntegrationTests.java +++ b/spring-webflux/src/test/java/org/springframework/web/reactive/function/server/SseHandlerFunctionIntegrationTests.java @@ -42,6 +42,12 @@ public class SseHandlerFunctionIntegrationTests extends AbstractRouterFunctionIn private WebClient webClient; + @Before + public void setup() throws Exception { + super.setup(); + this.webClient = WebClient.create("http://localhost:" + this.port); + } + @Override protected RouterFunction routerFunction() { SseHandler sseHandler = new SseHandler(); @@ -50,12 +56,6 @@ public class SseHandlerFunctionIntegrationTests extends AbstractRouterFunctionIn .and(route(RequestPredicates.GET("/event"), sseHandler::sse)); } - @Before - public void setup() throws Exception { - super.setup(); - this.webClient = WebClient.create("http://localhost:" + this.port); - } - @Test public void sseAsString() { diff --git a/spring-webflux/src/test/java/org/springframework/web/reactive/function/server/support/DispatcherHandlerIntegrationTests.java b/spring-webflux/src/test/java/org/springframework/web/reactive/function/server/support/DispatcherHandlerIntegrationTests.java index 6238a7ef536..ae9923f22bb 100644 --- a/spring-webflux/src/test/java/org/springframework/web/reactive/function/server/support/DispatcherHandlerIntegrationTests.java +++ b/spring-webflux/src/test/java/org/springframework/web/reactive/function/server/support/DispatcherHandlerIntegrationTests.java @@ -93,4 +93,4 @@ public class DispatcherHandlerIntegrationTests extends AbstractHttpHandlerIntegr } } -} \ No newline at end of file +} diff --git a/spring-webflux/src/test/java/org/springframework/web/reactive/result/SimpleUrlHandlerMappingIntegrationTests.java b/spring-webflux/src/test/java/org/springframework/web/reactive/result/SimpleUrlHandlerMappingIntegrationTests.java index abdaf45bdbd..9ea01e4129d 100644 --- a/spring-webflux/src/test/java/org/springframework/web/reactive/result/SimpleUrlHandlerMappingIntegrationTests.java +++ b/spring-webflux/src/test/java/org/springframework/web/reactive/result/SimpleUrlHandlerMappingIntegrationTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2016 the original author or authors. + * Copyright 2002-2018 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,13 +39,12 @@ import org.springframework.http.server.reactive.HttpHandler; import org.springframework.web.client.HttpClientErrorException; import org.springframework.web.client.RestTemplate; import org.springframework.web.reactive.DispatcherHandler; -import org.springframework.web.server.handler.ResponseStatusExceptionHandler; import org.springframework.web.reactive.handler.SimpleUrlHandlerMapping; import org.springframework.web.server.WebHandler; import org.springframework.web.server.adapter.WebHttpHandlerBuilder; +import org.springframework.web.server.handler.ResponseStatusExceptionHandler; -import static org.junit.Assert.assertArrayEquals; -import static org.junit.Assert.assertEquals; +import static org.junit.Assert.*; /** * Integration tests with requests mapped via @@ -66,6 +65,7 @@ public class SimpleUrlHandlerMappingIntegrationTests extends AbstractHttpHandler .build(); } + @Test public void testRequestToFooHandler() throws Exception { URI url = new URI("http://localhost:" + this.port + "/foo"); @@ -115,7 +115,6 @@ public class SimpleUrlHandlerMappingIntegrationTests extends AbstractHttpHandler @Configuration - @SuppressWarnings({"unused", "WeakerAccess"}) static class WebConfig { @Bean diff --git a/spring-webflux/src/test/java/org/springframework/web/reactive/result/method/annotation/AbstractRequestMappingIntegrationTests.java b/spring-webflux/src/test/java/org/springframework/web/reactive/result/method/annotation/AbstractRequestMappingIntegrationTests.java index 9ee0e3ab56f..c82e8fc917b 100644 --- a/spring-webflux/src/test/java/org/springframework/web/reactive/result/method/annotation/AbstractRequestMappingIntegrationTests.java +++ b/spring-webflux/src/test/java/org/springframework/web/reactive/result/method/annotation/AbstractRequestMappingIntegrationTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2016 the original author or authors. + * Copyright 2002-2018 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.reactive.result.method.annotation; import java.net.URI; @@ -31,9 +32,7 @@ import org.springframework.http.server.reactive.HttpHandler; import org.springframework.web.client.RestTemplate; import org.springframework.web.server.adapter.WebHttpHandlerBuilder; -import static org.springframework.http.RequestEntity.get; -import static org.springframework.http.RequestEntity.options; -import static org.springframework.http.RequestEntity.post; +import static org.springframework.http.RequestEntity.*; /** * Base class for integration tests with {@code @RequestMapping methods}. diff --git a/spring-webflux/src/test/java/org/springframework/web/reactive/result/method/annotation/ControllerInputIntegrationTests.java b/spring-webflux/src/test/java/org/springframework/web/reactive/result/method/annotation/ControllerInputIntegrationTests.java index c5ad949f8d3..3a8d3068270 100644 --- a/spring-webflux/src/test/java/org/springframework/web/reactive/result/method/annotation/ControllerInputIntegrationTests.java +++ b/spring-webflux/src/test/java/org/springframework/web/reactive/result/method/annotation/ControllerInputIntegrationTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2017 the original author or authors. + * Copyright 2002-2018 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.reactive.result.method.annotation; import org.junit.Test; @@ -29,7 +30,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.*; /** * {@code @RequestMapping} integration focusing on controller method parameters. @@ -42,7 +43,6 @@ import static org.junit.Assert.assertEquals; */ public class ControllerInputIntegrationTests extends AbstractRequestMappingIntegrationTests { - @Override protected ApplicationContext initApplicationContext() { AnnotationConfigApplicationContext wac = new AnnotationConfigApplicationContext(); @@ -58,7 +58,7 @@ public class ControllerInputIntegrationTests extends AbstractRequestMappingInteg assertEquals(expected, performGet("/param?name=George", new HttpHeaders(), String.class).getBody()); } - @Test // SPR-15140 + @Test // SPR-15140 public void handleWithEncodedParam() throws Exception { String expected = "Hello + \u00e0!"; assertEquals(expected, performGet("/param?name=%20%2B+%C3%A0", new HttpHeaders(), String.class).getBody()); @@ -77,6 +77,7 @@ public class ControllerInputIntegrationTests extends AbstractRequestMappingInteg static class WebConfig { } + @RestController @SuppressWarnings("unused") private static class TestRestController { diff --git a/spring-webflux/src/test/java/org/springframework/web/reactive/result/method/annotation/CrossOriginAnnotationIntegrationTests.java b/spring-webflux/src/test/java/org/springframework/web/reactive/result/method/annotation/CrossOriginAnnotationIntegrationTests.java index 8edc02e19e8..eff3f066e7d 100644 --- a/spring-webflux/src/test/java/org/springframework/web/reactive/result/method/annotation/CrossOriginAnnotationIntegrationTests.java +++ b/spring-webflux/src/test/java/org/springframework/web/reactive/result/method/annotation/CrossOriginAnnotationIntegrationTests.java @@ -41,9 +41,7 @@ import org.springframework.web.bind.annotation.RestController; import org.springframework.web.client.RestTemplate; import org.springframework.web.reactive.config.EnableWebFlux; -import static org.junit.Assert.assertArrayEquals; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNull; +import static org.junit.Assert.*; /** * Integration tests with {@code @CrossOrigin} and {@code @RequestMapping} @@ -105,7 +103,7 @@ public class CrossOriginAnnotationIntegrationTests extends AbstractRequestMappin ResponseEntity entity = performGet("/default", this.headers, String.class); assertEquals(HttpStatus.OK, entity.getStatusCode()); assertEquals("*", entity.getHeaders().getAccessControlAllowOrigin()); - assertEquals(false, entity.getHeaders().getAccessControlAllowCredentials()); + assertFalse(entity.getHeaders().getAccessControlAllowCredentials()); assertEquals("default", entity.getBody()); } @@ -116,7 +114,7 @@ public class CrossOriginAnnotationIntegrationTests extends AbstractRequestMappin assertEquals(HttpStatus.OK, entity.getStatusCode()); assertEquals("*", entity.getHeaders().getAccessControlAllowOrigin()); assertEquals(1800, entity.getHeaders().getAccessControlMaxAge()); - assertEquals(false, entity.getHeaders().getAccessControlAllowCredentials()); + assertFalse(entity.getHeaders().getAccessControlAllowCredentials()); } @Test @@ -133,7 +131,7 @@ public class CrossOriginAnnotationIntegrationTests extends AbstractRequestMappin ResponseEntity entity = performGet("/customized", this.headers, String.class); assertEquals(HttpStatus.OK, entity.getStatusCode()); assertEquals("http://site1.com", entity.getHeaders().getAccessControlAllowOrigin()); - assertEquals(false, entity.getHeaders().getAccessControlAllowCredentials()); + assertFalse(entity.getHeaders().getAccessControlAllowCredentials()); assertEquals(-1, entity.getHeaders().getAccessControlMaxAge()); assertEquals("customized", entity.getBody()); } @@ -152,7 +150,7 @@ public class CrossOriginAnnotationIntegrationTests extends AbstractRequestMappin entity.getHeaders().getAccessControlAllowHeaders().toArray()); assertArrayEquals(new String[] {"header3", "header4"}, entity.getHeaders().getAccessControlExposeHeaders().toArray()); - assertEquals(false, entity.getHeaders().getAccessControlAllowCredentials()); + assertFalse(entity.getHeaders().getAccessControlAllowCredentials()); assertEquals(123, entity.getHeaders().getAccessControlMaxAge()); } @@ -177,19 +175,19 @@ public class CrossOriginAnnotationIntegrationTests extends AbstractRequestMappin ResponseEntity entity = performGet("/foo", this.headers, String.class); assertEquals(HttpStatus.OK, entity.getStatusCode()); assertEquals("*", entity.getHeaders().getAccessControlAllowOrigin()); - assertEquals(false, entity.getHeaders().getAccessControlAllowCredentials()); + assertFalse(entity.getHeaders().getAccessControlAllowCredentials()); assertEquals("foo", entity.getBody()); entity = performGet("/bar", this.headers, String.class); assertEquals(HttpStatus.OK, entity.getStatusCode()); assertEquals("*", entity.getHeaders().getAccessControlAllowOrigin()); - assertEquals(false, entity.getHeaders().getAccessControlAllowCredentials()); + assertFalse(entity.getHeaders().getAccessControlAllowCredentials()); assertEquals("bar", entity.getBody()); entity = performGet("/baz", this.headers, String.class); assertEquals(HttpStatus.OK, entity.getStatusCode()); assertEquals("http://site1.com", entity.getHeaders().getAccessControlAllowOrigin()); - assertEquals(true, entity.getHeaders().getAccessControlAllowCredentials()); + assertTrue(entity.getHeaders().getAccessControlAllowCredentials()); assertEquals("baz", entity.getBody()); } @@ -205,7 +203,7 @@ public class CrossOriginAnnotationIntegrationTests extends AbstractRequestMappin entity.getHeaders().getAccessControlAllowMethods().toArray()); assertArrayEquals(new String[] {"header1"}, entity.getHeaders().getAccessControlAllowHeaders().toArray()); - assertEquals(true, entity.getHeaders().getAccessControlAllowCredentials()); + assertTrue(entity.getHeaders().getAccessControlAllowCredentials()); } @Test @@ -217,7 +215,7 @@ public class CrossOriginAnnotationIntegrationTests extends AbstractRequestMappin assertEquals("http://site1.com", entity.getHeaders().getAccessControlAllowOrigin()); assertArrayEquals(new HttpMethod[] {HttpMethod.GET}, entity.getHeaders().getAccessControlAllowMethods().toArray()); - assertEquals(true, entity.getHeaders().getAccessControlAllowCredentials()); + assertTrue(entity.getHeaders().getAccessControlAllowCredentials()); } @@ -228,6 +226,7 @@ public class CrossOriginAnnotationIntegrationTests extends AbstractRequestMappin static class WebConfig { } + @RestController @SuppressWarnings("unused") private static class MethodLevelController { @@ -299,6 +298,7 @@ public class CrossOriginAnnotationIntegrationTests extends AbstractRequestMappin } } + @RestController @CrossOrigin(allowCredentials = "false") @SuppressWarnings("unused") diff --git a/spring-webflux/src/test/java/org/springframework/web/reactive/result/method/annotation/ProtobufIntegrationTests.java b/spring-webflux/src/test/java/org/springframework/web/reactive/result/method/annotation/ProtobufIntegrationTests.java index f542bea9780..685be1b8598 100644 --- a/spring-webflux/src/test/java/org/springframework/web/reactive/result/method/annotation/ProtobufIntegrationTests.java +++ b/spring-webflux/src/test/java/org/springframework/web/reactive/result/method/annotation/ProtobufIntegrationTests.java @@ -43,11 +43,19 @@ import org.springframework.web.reactive.protobuf.SecondMsg; */ public class ProtobufIntegrationTests extends AbstractRequestMappingIntegrationTests { - public static final Msg TEST_MSG = Msg.newBuilder().setFoo("Foo").setBlah(SecondMsg.newBuilder().setBlah(123).build()).build(); + public static final Msg TEST_MSG = + Msg.newBuilder().setFoo("Foo").setBlah(SecondMsg.newBuilder().setBlah(123).build()).build(); private WebClient webClient; + @Override + @Before + public void setup() throws Exception { + super.setup(); + this.webClient = WebClient.create("http://localhost:" + this.port); + } + @Override protected ApplicationContext initApplicationContext() { AnnotationConfigApplicationContext wac = new AnnotationConfigApplicationContext(); @@ -56,12 +64,6 @@ public class ProtobufIntegrationTests extends AbstractRequestMappingIntegrationT return wac; } - @Override - @Before - public void setup() throws Exception { - super.setup(); - this.webClient = WebClient.create("http://localhost:" + this.port); - } @Test public void value() { @@ -140,6 +142,7 @@ public class ProtobufIntegrationTests extends AbstractRequestMappingIntegrationT .verifyComplete(); } + @RestController @SuppressWarnings("unused") static class ProtobufController { @@ -156,7 +159,8 @@ public class ProtobufIntegrationTests extends AbstractRequestMappingIntegrationT @GetMapping(value = "/message-stream", produces = "application/x-protobuf;delimited=true") Flux messageStream() { - return testInterval(Duration.ofMillis(50), 5).map(l -> Msg.newBuilder().setFoo("Foo").setBlah(SecondMsg.newBuilder().setBlah(l.intValue()).build()).build()); + return testInterval(Duration.ofMillis(50), 5).map(l -> + Msg.newBuilder().setFoo("Foo").setBlah(SecondMsg.newBuilder().setBlah(l.intValue()).build()).build()); } @GetMapping("/empty") @@ -168,13 +172,14 @@ public class ProtobufIntegrationTests extends AbstractRequestMappingIntegrationT Mono defaultInstance() { return Mono.just(Msg.getDefaultInstance()); } - } + @Configuration @EnableWebFlux @ComponentScan(resourcePattern = "**/ProtobufIntegrationTests*.class") @SuppressWarnings("unused") static class TestConfiguration { } + } 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 77b750331a5..63362edb52c 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 @@ -76,7 +76,7 @@ public class RequestMappingExceptionHandlingIntegrationTests extends AbstractReq doTest("/mono-error", "Recovered from error: Argument"); } - @Test // SPR-16051 + @Test // SPR-16051 public void exceptionAfterSeveralItems() { try { performGet("/SPR-16051", new HttpHeaders(), String.class).getBody(); @@ -89,7 +89,7 @@ public class RequestMappingExceptionHandlingIntegrationTests extends AbstractReq } } - @Test // SPR-16318 + @Test // SPR-16318 public void exceptionFromMethodWithProducesCondition() throws Exception { try { HttpHeaders headers = new HttpHeaders(); @@ -178,7 +178,9 @@ public class RequestMappingExceptionHandlingIntegrationTests extends AbstractReq } } + @SuppressWarnings("serial") - private static class Spr16318Exception extends Exception {} + private static class Spr16318Exception extends Exception { + } } 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 e9053df21fc..a62a9996dd1 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-2017 the original author or authors. + * Copyright 2002-2018 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. @@ -43,8 +43,7 @@ import org.springframework.web.reactive.config.WebFluxConfigurer; 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.junit.Assert.*; /** * {@code @RequestMapping} integration tests with view resolution scenarios. @@ -78,10 +77,9 @@ public class RequestMappingViewResolutionIntegrationTests extends AbstractReques assertNull(response.getBody()); } - @Test // SPR-15291 + @Test // SPR-15291 public void redirect() throws Exception { SimpleClientHttpRequestFactory factory = new SimpleClientHttpRequestFactory() { - @Override protected void prepareConnection(HttpURLConnection conn, String method) throws IOException { super.prepareConnection(conn, method); diff --git a/spring-webflux/src/test/java/org/springframework/web/reactive/result/method/annotation/SseIntegrationTests.java b/spring-webflux/src/test/java/org/springframework/web/reactive/result/method/annotation/SseIntegrationTests.java index 29128d50eb3..5f577f51e6b 100644 --- a/spring-webflux/src/test/java/org/springframework/web/reactive/result/method/annotation/SseIntegrationTests.java +++ b/spring-webflux/src/test/java/org/springframework/web/reactive/result/method/annotation/SseIntegrationTests.java @@ -81,6 +81,7 @@ public class SseIntegrationTests extends AbstractHttpHandlerIntegrationTests { }; } + @Override @Before public void setup() throws Exception { @@ -92,7 +93,6 @@ public class SseIntegrationTests extends AbstractHttpHandlerIntegrationTests { .build(); } - @Override protected HttpHandler createHttpHandler() { this.wac = new AnnotationConfigApplicationContext(); diff --git a/spring-webflux/src/test/java/org/springframework/web/reactive/result/view/LocaleContextResolverIntegrationTests.java b/spring-webflux/src/test/java/org/springframework/web/reactive/result/view/LocaleContextResolverIntegrationTests.java index d0c1958fee5..dc5210e99c2 100644 --- a/spring-webflux/src/test/java/org/springframework/web/reactive/result/view/LocaleContextResolverIntegrationTests.java +++ b/spring-webflux/src/test/java/org/springframework/web/reactive/result/view/LocaleContextResolverIntegrationTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2017 the original author or authors. + * Copyright 2002-2018 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,11 +39,11 @@ import org.springframework.web.reactive.config.WebFluxConfigurationSupport; import org.springframework.web.reactive.function.client.ClientResponse; import org.springframework.web.reactive.function.client.WebClient; import org.springframework.web.reactive.result.method.annotation.AbstractRequestMappingIntegrationTests; -import org.springframework.web.server.i18n.LocaleContextResolver; import org.springframework.web.server.ServerWebExchange; import org.springframework.web.server.i18n.FixedLocaleContextResolver; +import org.springframework.web.server.i18n.LocaleContextResolver; -import static org.junit.Assert.assertEquals; +import static org.junit.Assert.*; /** * @author Sebastien Deleuze @@ -52,6 +52,15 @@ public class LocaleContextResolverIntegrationTests extends AbstractRequestMappin private final WebClient webClient = WebClient.create(); + + @Override + protected ApplicationContext initApplicationContext() { + AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(); + context.register(WebConfig.class); + context.refresh(); + return context; + } + @Test public void fixedLocale() { Mono result = webClient @@ -67,14 +76,6 @@ public class LocaleContextResolverIntegrationTests extends AbstractRequestMappin .verifyComplete(); } - @Override - protected ApplicationContext initApplicationContext() { - AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(); - context.register(WebConfig.class); - context.refresh(); - return context; - } - @Configuration @ComponentScan(resourcePattern = "**/LocaleContextResolverIntegrationTests*.class") @@ -111,9 +112,9 @@ public class LocaleContextResolverIntegrationTests extends AbstractRequestMappin return Mono.empty(); } } - } + @Controller @SuppressWarnings("unused") static class TestController { @@ -122,7 +123,6 @@ public class LocaleContextResolverIntegrationTests extends AbstractRequestMappin public String foo() { return "foo"; } - } }