Skip to content

Commit 3d7e373

Browse files
committed
Polishing
(cherry picked from commit 77ab88b)
1 parent f0e69e0 commit 3d7e373

22 files changed

+112
-113
lines changed

spring-web/src/test/java/org/springframework/http/server/reactive/AbstractHttpHandlerIntegrationTests.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ public void tearDown() throws Exception {
8888
* set the number of buffered to an arbitrary number greater than N.
8989
* </ul>
9090
*/
91-
public static Flux<Long> interval(Duration period, int count) {
91+
public static Flux<Long> testInterval(Duration period, int count) {
9292
return Flux.interval(period).take(count).onBackpressureBuffer(count);
9393
}
9494

spring-web/src/test/java/org/springframework/http/server/reactive/CookieIntegrationTests.java

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2015 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.http.server.reactive;
1718

1819
import java.net.URI;
@@ -27,27 +28,25 @@
2728

2829
import org.springframework.http.HttpCookie;
2930
import org.springframework.http.RequestEntity;
30-
import org.springframework.http.ResponseEntity;
3131
import org.springframework.http.ResponseCookie;
32+
import org.springframework.http.ResponseEntity;
3233
import org.springframework.web.client.RestTemplate;
3334

3435
import static org.hamcrest.CoreMatchers.equalTo;
35-
import static org.hamcrest.Matchers.containsInAnyOrder;
36-
import static org.hamcrest.Matchers.equalToIgnoringCase;
37-
import static org.junit.Assert.assertEquals;
38-
import static org.junit.Assert.assertThat;
36+
import static org.hamcrest.Matchers.*;
37+
import static org.junit.Assert.*;
3938

4039
/**
4140
* @author Rossen Stoyanchev
4241
*/
4342
@RunWith(Parameterized.class)
4443
public class CookieIntegrationTests extends AbstractHttpHandlerIntegrationTests {
4544

46-
private CookieHandler cookieHandler;
45+
private final CookieHandler cookieHandler = new CookieHandler();
46+
4747

4848
@Override
4949
protected HttpHandler createHttpHandler() {
50-
this.cookieHandler = new CookieHandler();
5150
return this.cookieHandler;
5251
}
5352

spring-web/src/test/java/org/springframework/http/server/reactive/EchoHandlerIntegrationTests.java

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2016 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.
@@ -26,14 +26,16 @@
2626
import org.springframework.http.ResponseEntity;
2727
import org.springframework.web.client.RestTemplate;
2828

29-
import static org.junit.Assert.assertArrayEquals;
30-
29+
import static org.junit.Assert.*;
3130

31+
/**
32+
* @author Arjen Poutsma
33+
*/
3234
public class EchoHandlerIntegrationTests extends AbstractHttpHandlerIntegrationTests {
3335

3436
private static final int REQUEST_SIZE = 4096 * 3;
3537

36-
private Random rnd = new Random();
38+
private final Random rnd = new Random();
3739

3840

3941
@Override

spring-web/src/test/java/org/springframework/http/server/reactive/ErrorHandlerIntegrationTests.java

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2016 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.
@@ -28,21 +28,23 @@
2828
import org.springframework.web.client.ResponseErrorHandler;
2929
import org.springframework.web.client.RestTemplate;
3030

31-
import static org.junit.Assert.assertEquals;
32-
import static org.junit.Assume.assumeFalse;
31+
import static org.junit.Assert.*;
32+
import static org.junit.Assume.*;
3333

3434
/**
3535
* @author Arjen Poutsma
3636
*/
3737
public class ErrorHandlerIntegrationTests extends AbstractHttpHandlerIntegrationTests {
3838

39-
private ErrorHandler handler = new ErrorHandler();
39+
private final ErrorHandler handler = new ErrorHandler();
40+
4041

4142
@Override
4243
protected HttpHandler createHttpHandler() {
4344
return handler;
4445
}
4546

47+
4648
@Test
4749
public void responseBodyError() throws Exception {
4850
// TODO: fix Reactor
@@ -83,6 +85,7 @@ public void emptyPathSegments() throws Exception {
8385
assertEquals(HttpStatus.OK, response.getStatusCode());
8486
}
8587

88+
8689
private static class ErrorHandler implements HttpHandler {
8790

8891
@Override
@@ -101,6 +104,7 @@ else if (path.endsWith("handling-error")) {
101104
}
102105
}
103106

107+
104108
private static final ResponseErrorHandler NO_OP_ERROR_HANDLER = new ResponseErrorHandler() {
105109

106110
@Override

spring-web/src/test/java/org/springframework/http/server/reactive/RandomHandlerIntegrationTests.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2016 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.
@@ -33,6 +33,9 @@
3333

3434
import static org.junit.Assert.*;
3535

36+
/**
37+
* @author Arjen Poutsma
38+
*/
3639
public class RandomHandlerIntegrationTests extends AbstractHttpHandlerIntegrationTests {
3740

3841
public static final int REQUEST_SIZE = 4096 * 3;

spring-web/src/test/java/org/springframework/http/server/reactive/ServerHttpRequestIntegrationTests.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,9 @@
2828

2929
import static org.junit.Assert.*;
3030

31+
/**
32+
* @author Sebastien Deleuze
33+
*/
3134
public class ServerHttpRequestIntegrationTests extends AbstractHttpHandlerIntegrationTests {
3235

3336
@Override
@@ -58,4 +61,5 @@ public Mono<Void> handle(ServerHttpRequest request, ServerHttpResponse response)
5861
return Mono.empty();
5962
}
6063
}
64+
6165
}

spring-web/src/test/java/org/springframework/http/server/reactive/WriteOnlyHandlerIntegrationTests.java

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2016 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.
@@ -21,19 +21,16 @@
2121
import java.util.Random;
2222

2323
import org.junit.Test;
24+
import reactor.core.publisher.Flux;
25+
import reactor.core.publisher.Mono;
26+
2427
import org.springframework.core.io.buffer.DataBuffer;
2528
import org.springframework.http.RequestEntity;
2629
import org.springframework.http.ResponseEntity;
27-
import org.springframework.http.server.reactive.HttpHandler;
28-
import org.springframework.http.server.reactive.ServerHttpRequest;
29-
import org.springframework.http.server.reactive.ServerHttpResponse;
3030
import org.springframework.web.client.RestTemplate;
3131

3232
import static org.junit.Assert.*;
3333

34-
import reactor.core.publisher.Flux;
35-
import reactor.core.publisher.Mono;
36-
3734
/**
3835
* @author Violeta Georgieva
3936
* @since 5.0
@@ -52,7 +49,6 @@ protected WriteOnlyHandler createHttpHandler() {
5249
return new WriteOnlyHandler();
5350
}
5451

55-
5652
@Test
5753
public void writeOnly() throws Exception {
5854
RestTemplate restTemplate = new RestTemplate();
@@ -66,7 +62,6 @@ public void writeOnly() throws Exception {
6662
assertArrayEquals(body, response.getBody());
6763
}
6864

69-
7065
private byte[] randomBytes() {
7166
byte[] buffer = new byte[REQUEST_SIZE];
7267
rnd.nextBytes(buffer);
@@ -83,4 +78,5 @@ public Mono<Void> handle(ServerHttpRequest request, ServerHttpResponse response)
8378
return response.writeAndFlushWith(Flux.just(Flux.just(buffer)));
8479
}
8580
}
81+
8682
}

spring-web/src/test/java/org/springframework/http/server/reactive/ZeroCopyIntegrationTests.java

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,8 @@
3232
import org.springframework.http.server.reactive.bootstrap.UndertowHttpServer;
3333
import org.springframework.web.client.RestTemplate;
3434

35-
import static org.junit.Assert.assertEquals;
36-
import static org.junit.Assert.assertTrue;
37-
import static org.junit.Assume.assumeTrue;
35+
import static org.junit.Assert.*;
36+
import static org.junit.Assume.*;
3837

3938
/**
4039
* @author Arjen Poutsma
@@ -43,14 +42,15 @@ public class ZeroCopyIntegrationTests extends AbstractHttpHandlerIntegrationTest
4342

4443
private final ZeroCopyHandler handler = new ZeroCopyHandler();
4544

45+
4646
@Override
4747
protected HttpHandler createHttpHandler() {
48-
return handler;
48+
return this.handler;
4949
}
5050

51+
5152
@Test
5253
public void zeroCopy() throws Exception {
53-
5454
// Zero-copy only does not support servlet
5555
assumeTrue(server instanceof ReactorHttpServer || server instanceof UndertowHttpServer);
5656

@@ -64,9 +64,9 @@ public void zeroCopy() throws Exception {
6464
assertEquals(logo.contentLength(), response.getHeaders().getContentLength());
6565
assertEquals(logo.contentLength(), response.getBody().length);
6666
assertEquals(MediaType.IMAGE_PNG, response.getHeaders().getContentType());
67-
6867
}
6968

69+
7070
private static class ZeroCopyHandler implements HttpHandler {
7171

7272
@Override
@@ -85,4 +85,4 @@ public Mono<Void> handle(ServerHttpRequest request, ServerHttpResponse response)
8585
}
8686
}
8787

88-
}
88+
}

spring-web/src/test/java/org/springframework/web/server/session/WebSessionIntegrationTests.java

Lines changed: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2016 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.
@@ -38,31 +38,22 @@
3838
import org.springframework.web.server.WebSession;
3939
import org.springframework.web.server.adapter.WebHttpHandlerBuilder;
4040

41-
import static org.junit.Assert.assertEquals;
42-
import static org.junit.Assert.assertNotEquals;
43-
import static org.junit.Assert.assertNotNull;
44-
import static org.junit.Assert.assertNull;
45-
import static org.junit.Assert.assertTrue;
41+
import static org.junit.Assert.*;
4642

4743
/**
4844
* Integration tests for with a server-side session.
45+
*
4946
* @author Rossen Stoyanchev
5047
*/
5148
public class WebSessionIntegrationTests extends AbstractHttpHandlerIntegrationTests {
5249

53-
private RestTemplate restTemplate;
50+
private final RestTemplate restTemplate = new RestTemplate();
5451

5552
private DefaultWebSessionManager sessionManager;
5653

5754
private TestWebHandler handler;
5855

5956

60-
@Override
61-
public void setup() throws Exception {
62-
super.setup();
63-
this.restTemplate = new RestTemplate();
64-
}
65-
6657
@Override
6758
protected HttpHandler createHttpHandler() {
6859
this.sessionManager = new DefaultWebSessionManager();

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ private static class FlushingHandler implements HttpHandler {
123123
public Mono<Void> handle(ServerHttpRequest request, ServerHttpResponse response) {
124124
String path = request.getURI().getPath();
125125
if (path.endsWith("write-and-flush")) {
126-
Flux<Publisher<DataBuffer>> responseBody = interval(Duration.ofMillis(50), 2)
126+
Flux<Publisher<DataBuffer>> responseBody = testInterval(Duration.ofMillis(50), 2)
127127
.map(l -> toDataBuffer("data" + l + "\n", response.bufferFactory()))
128128
.map(Flux::just);
129129
return response.writeAndFlushWith(responseBody.concatWith(Flux.never()));

0 commit comments

Comments
 (0)