@Test public void shouldHandleCallbacksInternally() throws RestAuthCallbackHandlerResponseException { HttpHeaders headers = mock(HttpHeaders.class); HttpServletRequest request = mock(HttpServletRequest.class); HttpServletResponse response = mock(HttpServletResponse.class); Callback callback1 = mock(Callback.class); Callback callback2 = mock(Callback.class); Callback[] callbacks = new Callback[]{callback1, callback2}; RestAuthCallbackHandler restAuthCallbackHandler1 = mock(RestAuthCallbackHandler.class); RestAuthCallbackHandler restAuthCallbackHandler2 = mock(RestAuthCallbackHandler.class); given(restAuthCallbackHandlerFactory.getRestAuthCallbackHandler( Matchers.<Class<? extends Callback>>anyObject())).willReturn( restAuthCallbackHandler1).willReturn(restAuthCallbackHandler2); given(restAuthCallbackHandler1.updateCallbackFromRequest(headers, request, response, callback1)) .willReturn(true); given(restAuthCallbackHandler2.updateCallbackFromRequest(headers, request, response, callback2)) .willReturn(true); JsonValue jsonCallbacks = restAuthCallbackHandlerManager.handleCallbacks(headers, request, response, callbacks); verify(restAuthCallbackHandler1).updateCallbackFromRequest(headers, request, response, callback1); verify(restAuthCallbackHandler2).updateCallbackFromRequest(headers, request, response, callback2); verify(restAuthCallbackHandler1, never()).convertToJson(callback1, 1); verify(restAuthCallbackHandler2, never()).convertToJson(callback2, 2); assertEquals(jsonCallbacks.size(), 0); }
public JsonValue handleCallbacks(HttpHeaders headers, HttpServletRequest request, HttpServletResponse response, Callback[] callbacks) throws RestAuthCallbackHandlerResponseException { List<JsonValue> jsonCallbacks = new ArrayList<JsonValue>(); int callbackIndex = 0; boolean handledInternally = handleCallbacksInternally(headers, request, response, callbacks); if (!handledInternally) { logger.message("Cannot handle callbacks internally. Converting to JSON instead."); for (Callback callback : callbacks) { callbackIndex++; RestAuthCallbackHandler restAuthCallbackHandler = restAuthCallbackHandlerFactory.getRestAuthCallbackHandler(callback.getClass()); JsonValue jsonCallback = restAuthCallbackHandler.convertToJson(callback, callbackIndex); jsonCallbacks.add(jsonCallback); } } return new JsonValue(jsonCallbacks); }
RestAuthCallbackHandlerManager { public JsonValue handleCallbacks(HttpHeaders headers, HttpServletRequest request, HttpServletResponse response, Callback[] callbacks) throws RestAuthCallbackHandlerResponseException { List<JsonValue> jsonCallbacks = new ArrayList<JsonValue>(); int callbackIndex = 0; boolean handledInternally = handleCallbacksInternally(headers, request, response, callbacks); if (!handledInternally) { logger.message("Cannot handle callbacks internally. Converting to JSON instead."); for (Callback callback : callbacks) { callbackIndex++; RestAuthCallbackHandler restAuthCallbackHandler = restAuthCallbackHandlerFactory.getRestAuthCallbackHandler(callback.getClass()); JsonValue jsonCallback = restAuthCallbackHandler.convertToJson(callback, callbackIndex); jsonCallbacks.add(jsonCallback); } } return new JsonValue(jsonCallbacks); } }
RestAuthCallbackHandlerManager { public JsonValue handleCallbacks(HttpHeaders headers, HttpServletRequest request, HttpServletResponse response, Callback[] callbacks) throws RestAuthCallbackHandlerResponseException { List<JsonValue> jsonCallbacks = new ArrayList<JsonValue>(); int callbackIndex = 0; boolean handledInternally = handleCallbacksInternally(headers, request, response, callbacks); if (!handledInternally) { logger.message("Cannot handle callbacks internally. Converting to JSON instead."); for (Callback callback : callbacks) { callbackIndex++; RestAuthCallbackHandler restAuthCallbackHandler = restAuthCallbackHandlerFactory.getRestAuthCallbackHandler(callback.getClass()); JsonValue jsonCallback = restAuthCallbackHandler.convertToJson(callback, callbackIndex); jsonCallbacks.add(jsonCallback); } } return new JsonValue(jsonCallbacks); } @Inject  RestAuthCallbackHandlerManager(RestAuthCallbackHandlerFactory restAuthCallbackHandlerFactory); }
RestAuthCallbackHandlerManager { public JsonValue handleCallbacks(HttpHeaders headers, HttpServletRequest request, HttpServletResponse response, Callback[] callbacks) throws RestAuthCallbackHandlerResponseException { List<JsonValue> jsonCallbacks = new ArrayList<JsonValue>(); int callbackIndex = 0; boolean handledInternally = handleCallbacksInternally(headers, request, response, callbacks); if (!handledInternally) { logger.message("Cannot handle callbacks internally. Converting to JSON instead."); for (Callback callback : callbacks) { callbackIndex++; RestAuthCallbackHandler restAuthCallbackHandler = restAuthCallbackHandlerFactory.getRestAuthCallbackHandler(callback.getClass()); JsonValue jsonCallback = restAuthCallbackHandler.convertToJson(callback, callbackIndex); jsonCallbacks.add(jsonCallback); } } return new JsonValue(jsonCallbacks); } @Inject  RestAuthCallbackHandlerManager(RestAuthCallbackHandlerFactory restAuthCallbackHandlerFactory); JsonValue handleCallbacks(HttpHeaders headers, HttpServletRequest request,
            HttpServletResponse response, Callback[] callbacks); Callback[] handleJsonCallbacks(Callback[] originalCallbacks, JsonValue jsonCallbacks); Callback[] handleResponseCallbacks(HttpHeaders headers, HttpServletRequest request,
            HttpServletResponse response, Callback[] originalCallbacks, JsonValue jsonRequestObject); }
RestAuthCallbackHandlerManager { public JsonValue handleCallbacks(HttpHeaders headers, HttpServletRequest request, HttpServletResponse response, Callback[] callbacks) throws RestAuthCallbackHandlerResponseException { List<JsonValue> jsonCallbacks = new ArrayList<JsonValue>(); int callbackIndex = 0; boolean handledInternally = handleCallbacksInternally(headers, request, response, callbacks); if (!handledInternally) { logger.message("Cannot handle callbacks internally. Converting to JSON instead."); for (Callback callback : callbacks) { callbackIndex++; RestAuthCallbackHandler restAuthCallbackHandler = restAuthCallbackHandlerFactory.getRestAuthCallbackHandler(callback.getClass()); JsonValue jsonCallback = restAuthCallbackHandler.convertToJson(callback, callbackIndex); jsonCallbacks.add(jsonCallback); } } return new JsonValue(jsonCallbacks); } @Inject  RestAuthCallbackHandlerManager(RestAuthCallbackHandlerFactory restAuthCallbackHandlerFactory); JsonValue handleCallbacks(HttpHeaders headers, HttpServletRequest request,
            HttpServletResponse response, Callback[] callbacks); Callback[] handleJsonCallbacks(Callback[] originalCallbacks, JsonValue jsonCallbacks); Callback[] handleResponseCallbacks(HttpHeaders headers, HttpServletRequest request,
            HttpServletResponse response, Callback[] originalCallbacks, JsonValue jsonRequestObject);  }