### Question:
RouterFunctions { public static Builder route() { return new RouterFunctionBuilder(); }  static Builder route(); 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, Optional<Resource>> resourceLookupFunction(String pattern, Resource location); static RouterFunction<ServerResponse> resources(Function<ServerRequest, Optional<Resource>> lookupFunction); static final String REQUEST_ATTRIBUTE; static final String URI_TEMPLATE_VARIABLES_ATTRIBUTE; static final String MATCHING_PATTERN_ATTRIBUTE; }### Answer:
@Test public void and() { HandlerFunction<ServerResponse> handlerFunction = request -> ServerResponse.ok().build(); RouterFunction<ServerResponse> routerFunction1 = request -> Optional.empty(); RouterFunction<ServerResponse> routerFunction2 = request -> Optional.of(handlerFunction); RouterFunction<ServerResponse> result = routerFunction1.and(routerFunction2); assertNotNull(result); MockHttpServletRequest servletRequest = new MockHttpServletRequest(); ServerRequest request = new DefaultServerRequest(servletRequest, emptyList()); Optional<HandlerFunction<ServerResponse>> resultHandlerFunction = result.route(request); assertTrue(resultHandlerFunction.isPresent()); assertEquals(handlerFunction, resultHandlerFunction.get()); }
@Test public void andOther() { HandlerFunction<ServerResponse> handlerFunction = request -> ServerResponse.ok().body("42"); RouterFunction<?> routerFunction1 = request -> Optional.empty(); RouterFunction<ServerResponse> routerFunction2 = request -> Optional.of(handlerFunction); RouterFunction<?> result = routerFunction1.andOther(routerFunction2); assertNotNull(result); MockHttpServletRequest servletRequest = new MockHttpServletRequest(); ServerRequest request = new DefaultServerRequest(servletRequest, emptyList()); Optional<? extends HandlerFunction<?>> resultHandlerFunction = result.route(request); assertTrue(resultHandlerFunction.isPresent()); assertEquals(handlerFunction, resultHandlerFunction.get()); }
@Test public void andRoute() { RouterFunction<ServerResponse> routerFunction1 = request -> Optional.empty(); RequestPredicate requestPredicate = request -> true; RouterFunction<ServerResponse> result = routerFunction1.andRoute(requestPredicate, this::handlerMethod); assertNotNull(result); MockHttpServletRequest servletRequest = new MockHttpServletRequest(); ServerRequest request = new DefaultServerRequest(servletRequest, emptyList()); Optional<? extends HandlerFunction<?>> resultHandlerFunction = result.route(request); assertTrue(resultHandlerFunction.isPresent()); }
@Test public void filter() { String string = "42"; HandlerFunction<EntityResponse<String>> handlerFunction = request -> EntityResponse.fromObject(string).build(); RouterFunction<EntityResponse<String>> routerFunction = request -> Optional.of(handlerFunction); HandlerFilterFunction<EntityResponse<String>, EntityResponse<Integer>> filterFunction = (request, next) -> { String stringResponse = next.handle(request).entity(); Integer intResponse = Integer.parseInt(stringResponse); return EntityResponse.fromObject(intResponse).build(); }; RouterFunction<EntityResponse<Integer>> result = routerFunction.filter(filterFunction); assertNotNull(result); MockHttpServletRequest servletRequest = new MockHttpServletRequest(); ServerRequest request = new DefaultServerRequest(servletRequest, emptyList()); Optional<EntityResponse<Integer>> resultHandlerFunction = result.route(request) .map(hf -> { try { return hf.handle(request); } catch (Exception e) { fail(e.getMessage()); return null; } }); assertTrue(resultHandlerFunction.isPresent()); assertEquals(42, (int)resultHandlerFunction.get().entity()); }