From dd4468a74a40c3e6d879ea2dd6d4b563b1f5240c Mon Sep 17 00:00:00 2001 From: Juergen Hoeller Date: Tue, 24 Jul 2018 16:16:52 +0200 Subject: [PATCH] Polishing --- .../reactive/DispatcherHandlerErrorTests.java | 26 +++++++++---------- .../web/reactive/DispatcherHandlerTests.java | 16 ++++++------ .../reactive/FlushingIntegrationTests.java | 2 ++ .../AbstractWebSocketIntegrationTests.java | 5 ++-- .../socket/WebSocketIntegrationTests.java | 5 ++-- .../HandshakeWebSocketServiceTests.java | 4 +-- 6 files changed, 28 insertions(+), 30 deletions(-) diff --git a/spring-webflux/src/test/java/org/springframework/web/reactive/DispatcherHandlerErrorTests.java b/spring-webflux/src/test/java/org/springframework/web/reactive/DispatcherHandlerErrorTests.java index 64e97eadc6b..e4d34801a3c 100644 --- a/spring-webflux/src/test/java/org/springframework/web/reactive/DispatcherHandlerErrorTests.java +++ b/spring-webflux/src/test/java/org/springframework/web/reactive/DispatcherHandlerErrorTests.java @@ -52,10 +52,8 @@ import org.springframework.web.server.handler.ExceptionHandlingWebHandler; import static org.hamcrest.CoreMatchers.instanceOf; import static org.hamcrest.CoreMatchers.startsWith; import static org.hamcrest.Matchers.is; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertSame; -import static org.junit.Assert.assertThat; -import static org.springframework.http.MediaType.APPLICATION_JSON; +import static org.junit.Assert.*; +import static org.springframework.http.MediaType.*; /** * Test the effect of exceptions at different stages of request processing by @@ -72,7 +70,7 @@ public class DispatcherHandlerErrorTests { @Before - public void setup() throws Exception { + public void setup() { AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext(); ctx.register(TestConfig.class); ctx.refresh(); @@ -81,7 +79,7 @@ public class DispatcherHandlerErrorTests { @Test - public void noHandler() throws Exception { + public void noHandler() { MockServerWebExchange exchange = MockServerWebExchange.from(MockServerHttpRequest.get("/does-not-exist")); Mono publisher = this.dispatcherHandler.handle(exchange); @@ -95,7 +93,7 @@ public class DispatcherHandlerErrorTests { } @Test - public void controllerReturnsMonoError() throws Exception { + public void controllerReturnsMonoError() { MockServerWebExchange exchange = MockServerWebExchange.from(MockServerHttpRequest.get("/error-signal")); Mono publisher = this.dispatcherHandler.handle(exchange); @@ -105,7 +103,7 @@ public class DispatcherHandlerErrorTests { } @Test - public void controllerThrowsException() throws Exception { + public void controllerThrowsException() { MockServerWebExchange exchange = MockServerWebExchange.from(MockServerHttpRequest.get("/raise-exception")); Mono publisher = this.dispatcherHandler.handle(exchange); @@ -115,7 +113,7 @@ public class DispatcherHandlerErrorTests { } @Test - public void unknownReturnType() throws Exception { + public void unknownReturnType() { MockServerWebExchange exchange = MockServerWebExchange.from(MockServerHttpRequest.get("/unknown-return-type")); Mono publisher = this.dispatcherHandler.handle(exchange); @@ -128,7 +126,7 @@ public class DispatcherHandlerErrorTests { } @Test - public void responseBodyMessageConversionError() throws Exception { + public void responseBodyMessageConversionError() { ServerWebExchange exchange = MockServerWebExchange.from( MockServerHttpRequest.post("/request-body").accept(APPLICATION_JSON).body("body")); @@ -140,7 +138,7 @@ public class DispatcherHandlerErrorTests { } @Test - public void requestBodyError() throws Exception { + public void requestBodyError() { ServerWebExchange exchange = MockServerWebExchange.from( MockServerHttpRequest.post("/request-body").body(Mono.error(EXCEPTION))); @@ -152,7 +150,7 @@ public class DispatcherHandlerErrorTests { } @Test - public void webExceptionHandler() throws Exception { + public void webExceptionHandler() { ServerWebExchange exchange = MockServerWebExchange.from(MockServerHttpRequest.get("/unknown-argument-type")); List handlers = Collections.singletonList(new ServerError500ExceptionHandler()); @@ -202,12 +200,12 @@ public class DispatcherHandlerErrorTests { } @RequestMapping("/raise-exception") - public void raiseException() throws Exception { + public void raiseException() { throw EXCEPTION; } @RequestMapping("/unknown-return-type") - public Foo unknownReturnType() throws Exception { + public Foo unknownReturnType() { return new Foo(); } diff --git a/spring-webflux/src/test/java/org/springframework/web/reactive/DispatcherHandlerTests.java b/spring-webflux/src/test/java/org/springframework/web/reactive/DispatcherHandlerTests.java index 5c43f65b99c..371224472cb 100644 --- a/spring-webflux/src/test/java/org/springframework/web/reactive/DispatcherHandlerTests.java +++ b/spring-webflux/src/test/java/org/springframework/web/reactive/DispatcherHandlerTests.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; import java.nio.charset.StandardCharsets; @@ -32,11 +33,9 @@ import org.springframework.mock.web.test.server.MockServerWebExchange; import org.springframework.web.method.ResolvableMethod; import org.springframework.web.server.ServerWebExchange; -import static org.junit.Assert.assertEquals; -import static org.mockito.ArgumentMatchers.any; -import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.when; -import static org.mockito.Mockito.withSettings; +import static org.junit.Assert.*; +import static org.mockito.ArgumentMatchers.*; +import static org.mockito.Mockito.*; /** * Unit tests for {@link DispatcherHandler}. @@ -49,8 +48,7 @@ public class DispatcherHandlerTests { @Test - public void handlerMappingOrder() throws Exception { - + public void handlerMappingOrder() { HandlerMapping hm1 = mock(HandlerMapping.class, withSettings().extraInterfaces(Ordered.class)); HandlerMapping hm2 = mock(HandlerMapping.class, withSettings().extraInterfaces(Ordered.class)); when(((Ordered) hm1).getOrder()).thenReturn(1); @@ -90,6 +88,7 @@ public class DispatcherHandlerTests { } } + private static class StringHandlerResultHandler implements HandlerResultHandler { @Override @@ -105,4 +104,5 @@ public class DispatcherHandlerTests { return exchange.getResponse().writeWith(Mono.just(dataBuffer)); } } + } diff --git a/spring-webflux/src/test/java/org/springframework/web/reactive/FlushingIntegrationTests.java b/spring-webflux/src/test/java/org/springframework/web/reactive/FlushingIntegrationTests.java index e99d0f183ee..f023d45e0b2 100644 --- a/spring-webflux/src/test/java/org/springframework/web/reactive/FlushingIntegrationTests.java +++ b/spring-webflux/src/test/java/org/springframework/web/reactive/FlushingIntegrationTests.java @@ -36,6 +36,7 @@ import static org.junit.Assert.*; /** * Integration tests for server response flushing behavior. + * * @author Sebastien Deleuze * @author Rossen Stoyanchev * @since 5.0 @@ -160,4 +161,5 @@ public class FlushingIntegrationTests extends AbstractHttpHandlerIntegrationTest return response.bufferFactory().wrap(bytes); } } + } diff --git a/spring-webflux/src/test/java/org/springframework/web/reactive/socket/AbstractWebSocketIntegrationTests.java b/spring-webflux/src/test/java/org/springframework/web/reactive/socket/AbstractWebSocketIntegrationTests.java index 4b7465a434e..72e5545af36 100644 --- a/spring-webflux/src/test/java/org/springframework/web/reactive/socket/AbstractWebSocketIntegrationTests.java +++ b/spring-webflux/src/test/java/org/springframework/web/reactive/socket/AbstractWebSocketIntegrationTests.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. @@ -114,7 +114,6 @@ public abstract class AbstractWebSocketIntegrationTests { @Before public void setup() throws Exception { - this.server.setHandler(createHttpHandler()); this.server.afterPropertiesSet(); this.server.start(); @@ -128,7 +127,7 @@ public abstract class AbstractWebSocketIntegrationTests { } @After - public void stop() throws Exception { + public void stop() { if (this.client instanceof Lifecycle) { ((Lifecycle) this.client).stop(); } diff --git a/spring-webflux/src/test/java/org/springframework/web/reactive/socket/WebSocketIntegrationTests.java b/spring-webflux/src/test/java/org/springframework/web/reactive/socket/WebSocketIntegrationTests.java index 31125f71496..b952d46cac3 100644 --- a/spring-webflux/src/test/java/org/springframework/web/reactive/socket/WebSocketIntegrationTests.java +++ b/spring-webflux/src/test/java/org/springframework/web/reactive/socket/WebSocketIntegrationTests.java @@ -38,11 +38,11 @@ import org.springframework.http.HttpHeaders; import org.springframework.web.reactive.HandlerMapping; import org.springframework.web.reactive.handler.SimpleUrlHandlerMapping; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertThat; +import static org.junit.Assert.*; /** * Integration tests with server-side {@link WebSocketHandler}s. + * * @author Rossen Stoyanchev */ public class WebSocketIntegrationTests extends AbstractWebSocketIntegrationTests { @@ -192,6 +192,7 @@ public class WebSocketIntegrationTests extends AbstractWebSocketIntegrationTests } } + private static class SessionClosingHandler implements WebSocketHandler { @Override diff --git a/spring-webflux/src/test/java/org/springframework/web/reactive/socket/server/support/HandshakeWebSocketServiceTests.java b/spring-webflux/src/test/java/org/springframework/web/reactive/socket/server/support/HandshakeWebSocketServiceTests.java index 9a546d9dee3..f71e0ad30b6 100644 --- a/spring-webflux/src/test/java/org/springframework/web/reactive/socket/server/support/HandshakeWebSocketServiceTests.java +++ b/spring-webflux/src/test/java/org/springframework/web/reactive/socket/server/support/HandshakeWebSocketServiceTests.java @@ -13,6 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package org.springframework.web.reactive.socket.server.support; import java.util.Arrays; @@ -42,10 +43,8 @@ import static org.mockito.Mockito.*; */ public class HandshakeWebSocketServiceTests { - @Test public void sessionAttributePredicate() { - MockWebSession session = new MockWebSession(); session.getAttributes().put("a1", "v1"); session.getAttributes().put("a2", "v2"); @@ -86,7 +85,6 @@ public class HandshakeWebSocketServiceTests { HandshakeInfo handshakeInfo; - @Override public Mono upgrade(ServerWebExchange exchange, WebSocketHandler webSocketHandler, @Nullable String subProtocol, Supplier handshakeInfoFactory) {