### Question:
AuthenticationServiceV2 extends AuthenticationServiceV1 { @Override protected Response handleErrorResponse(Request request, Status status, Exception exception) { Reject.ifNull(status); Response response = new Response(status); if (exception instanceof RestAuthResponseException) { final RestAuthResponseException authResponseException = (RestAuthResponseException)exception; for (Map.Entry<String, String> entry : authResponseException.getResponseHeaders().entrySet()) { response.getHeaders().add(entry.getKey(), entry.getValue()); } response.setEntity(authResponseException.getJsonResponse().asMap()); return response; } else if (exception instanceof RestAuthException) { final RestAuthException rae = (RestAuthException)exception; ResourceException cause = ResourceException.getException(rae.getStatusCode(), getLocalizedMessage(request, rae)); if (rae.getFailureUrl() != null) { cause.setDetail(json(object(field("failureUrl", rae.getFailureUrl())))); } return createExceptionResponse(response, cause); } else if (exception == null) { return createExceptionResponse(response, ResourceException.getException(status.getCode())); } else { return createExceptionResponse(response, ResourceException.getException(status.getCode(), exception.getMessage(), exception)); } } @Inject  AuthenticationServiceV2(RestAuthenticationHandler restAuthenticationHandler);   }### Answer:
@Test public void shouldReturnUnauthorizedCodeWithJsonFailureMessage() throws IOException { Request httpRequest = new Request(); JsonValue jsonValue = json(object( field("failure", true), field("reason", "http-auth-failed"), field("authId", "12345"))); RestAuthResponseException exception = new RestAuthResponseException(RestAuthException.UNAUTHORIZED, Collections.<String, String>emptyMap(), jsonValue); Response response = authServiceV2.handleErrorResponse(httpRequest, Status.valueOf(exception.getStatusCode()), exception); assertThat(response.getStatus()).isEqualToComparingFieldByField(Status.UNAUTHORIZED); JsonValue responseBody = json(response.getEntity().getJson()); assertThat(responseBody).booleanAt("failure").isTrue(); assertThat(responseBody).stringAt("reason").isEqualTo("http-auth-failed"); assertThat(responseBody).stringAt("authId").isEqualTo("12345"); }
@Test public void shouldReturnResponseContainingUnauthorizedCodeWithJsonErrorMessage() throws IOException { Request httpRequest = new Request(); RestAuthException testException = new RestAuthException(401, "Invalid Password!!"); testException.setFailureUrl("http: Response response = authServiceV2.handleErrorResponse(httpRequest, Status.valueOf(401), testException); assertThat(response.getStatus()).isEqualToComparingFieldByField(Status.UNAUTHORIZED); JsonValue responseBody = json(response.getEntity().getJson()); assertThat(responseBody).integerAt("code").isEqualTo(401); assertThat(responseBody).stringAt("reason").isEqualTo("Unauthorized"); assertThat(responseBody).stringAt("message").isEqualTo("Invalid Password!!"); assertThat(responseBody).stringAt("detail/failureUrl").isEqualTo("http: }