### Question:
RouterFunctions { public static <T extends ServerResponse> RouterFunction<T> route( RequestPredicate predicate, HandlerFunction<T> handlerFunction) { return new DefaultRouterFunction<>(predicate, handlerFunction); }  static RouterFunction<T> route(
			RequestPredicate predicate, HandlerFunction<T> handlerFunction); static RouterFunction<T> nest(
			RequestPredicate predicate, RouterFunction<T> routerFunction); static RouterFunction<ServerResponse> resources(String pattern, Resource location); static Function<ServerRequest, Mono<Resource>> resourceLookupFunction(String pattern, Resource location); static RouterFunction<ServerResponse> resources(Function<ServerRequest, Mono<Resource>> lookupFunction); static HttpHandler toHttpHandler(RouterFunction<?> routerFunction); static HttpHandler toHttpHandler(RouterFunction<?> routerFunction, HandlerStrategies strategies); static WebHandler toWebHandler(RouterFunction<?> routerFunction); static WebHandler toWebHandler(RouterFunction<?> routerFunction, HandlerStrategies strategies); static final String REQUEST_ATTRIBUTE; static final String URI_TEMPLATE_VARIABLES_ATTRIBUTE; }### Answer:
@Test public void and() throws Exception { HandlerFunction<ServerResponse> handlerFunction = request -> ServerResponse.ok().build(); RouterFunction<ServerResponse> routerFunction1 = request -> Mono.empty(); RouterFunction<ServerResponse> routerFunction2 = request -> Mono.just(handlerFunction); RouterFunction<ServerResponse> result = routerFunction1.and(routerFunction2); assertNotNull(result); MockServerRequest request = MockServerRequest.builder().build(); Mono<HandlerFunction<ServerResponse>> resultHandlerFunction = result.route(request); StepVerifier.create(resultHandlerFunction) .expectNext(handlerFunction) .expectComplete() .verify(); }
@Test public void andOther() throws Exception { HandlerFunction<ServerResponse> handlerFunction = request -> ServerResponse.ok().body(fromObject("42")); RouterFunction<?> routerFunction1 = request -> Mono.empty(); RouterFunction<ServerResponse> routerFunction2 = request -> Mono.just(handlerFunction); RouterFunction<?> result = routerFunction1.andOther(routerFunction2); assertNotNull(result); MockServerRequest request = MockServerRequest.builder().build(); Mono<? extends HandlerFunction<?>> resultHandlerFunction = result.route(request); StepVerifier.create(resultHandlerFunction) .expectNextMatches(o -> o.equals(handlerFunction)) .expectComplete() .verify(); }
@Test public void andRoute() throws Exception { RouterFunction<ServerResponse> routerFunction1 = request -> Mono.empty(); RequestPredicate requestPredicate = request -> true; RouterFunction<ServerResponse> result = routerFunction1.andRoute(requestPredicate, this::handlerMethod); assertNotNull(result); MockServerRequest request = MockServerRequest.builder().build(); Mono<? extends HandlerFunction<?>> resultHandlerFunction = result.route(request); StepVerifier.create(resultHandlerFunction) .expectNextCount(1) .expectComplete() .verify(); }
@Test public void filter() throws Exception { Mono<String> stringMono = Mono.just("42"); HandlerFunction<EntityResponse<Mono<String>>> handlerFunction = request -> EntityResponse.fromPublisher(stringMono, String.class).build(); RouterFunction<EntityResponse<Mono<String>>> routerFunction = request -> Mono.just(handlerFunction); HandlerFilterFunction<EntityResponse<Mono<String>>, EntityResponse<Mono<Integer>>> filterFunction = (request, next) -> next.handle(request).flatMap( response -> { Mono<Integer> intMono = response.entity() .map(Integer::parseInt); return EntityResponse.fromPublisher(intMono, Integer.class).build(); }); RouterFunction<EntityResponse<Mono<Integer>>> result = routerFunction.filter(filterFunction); assertNotNull(result); MockServerRequest request = MockServerRequest.builder().build(); Mono<EntityResponse<Mono<Integer>>> responseMono = result.route(request).flatMap(hf -> hf.handle(request)); StepVerifier.create(responseMono) .consumeNextWith( serverResponse -> { StepVerifier.create(serverResponse.entity()) .expectNext(42) .expectComplete() .verify(); }) .expectComplete() .verify(); }