Invoker { public WebResponse invoke(WebRequest request, MatchResult match, Handler handler) { try { Map<String, Object> parameters = createParameters(request, match, handler); Object value = handler.invoke(parameters); ResponseBuilder builder = value == null ? Response.noContent() : Response.ok(value); return toWebResponse(builder.build()); } catch (Exception e) { logInvocationException(e); return toWebResponse(e); } } @Inject  Invoker(GsonWebRenderer webRenderer, Logger logger); WebResponse invoke(WebRequest request, MatchResult match, Handler handler);  }
@Test public void invokeWithException() throws Exception { Handler handler = createHandler("getWithThrow"); WebResponse response = invoker.invoke(mock(WebRequest.class), new MatchResult(true, ImmutableMap.of()), handler); assertEquals(500, response.getResponseCode()); assertEquals("{\"errorCode\":\"NullPointerException\",\"message\":\"test\"}", response.getEntity()); verify(logger).log(eq(Level.SEVERE), eq("test"), any(NullPointerException.class)); verifyNoMoreInteractions(logger); }