Skip to content

Commit 0c44b52

Browse files
committed
Polishing
(cherry picked from commit dd4468a)
1 parent 207e8c2 commit 0c44b52

File tree

5 files changed

+40
-43
lines changed

5 files changed

+40
-43
lines changed

spring-webflux/src/test/java/org/springframework/web/reactive/DispatcherHandlerErrorTests.java

Lines changed: 16 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2017 the original author or authors.
2+
* Copyright 2002-2018 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -52,10 +52,8 @@
5252
import static org.hamcrest.CoreMatchers.instanceOf;
5353
import static org.hamcrest.CoreMatchers.startsWith;
5454
import static org.hamcrest.Matchers.is;
55-
import static org.junit.Assert.assertEquals;
56-
import static org.junit.Assert.assertSame;
57-
import static org.junit.Assert.assertThat;
58-
import static org.springframework.http.MediaType.APPLICATION_JSON;
55+
import static org.junit.Assert.*;
56+
import static org.springframework.http.MediaType.*;
5957

6058
/**
6159
* Test the effect of exceptions at different stages of request processing by
@@ -72,7 +70,7 @@ public class DispatcherHandlerErrorTests {
7270

7371

7472
@Before
75-
public void setup() throws Exception {
73+
public void setup() {
7674
AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext();
7775
ctx.register(TestConfig.class);
7876
ctx.refresh();
@@ -81,20 +79,21 @@ public void setup() throws Exception {
8179

8280

8381
@Test
84-
public void noHandler() throws Exception {
82+
public void noHandler() {
8583
MockServerWebExchange exchange = MockServerWebExchange.from(MockServerHttpRequest.get("/does-not-exist"));
8684
Mono<Void> publisher = this.dispatcherHandler.handle(exchange);
8785

8886
StepVerifier.create(publisher)
8987
.consumeErrorWith(error -> {
9088
assertThat(error, instanceOf(ResponseStatusException.class));
91-
assertThat(error.getMessage(), is("Response status 404 with reason \"No matching handler\""));
89+
assertThat(error.getMessage(),
90+
is("Response status 404 with reason \"No matching handler\""));
9291
})
9392
.verify();
9493
}
9594

9695
@Test
97-
public void controllerReturnsMonoError() throws Exception {
96+
public void controllerReturnsMonoError() {
9897
MockServerWebExchange exchange = MockServerWebExchange.from(MockServerHttpRequest.get("/error-signal"));
9998
Mono<Void> publisher = this.dispatcherHandler.handle(exchange);
10099

@@ -104,7 +103,7 @@ public void controllerReturnsMonoError() throws Exception {
104103
}
105104

106105
@Test
107-
public void controllerThrowsException() throws Exception {
106+
public void controllerThrowsException() {
108107
MockServerWebExchange exchange = MockServerWebExchange.from(MockServerHttpRequest.get("/raise-exception"));
109108
Mono<Void> publisher = this.dispatcherHandler.handle(exchange);
110109

@@ -114,7 +113,7 @@ public void controllerThrowsException() throws Exception {
114113
}
115114

116115
@Test
117-
public void unknownReturnType() throws Exception {
116+
public void unknownReturnType() {
118117
MockServerWebExchange exchange = MockServerWebExchange.from(MockServerHttpRequest.get("/unknown-return-type"));
119118
Mono<Void> publisher = this.dispatcherHandler.handle(exchange);
120119

@@ -127,7 +126,7 @@ public void unknownReturnType() throws Exception {
127126
}
128127

129128
@Test
130-
public void responseBodyMessageConversionError() throws Exception {
129+
public void responseBodyMessageConversionError() {
131130
ServerWebExchange exchange = MockServerWebExchange.from(
132131
MockServerHttpRequest.post("/request-body").accept(APPLICATION_JSON).body("body"));
133132

@@ -139,10 +138,10 @@ public void responseBodyMessageConversionError() throws Exception {
139138
}
140139

141140
@Test
142-
public void requestBodyError() throws Exception {
141+
public void requestBodyError() {
143142
ServerWebExchange exchange = MockServerWebExchange.from(
144143
MockServerHttpRequest.post("/request-body").body(Mono.error(EXCEPTION)));
145-
144+
146145
Mono<Void> publisher = this.dispatcherHandler.handle(exchange);
147146

148147
StepVerifier.create(publisher)
@@ -151,7 +150,7 @@ public void requestBodyError() throws Exception {
151150
}
152151

153152
@Test
154-
public void webExceptionHandler() throws Exception {
153+
public void webExceptionHandler() {
155154
ServerWebExchange exchange = MockServerWebExchange.from(MockServerHttpRequest.get("/unknown-argument-type"));
156155

157156
List<WebExceptionHandler> handlers = Collections.singletonList(new ServerError500ExceptionHandler());
@@ -201,12 +200,12 @@ public Publisher<String> errorSignal() {
201200
}
202201

203202
@RequestMapping("/raise-exception")
204-
public void raiseException() throws Exception {
203+
public void raiseException() {
205204
throw EXCEPTION;
206205
}
207206

208207
@RequestMapping("/unknown-return-type")
209-
public Foo unknownReturnType() throws Exception {
208+
public Foo unknownReturnType() {
210209
return new Foo();
211210
}
212211

spring-webflux/src/test/java/org/springframework/web/reactive/DispatcherHandlerTests.java

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2017 the original author or authors.
2+
* Copyright 2002-2018 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -13,6 +13,7 @@
1313
* See the License for the specific language governing permissions and
1414
* limitations under the License.
1515
*/
16+
1617
package org.springframework.web.reactive;
1718

1819
import java.nio.charset.StandardCharsets;
@@ -32,11 +33,9 @@
3233
import org.springframework.web.method.ResolvableMethod;
3334
import org.springframework.web.server.ServerWebExchange;
3435

35-
import static org.junit.Assert.assertEquals;
36-
import static org.mockito.ArgumentMatchers.any;
37-
import static org.mockito.Mockito.mock;
38-
import static org.mockito.Mockito.when;
39-
import static org.mockito.Mockito.withSettings;
36+
import static org.junit.Assert.*;
37+
import static org.mockito.ArgumentMatchers.*;
38+
import static org.mockito.Mockito.*;
4039

4140
/**
4241
* Unit tests for {@link DispatcherHandler}.
@@ -49,8 +48,7 @@ public class DispatcherHandlerTests {
4948

5049

5150
@Test
52-
public void handlerMappingOrder() throws Exception {
53-
51+
public void handlerMappingOrder() {
5452
HandlerMapping hm1 = mock(HandlerMapping.class, withSettings().extraInterfaces(Ordered.class));
5553
HandlerMapping hm2 = mock(HandlerMapping.class, withSettings().extraInterfaces(Ordered.class));
5654
when(((Ordered) hm1).getOrder()).thenReturn(1);
@@ -90,6 +88,7 @@ public Mono<HandlerResult> handle(ServerWebExchange exchange, Object handler) {
9088
}
9189
}
9290

91+
9392
private static class StringHandlerResultHandler implements HandlerResultHandler {
9493

9594
@Override
@@ -105,4 +104,5 @@ public Mono<Void> handleResult(ServerWebExchange exchange, HandlerResult result)
105104
return exchange.getResponse().writeWith(Mono.just(dataBuffer));
106105
}
107106
}
107+
108108
}

spring-webflux/src/test/java/org/springframework/web/reactive/FlushingIntegrationTests.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,10 @@
3737
import static org.junit.Assert.*;
3838

3939
/**
40+
* Integration tests for server response flushing behavior.
41+
*
4042
* @author Sebastien Deleuze
43+
* @author Rossen Stoyanchev
4144
* @since 5.0
4245
*/
4346
public class FlushingIntegrationTests extends AbstractHttpHandlerIntegrationTests {
@@ -83,7 +86,8 @@ public void writeAndAutoFlushOnComplete() {
8386
}
8487
catch (AssertionError err) {
8588
String os = System.getProperty("os.name").toLowerCase();
86-
if (os.contains("windows") && err.getMessage().startsWith("VerifySubscriber timed out")) {
89+
if (os.contains("windows") && err.getMessage() != null &&
90+
err.getMessage().startsWith("VerifySubscriber timed out")) {
8791
// TODO: Reactor usually times out on Windows ...
8892
err.printStackTrace();
8993
return;

spring-webflux/src/test/java/org/springframework/web/reactive/socket/AbstractWebSocketIntegrationTests.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2017 the original author or authors.
2+
* Copyright 2002-2018 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -114,7 +114,6 @@ public static Object[][] arguments() throws IOException {
114114

115115
@Before
116116
public void setup() throws Exception {
117-
118117
this.server.setHandler(createHttpHandler());
119118
this.server.afterPropertiesSet();
120119
this.server.start();
@@ -128,7 +127,7 @@ public void setup() throws Exception {
128127
}
129128

130129
@After
131-
public void stop() throws Exception {
130+
public void stop() {
132131
if (this.client instanceof Lifecycle) {
133132
((Lifecycle) this.client).stop();
134133
}

spring-webflux/src/test/java/org/springframework/web/reactive/socket/WebSocketIntegrationTests.java

Lines changed: 9 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -38,11 +38,11 @@
3838
import org.springframework.web.reactive.HandlerMapping;
3939
import org.springframework.web.reactive.handler.SimpleUrlHandlerMapping;
4040

41-
import static org.junit.Assert.assertEquals;
42-
import static org.junit.Assert.assertThat;
41+
import static org.junit.Assert.*;
4342

4443
/**
4544
* Integration tests with server-side {@link WebSocketHandler}s.
45+
*
4646
* @author Rossen Stoyanchev
4747
*/
4848
public class WebSocketIntegrationTests extends AbstractWebSocketIntegrationTests {
@@ -64,17 +64,11 @@ public void echo() throws Exception {
6464
Flux<String> input = Flux.range(1, count).map(index -> "msg-" + index);
6565
ReplayProcessor<Object> output = ReplayProcessor.create(count);
6666

67-
this.client.execute(getUrl("/echo"),
68-
session -> {
69-
logger.debug("Starting to send messages");
70-
return session
71-
.send(input.doOnNext(s -> logger.debug("outbound " + s)).map(session::textMessage))
72-
.thenMany(session.receive().take(count).map(WebSocketMessage::getPayloadAsText))
73-
.subscribeWith(output)
74-
.doOnNext(s -> logger.debug("inbound " + s))
75-
.then();
76-
})
77-
.doOnSuccessOrError((aVoid, ex) -> logger.debug("Done: " + (ex != null ? ex.getMessage() : "success")))
67+
this.client.execute(getUrl("/echo"), session -> session
68+
.send(input.map(session::textMessage))
69+
.thenMany(session.receive().take(count).map(WebSocketMessage::getPayloadAsText))
70+
.subscribeWith(output)
71+
.then())
7872
.block(TIMEOUT);
7973

8074
assertEquals(input.collectList().block(TIMEOUT), output.collectList().block(TIMEOUT));
@@ -181,7 +175,7 @@ public List<String> getSubProtocols() {
181175
@Override
182176
public Mono<Void> handle(WebSocketSession session) {
183177
String protocol = session.getHandshakeInfo().getSubProtocol();
184-
WebSocketMessage message = session.textMessage(protocol);
178+
WebSocketMessage message = session.textMessage(protocol != null ? protocol : "none");
185179
return session.send(Mono.just(message));
186180
}
187181
}
@@ -198,6 +192,7 @@ public Mono<Void> handle(WebSocketSession session) {
198192
}
199193
}
200194

195+
201196
private static class SessionClosingHandler implements WebSocketHandler {
202197

203198
@Override

0 commit comments

Comments
 (0)