Polishing
This commit is contained in:
parent
7f1a8d78b5
commit
dd4468a74a
|
|
@ -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<Void> 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<Void> 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<Void> 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<Void> 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<WebExceptionHandler> 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();
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -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));
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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<Void> upgrade(ServerWebExchange exchange, WebSocketHandler webSocketHandler,
|
||||
@Nullable String subProtocol, Supplier<HandshakeInfo> handshakeInfoFactory) {
|
||||
|
|
|
|||
Loading…
Reference in New Issue