From 6de062d198a0a00861a7c89c304f53dd32b76033 Mon Sep 17 00:00:00 2001 From: Arjen Poutsma Date: Mon, 14 Nov 2016 17:16:59 +0100 Subject: [PATCH] Fix RouterFunction.andRoute() Fixed RouterFunction.andRoute signature. Issue: SPR-14904 --- .../web/reactive/function/RouterFunction.java | 5 +++-- .../reactive/function/RouterFunctionTests.java | 17 +++++++++++++++++ 2 files changed, 20 insertions(+), 2 deletions(-) diff --git a/spring-web-reactive/src/main/java/org/springframework/web/reactive/function/RouterFunction.java b/spring-web-reactive/src/main/java/org/springframework/web/reactive/function/RouterFunction.java index b0aa3b28b1..fa80fd0ce9 100644 --- a/spring-web-reactive/src/main/java/org/springframework/web/reactive/function/RouterFunction.java +++ b/spring-web-reactive/src/main/java/org/springframework/web/reactive/function/RouterFunction.java @@ -78,12 +78,13 @@ public interface RouterFunction { * {@link RouterFunctions#route(RequestPredicate, HandlerFunction)}. * @param predicate the predicate to test * @param handlerFunction the handler function to route to + * @param the handler function type * @return a composed function that first routes with this function and then the function * created from {@code predicate} and {@code handlerFunction} if this * function has no result */ - default RouterFunction andRoute(RequestPredicate predicate, - HandlerFunction handlerFunction) { + default RouterFunction andRoute(RequestPredicate predicate, + HandlerFunction handlerFunction) { return and(RouterFunctions.route(predicate, handlerFunction)); } diff --git a/spring-web-reactive/src/test/java/org/springframework/web/reactive/function/RouterFunctionTests.java b/spring-web-reactive/src/test/java/org/springframework/web/reactive/function/RouterFunctionTests.java index 770c4e4efc..8d62e2b5ac 100644 --- a/spring-web-reactive/src/test/java/org/springframework/web/reactive/function/RouterFunctionTests.java +++ b/spring-web-reactive/src/test/java/org/springframework/web/reactive/function/RouterFunctionTests.java @@ -61,6 +61,23 @@ public class RouterFunctionTests { assertEquals(handlerFunction, resultHandlerFunction.get()); } + @Test + public void andRoute() throws Exception { + RouterFunction routerFunction1 = request -> Optional.empty(); + RequestPredicate requestPredicate = request -> true; + + RouterFunction result = routerFunction1.andRoute(requestPredicate, this::handlerMethod); + assertNotNull(result); + + MockServerRequest request = MockServerRequest.builder().build(); + Optional> resultHandlerFunction = result.route(request); + assertTrue(resultHandlerFunction.isPresent()); + } + + private ServerResponse handlerMethod(ServerRequest request) { + return ServerResponse.ok().body(fromObject("42")); + } + @Test public void filter() throws Exception { HandlerFunction handlerFunction = request -> ServerResponse.ok().body(fromObject("42"));