Switch to functional web code to use static imports

Update the samples and tests to use the more idiomatic static import
style.
This commit is contained in:
Phillip Webb
2018-06-04 17:27:34 -07:00
parent 8eba37500c
commit 571c50e43f
7 changed files with 29 additions and 31 deletions

View File

@@ -36,13 +36,13 @@ import org.springframework.http.server.reactive.HttpHandler;
import org.springframework.test.web.reactive.server.WebTestClient;
import org.springframework.web.reactive.config.EnableWebFlux;
import org.springframework.web.reactive.function.server.HandlerFunction;
import org.springframework.web.reactive.function.server.RequestPredicates;
import org.springframework.web.reactive.function.server.RouterFunction;
import org.springframework.web.reactive.function.server.RouterFunctions;
import org.springframework.web.reactive.function.server.ServerResponse;
import org.springframework.web.server.adapter.WebHttpHandlerBuilder;
import static org.assertj.core.api.Assertions.assertThat;
import static org.springframework.web.reactive.function.server.RequestPredicates.GET;
import static org.springframework.web.reactive.function.server.RouterFunctions.route;
/**
* Integration tests for {@link HttpTraceWebFilter}.
@@ -115,10 +115,9 @@ public class HttpTraceWebFilterIntegrationTests {
@Bean
public RouterFunction<ServerResponse> router() {
return RouterFunctions
.route(RequestPredicates.GET("/mono-error"),
(request) -> Mono.error(new RuntimeException()))
.andRoute(RequestPredicates.GET("/thrown"),
return route(GET("/mono-error"),
(request) -> Mono.error(new RuntimeException())).andRoute(
GET("/thrown"),
(HandlerFunction<ServerResponse>) (request) -> {
throw new RuntimeException();
});

View File

@@ -51,9 +51,7 @@ import org.springframework.web.context.ConfigurableWebApplicationContext;
import org.springframework.web.context.WebApplicationContext;
import org.springframework.web.context.support.AnnotationConfigWebApplicationContext;
import org.springframework.web.reactive.config.EnableWebFlux;
import org.springframework.web.reactive.function.server.RequestPredicates;
import org.springframework.web.reactive.function.server.RouterFunction;
import org.springframework.web.reactive.function.server.RouterFunctions;
import org.springframework.web.reactive.function.server.ServerResponse;
import org.springframework.web.servlet.DispatcherServlet;
import org.springframework.web.servlet.config.annotation.EnableWebMvc;
@@ -61,6 +59,9 @@ import org.springframework.web.servlet.config.annotation.EnableWebMvc;
import static org.assertj.core.api.Assertions.assertThat;
import static org.mockito.BDDMockito.given;
import static org.mockito.Mockito.mock;
import static org.springframework.web.reactive.function.server.RequestPredicates.GET;
import static org.springframework.web.reactive.function.server.RequestPredicates.POST;
import static org.springframework.web.reactive.function.server.RouterFunctions.route;
/**
* Tests for {@link MappingsEndpoint}.
@@ -166,11 +167,8 @@ public class MappingsEndpointTests {
@Bean
public RouterFunction<ServerResponse> routerFunction() {
return RouterFunctions
.route(RequestPredicates.GET("/one"),
(request) -> ServerResponse.ok().build())
.andRoute(RequestPredicates.POST("/two"),
(request) -> ServerResponse.ok().build());
return route(GET("/one"), (request) -> ServerResponse.ok().build())
.andRoute(POST("/two"), (request) -> ServerResponse.ok().build());
}
@RequestMapping("/three")