JsonSecurityRequestFilterBase extends AbstractComponent implements SecurityRequestFilter { @Override public final void filter(DiscFilterRequest request, ResponseHandler handler) { filter(request) .ifPresent(errorResponse -> writeResponse(request, errorResponse, handler)); }  @Override final void filter(DiscFilterRequest request, ResponseHandler handler);  }
@Test public void filter_renders_errors_as_json() throws IOException { int statusCode = 403; String message = "Forbidden"; DiscFilterRequest request = mock(DiscFilterRequest.class); SimpleSecurityRequestFilter filter = new SimpleSecurityRequestFilter(new JsonSecurityRequestFilterBase.ErrorResponse(statusCode, message)); RequestHandlerTestDriver.MockResponseHandler responseHandler = new RequestHandlerTestDriver.MockResponseHandler(); filter.filter(request, responseHandler); Response response = responseHandler.getResponse(); assertThat(response, notNullValue()); assertThat(response.getStatus(), equalTo(statusCode)); JsonNode jsonNode = mapper.readTree(responseHandler.readAll()); assertThat(jsonNode.get("message").asText(), equalTo(message)); assertThat(jsonNode.get("code").asInt(), equalTo(statusCode)); }