Fix RouterFunction.andRoute()
Fixed RouterFunction.andRoute signature. Issue: SPR-14904
This commit is contained in:
parent
6261106a93
commit
6de062d198
|
@ -78,12 +78,13 @@ public interface RouterFunction<T> {
|
|||
* {@link RouterFunctions#route(RequestPredicate, HandlerFunction)}.
|
||||
* @param predicate the predicate to test
|
||||
* @param handlerFunction the handler function to route to
|
||||
* @param <S> 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 <S> RouterFunction<?> andRoute(RequestPredicate predicate,
|
||||
HandlerFunction<S> handlerFunction) {
|
||||
return and(RouterFunctions.route(predicate, handlerFunction));
|
||||
}
|
||||
|
||||
|
|
|
@ -61,6 +61,23 @@ public class RouterFunctionTests {
|
|||
assertEquals(handlerFunction, resultHandlerFunction.get());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void andRoute() throws Exception {
|
||||
RouterFunction<Integer> routerFunction1 = request -> Optional.empty();
|
||||
RequestPredicate requestPredicate = request -> true;
|
||||
|
||||
RouterFunction<?> result = routerFunction1.andRoute(requestPredicate, this::handlerMethod);
|
||||
assertNotNull(result);
|
||||
|
||||
MockServerRequest request = MockServerRequest.builder().build();
|
||||
Optional<? extends HandlerFunction<?>> resultHandlerFunction = result.route(request);
|
||||
assertTrue(resultHandlerFunction.isPresent());
|
||||
}
|
||||
|
||||
private ServerResponse<String> handlerMethod(ServerRequest request) {
|
||||
return ServerResponse.ok().body(fromObject("42"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void filter() throws Exception {
|
||||
HandlerFunction<String> handlerFunction = request -> ServerResponse.ok().body(fromObject("42"));
|
||||
|
|
Loading…
Reference in New Issue