### Question:
RestAuthHttpCallbackHandler extends AbstractRestAuthCallbackHandler<HttpCallback> { public boolean updateCallbackFromRequest(HttpServletRequest request, HttpServletResponse response, HttpCallback callback) throws RestAuthResponseException { String httpAuthorization = request.getHeader(callback.getAuthorizationHeader()); if (httpAuthorization == null || "".equals(httpAuthorization)) { DEBUG.message("Authorization Header not set in request."); JsonValue jsonValue = JsonValueBuilder.jsonValue() .put("failure", true) .put("reason", HTTP_AUTH_FAILED) .build(); Map<String, String> responseHeaders = new HashMap<String, String>(); responseHeaders.put(callback.getNegotiationHeaderName(), callback.getNegotiationHeaderValue()); throw new RestAuthResponseException(RestAuthException.UNAUTHORIZED, responseHeaders, jsonValue); } callback.setAuthorization(httpAuthorization); return true; }  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 shouldUpdateCallbackFromRequest() throws RestAuthResponseException, RestAuthException { HttpServletRequest request = mock(HttpServletRequest.class); HttpServletResponse response = mock(HttpServletResponse.class); HttpCallback httpCallback = mock(HttpCallback.class); given(httpCallback.getAuthorizationHeader()).willReturn("AUTHORIZATION"); given(request.getHeader("AUTHORIZATION")).willReturn("HTTP_AUTHZ"); boolean updated = restAuthHttpCallbackHandler.updateCallbackFromRequest(request, response, httpCallback); verify(httpCallback).setAuthorization("HTTP_AUTHZ"); assertTrue(updated); }
@Test public void shouldFailToUpdateCallbackFromRequestWhenHttpAuthorizationIsNull() throws RestAuthResponseException, RestAuthException { HttpServletRequest request = mock(HttpServletRequest.class); HttpServletResponse response = mock(HttpServletResponse.class); HttpCallback httpCallback = mock(HttpCallback.class); given(request.getParameter("httpAuthorization")).willReturn(null); given(httpCallback.getNegotiationHeaderName()).willReturn("WWW-Authenticate"); given(httpCallback.getNegotiationHeaderValue()).willReturn("Negotiate"); boolean exceptionCaught = false; RestAuthResponseException exception = null; try { restAuthHttpCallbackHandler.updateCallbackFromRequest(request, response, httpCallback); } catch (RestAuthResponseException e) { exceptionCaught = true; exception = e; } assertTrue(exceptionCaught); assertEquals(exception.getStatusCode(), 401); assertEquals(exception.getResponseHeaders().size(), 1); assertTrue(exception.getResponseHeaders().containsKey("WWW-Authenticate")); assertTrue(exception.getResponseHeaders().containsValue("Negotiate")); assertEquals(exception.getJsonResponse().get("failure").asBoolean(), (Boolean) true); assertEquals(exception.getJsonResponse().get("reason").asString(), "http-auth-failed"); }
@Test public void shouldFailToUpdateCallbackFromRequestWhenHttpAuthorizationIsEmptyString() throws RestAuthResponseException, RestAuthException { HttpServletRequest request = mock(HttpServletRequest.class); HttpServletResponse response = mock(HttpServletResponse.class); HttpCallback httpCallback = mock(HttpCallback.class); given(request.getParameter("httpAuthorization")).willReturn(""); given(httpCallback.getNegotiationHeaderName()).willReturn("WWW-Authenticate"); given(httpCallback.getNegotiationHeaderValue()).willReturn("Negotiate"); boolean exceptionCaught = false; RestAuthResponseException exception = null; try { restAuthHttpCallbackHandler.updateCallbackFromRequest(request, response, httpCallback); } catch (RestAuthResponseException e) { exceptionCaught = true; exception = e; } assertTrue(exceptionCaught); assertEquals(exception.getStatusCode(), 401); assertEquals(exception.getResponseHeaders().size(), 1); assertTrue(exception.getResponseHeaders().containsKey("WWW-Authenticate")); assertTrue(exception.getResponseHeaders().containsValue("Negotiate")); assertEquals(exception.getJsonResponse().get("failure").asBoolean(), (Boolean) true); assertEquals(exception.getJsonResponse().get("reason").asString(), "http-auth-failed"); }