### Question:
FunctionResolver { PartialFunction resolveFunction(String name, List<String> arguments) { int argumentSize = arguments.size(); String argumentsRepresentation = join(", ", arguments); switch (argumentSize) { case 0: Function0 function0 = ensureNotNull( zeroArgumentFunctions.get(name), "No such function=[%s], with n=[%d] arguments=[%s]", name, argumentSize, argumentsRepresentation); return function0::call; case 1: Function1 function1 = ensureNotNull( oneArgumentFunctions.get(name), "No such function=[%s], with n=[%d] arguments=[%s]", name, argumentSize, argumentsRepresentation); return (request, context) -> function1.call(request, context, arguments.get(0)); default: throw new IllegalArgumentException(format("No such function=[%s], with n=[%d] arguments=[%s]", name, argumentSize, argumentsRepresentation)); } } FunctionResolver(Map<String, Function0> zeroArgumentFunctions, Map<String, Function1> oneArgumentFunctions);   }### Answer:
@Test public void resolvesZeroArgumentFunctions() { LiveHttpRequest request = get("/foo").build(); assertThat(functionResolver.resolveFunction("path", emptyList()).call(request, context), is("/foo")); assertThat(functionResolver.resolveFunction("method", emptyList()).call(request, context), is("GET")); }
@Test public void throwsExceptionIfZeroArgumentFunctionDoesNotExist() { LiveHttpRequest request = get("/foo").build(); Exception e = assertThrows(DslFunctionResolutionError.class, () -> functionResolver.resolveFunction("foobar", emptyList()).call(request, context)); assertThat(e.getMessage(), matchesPattern("No such function=\\[foobar\\], with n=\\[0\\] arguments=\\[\\]")); }
@Test public void resolvesOneArgumentFunctions() { LiveHttpRequest request = get("/foo") .header("Host", "www.hotels.com") .cookies(requestCookie("lang", "en_US|en-us_hotels_com")) .build(); assertThat(functionResolver.resolveFunction("header", singletonList("Host")).call(request, context), is("www.hotels.com")); assertThat(functionResolver.resolveFunction("cookie", singletonList("lang")).call(request, context), is("en_US|en-us_hotels_com")); }
@Test public void throwsExceptionIfOneArgumentFunctionDoesNotExist() { LiveHttpRequest request = get("/foo") .header("Host", "www.hotels.com") .cookies(requestCookie("lang", "en_US|en-us_hotels_com")) .build(); Exception e = assertThrows(DslFunctionResolutionError.class, () -> functionResolver.resolveFunction("foobar", singletonList("barfoo")).call(request, context)); assertThat(e.getMessage(), matchesPattern("No such function=\\[foobar\\], with n=\\[1\\] arguments=\\[barfoo\\]")); }