### Question:
RestAuthHttpCallbackHandler extends AbstractRestAuthCallbackHandler<HttpCallback> { public HttpCallback handle(HttpServletRequest request, HttpServletResponse response, JsonValue postBody, HttpCallback originalCallback) { if (isJsonAttributePresent(postBody, "reason") && postBody.get("reason").asString().equals(HTTP_AUTH_FAILED)) { request.setAttribute(HTTP_AUTH_FAILED, true); } return originalCallback; }  boolean updateCallbackFromRequest(HttpServletRequest request, HttpServletResponse response,
            HttpCallback callback); HttpCallback handle(HttpServletRequest request, HttpServletResponse response,
            JsonValue postBody, HttpCallback originalCallback); String getCallbackClassName(); JsonValue convertToJson(HttpCallback callback, int index); HttpCallback convertFromJson(HttpCallback callback, JsonValue jsonCallback);  }### Answer:
@Test public void shouldHandleCallbackAndSetHttpAuthFailedIfReasonInPostBody() { HttpServletRequest request = mock(HttpServletRequest.class); HttpServletResponse response = mock(HttpServletResponse.class); HttpCallback originalHttpCallback = mock(HttpCallback.class); Map<String, String> postBodyMap = new LinkedHashMap<String, String>(); postBodyMap.put("reason", "http-auth-failed"); JsonValue jsonPostBody = new JsonValue(postBodyMap); HttpCallback httpCallback = restAuthHttpCallbackHandler.handle(request, response, jsonPostBody, originalHttpCallback); Assert.assertEquals(originalHttpCallback, httpCallback); verify(request).setAttribute("http-auth-failed", true); }
@Test public void shouldHandleCallbackWhereIWASuccessful() { HttpServletRequest request = mock(HttpServletRequest.class); HttpServletResponse response = mock(HttpServletResponse.class); JsonValue jsonPostBody = new JsonValue(new HashMap<String, String>()); HttpCallback originalHttpCallback = mock(HttpCallback.class); HttpCallback httpCallback = restAuthHttpCallbackHandler.handle(request, response, jsonPostBody, originalHttpCallback); Assert.assertEquals(originalHttpCallback, httpCallback); verify(request, never()).setAttribute("http-auth-failed", true); }