Skip to content

Commit 571c50e

Browse files
committed
Switch to functional web code to use static imports
Update the samples and tests to use the more idiomatic static import style.
1 parent 8eba375 commit 571c50e

File tree

7 files changed

+29
-31
lines changed

7 files changed

+29
-31
lines changed

spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/endpoint/web/documentation/MappingsEndpointReactiveDocumentationTests.java

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -45,16 +45,16 @@
4545
import org.springframework.test.web.reactive.server.WebTestClient;
4646
import org.springframework.web.bind.annotation.PostMapping;
4747
import org.springframework.web.bind.annotation.RestController;
48-
import org.springframework.web.reactive.function.server.RequestPredicates;
4948
import org.springframework.web.reactive.function.server.RouterFunction;
50-
import org.springframework.web.reactive.function.server.RouterFunctions;
5149
import org.springframework.web.reactive.function.server.ServerResponse;
5250

5351
import static org.springframework.restdocs.payload.PayloadDocumentation.beneathPath;
5452
import static org.springframework.restdocs.payload.PayloadDocumentation.fieldWithPath;
5553
import static org.springframework.restdocs.payload.PayloadDocumentation.responseFields;
5654
import static org.springframework.restdocs.webtestclient.WebTestClientRestDocumentation.document;
5755
import static org.springframework.restdocs.webtestclient.WebTestClientRestDocumentation.documentationConfiguration;
56+
import static org.springframework.web.reactive.function.server.RequestPredicates.GET;
57+
import static org.springframework.web.reactive.function.server.RouterFunctions.route;
5858

5959
/**
6060
* Tests for generating documentation describing {@link MappingsEndpoint}.
@@ -191,8 +191,7 @@ public MappingsEndpoint mappingsEndpoint(
191191

192192
@Bean
193193
public RouterFunction<ServerResponse> exampleRouter() {
194-
return RouterFunctions.route(RequestPredicates.GET("/foo"),
195-
(request) -> ServerResponse.ok().build());
194+
return route(GET("/foo"), (request) -> ServerResponse.ok().build());
196195
}
197196

198197
@Bean

spring-boot-project/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/trace/http/reactive/HttpTraceWebFilterIntegrationTests.java

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -36,13 +36,13 @@
3636
import org.springframework.test.web.reactive.server.WebTestClient;
3737
import org.springframework.web.reactive.config.EnableWebFlux;
3838
import org.springframework.web.reactive.function.server.HandlerFunction;
39-
import org.springframework.web.reactive.function.server.RequestPredicates;
4039
import org.springframework.web.reactive.function.server.RouterFunction;
41-
import org.springframework.web.reactive.function.server.RouterFunctions;
4240
import org.springframework.web.reactive.function.server.ServerResponse;
4341
import org.springframework.web.server.adapter.WebHttpHandlerBuilder;
4442

4543
import static org.assertj.core.api.Assertions.assertThat;
44+
import static org.springframework.web.reactive.function.server.RequestPredicates.GET;
45+
import static org.springframework.web.reactive.function.server.RouterFunctions.route;
4646

4747
/**
4848
* Integration tests for {@link HttpTraceWebFilter}.
@@ -115,10 +115,9 @@ public HttpHandler httpHandler(ApplicationContext applicationContext) {
115115

116116
@Bean
117117
public RouterFunction<ServerResponse> router() {
118-
return RouterFunctions
119-
.route(RequestPredicates.GET("/mono-error"),
120-
(request) -> Mono.error(new RuntimeException()))
121-
.andRoute(RequestPredicates.GET("/thrown"),
118+
return route(GET("/mono-error"),
119+
(request) -> Mono.error(new RuntimeException())).andRoute(
120+
GET("/thrown"),
122121
(HandlerFunction<ServerResponse>) (request) -> {
123122
throw new RuntimeException();
124123
});

spring-boot-project/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/web/mappings/MappingsEndpointTests.java

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -51,16 +51,17 @@
5151
import org.springframework.web.context.WebApplicationContext;
5252
import org.springframework.web.context.support.AnnotationConfigWebApplicationContext;
5353
import org.springframework.web.reactive.config.EnableWebFlux;
54-
import org.springframework.web.reactive.function.server.RequestPredicates;
5554
import org.springframework.web.reactive.function.server.RouterFunction;
56-
import org.springframework.web.reactive.function.server.RouterFunctions;
5755
import org.springframework.web.reactive.function.server.ServerResponse;
5856
import org.springframework.web.servlet.DispatcherServlet;
5957
import org.springframework.web.servlet.config.annotation.EnableWebMvc;
6058

6159
import static org.assertj.core.api.Assertions.assertThat;
6260
import static org.mockito.BDDMockito.given;
6361
import static org.mockito.Mockito.mock;
62+
import static org.springframework.web.reactive.function.server.RequestPredicates.GET;
63+
import static org.springframework.web.reactive.function.server.RequestPredicates.POST;
64+
import static org.springframework.web.reactive.function.server.RouterFunctions.route;
6465

6566
/**
6667
* Tests for {@link MappingsEndpoint}.
@@ -166,11 +167,8 @@ public DispatcherHandlersMappingDescriptionProvider dispatcherHandlersMappingDes
166167

167168
@Bean
168169
public RouterFunction<ServerResponse> routerFunction() {
169-
return RouterFunctions
170-
.route(RequestPredicates.GET("/one"),
171-
(request) -> ServerResponse.ok().build())
172-
.andRoute(RequestPredicates.POST("/two"),
173-
(request) -> ServerResponse.ok().build());
170+
return route(GET("/one"), (request) -> ServerResponse.ok().build())
171+
.andRoute(POST("/two"), (request) -> ServerResponse.ok().build());
174172
}
175173

176174
@RequestMapping("/three")

spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/web/reactive/error/DefaultErrorWebExceptionHandler.java

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,13 +35,14 @@
3535
import org.springframework.http.MediaType;
3636
import org.springframework.web.reactive.function.BodyInserters;
3737
import org.springframework.web.reactive.function.server.RequestPredicate;
38-
import org.springframework.web.reactive.function.server.RequestPredicates;
3938
import org.springframework.web.reactive.function.server.RouterFunction;
40-
import org.springframework.web.reactive.function.server.RouterFunctions;
4139
import org.springframework.web.reactive.function.server.ServerRequest;
4240
import org.springframework.web.reactive.function.server.ServerResponse;
4341
import org.springframework.web.server.ResponseStatusException;
4442

43+
import static org.springframework.web.reactive.function.server.RequestPredicates.all;
44+
import static org.springframework.web.reactive.function.server.RouterFunctions.route;
45+
4546
/**
4647
* Basic global {@link org.springframework.web.server.WebExceptionHandler}, rendering
4748
* {@link ErrorAttributes}.
@@ -106,8 +107,8 @@ public DefaultErrorWebExceptionHandler(ErrorAttributes errorAttributes,
106107
@Override
107108
protected RouterFunction<ServerResponse> getRoutingFunction(
108109
ErrorAttributes errorAttributes) {
109-
return RouterFunctions.route(acceptsTextHtml(), this::renderErrorView)
110-
.andRoute(RequestPredicates.all(), this::renderErrorResponse);
110+
return route(acceptsTextHtml(), this::renderErrorView).andRoute(all(),
111+
this::renderErrorResponse);
111112
}
112113

113114
/**

spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/web/reactive/HttpHandlerAutoConfigurationTests.java

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,12 @@
2323
import org.springframework.context.annotation.Bean;
2424
import org.springframework.context.annotation.Configuration;
2525
import org.springframework.http.server.reactive.HttpHandler;
26-
import org.springframework.web.reactive.function.server.RequestPredicates;
2726
import org.springframework.web.reactive.function.server.RouterFunction;
28-
import org.springframework.web.reactive.function.server.RouterFunctions;
2927
import org.springframework.web.reactive.function.server.ServerResponse;
3028

3129
import static org.assertj.core.api.Assertions.assertThat;
30+
import static org.springframework.web.reactive.function.server.RequestPredicates.GET;
31+
import static org.springframework.web.reactive.function.server.RouterFunctions.route;
3232

3333
/**
3434
* Tests for {@link HttpHandlerAutoConfiguration}.
@@ -69,8 +69,7 @@ public HttpHandler customHttpHandler() {
6969

7070
@Bean
7171
public RouterFunction<ServerResponse> routerFunction() {
72-
return RouterFunctions.route(RequestPredicates.GET("/test"),
73-
(serverRequest) -> null);
72+
return route(GET("/test"), (serverRequest) -> null);
7473
}
7574

7675
}

spring-boot-samples/spring-boot-sample-secure-webflux/src/main/java/sample/secure/webflux/SampleSecureWebFluxApplication.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,12 @@
1919
import org.springframework.boot.SpringApplication;
2020
import org.springframework.boot.autoconfigure.SpringBootApplication;
2121
import org.springframework.context.annotation.Bean;
22-
import org.springframework.web.reactive.function.server.RequestPredicates;
2322
import org.springframework.web.reactive.function.server.RouterFunction;
24-
import org.springframework.web.reactive.function.server.RouterFunctions;
2523
import org.springframework.web.reactive.function.server.ServerResponse;
2624

25+
import static org.springframework.web.reactive.function.server.RequestPredicates.POST;
26+
import static org.springframework.web.reactive.function.server.RouterFunctions.route;
27+
2728
@SpringBootApplication
2829
public class SampleSecureWebFluxApplication {
2930

@@ -33,7 +34,7 @@ public static void main(String[] args) {
3334

3435
@Bean
3536
public RouterFunction<ServerResponse> monoRouterFunction(EchoHandler echoHandler) {
36-
return RouterFunctions.route(RequestPredicates.POST("/echo"), echoHandler::echo);
37+
return route(POST("/echo"), echoHandler::echo);
3738
}
3839

3940
}

spring-boot-samples/spring-boot-sample-webflux/src/main/java/sample/webflux/SampleWebFluxApplication.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,12 @@
1919
import org.springframework.boot.SpringApplication;
2020
import org.springframework.boot.autoconfigure.SpringBootApplication;
2121
import org.springframework.context.annotation.Bean;
22-
import org.springframework.web.reactive.function.server.RequestPredicates;
2322
import org.springframework.web.reactive.function.server.RouterFunction;
24-
import org.springframework.web.reactive.function.server.RouterFunctions;
2523
import org.springframework.web.reactive.function.server.ServerResponse;
2624

25+
import static org.springframework.web.reactive.function.server.RequestPredicates.POST;
26+
import static org.springframework.web.reactive.function.server.RouterFunctions.route;
27+
2728
@SpringBootApplication
2829
public class SampleWebFluxApplication {
2930

@@ -33,7 +34,7 @@ public static void main(String[] args) {
3334

3435
@Bean
3536
public RouterFunction<ServerResponse> monoRouterFunction(EchoHandler echoHandler) {
36-
return RouterFunctions.route(RequestPredicates.POST("/echo"), echoHandler::echo);
37+
return route(POST("/echo"), echoHandler::echo);
3738
}
3839

3940
}

0 commit comments

Comments
 (0)