@Test public void dispatch_shouldCallOnFailureWhenCallbackFails() { JsonApiResponse jsonApiResponse = new JsonApiResponse(200); TestApiResponseCallbacks callbacks = new TestApiResponseCallbacks() { @Override public void onSuccess(JsonApiResponse successResponse) throws IOException { try { callbackFailed.onSuccess(); } catch (Exception e) { onCallbackFailure(successResponse); } } }; apiGateway.dispatch(jsonApiResponse, callbacks); assertThat(callbacks.onCallBackFailureWasCalled, equalTo(true)); assertThat(callbacks.onCompleteWasCalled, equalTo(true)); }
protected void dispatch(T apiResponse, ApiResponseCallbacks<T> responseCallbacks) { if (apiResponse.isSuccess()) { try { responseCallbacks.onSuccess(apiResponse); } catch (Exception e) { e.printStackTrace(); Log.e(e.getClass().getName(), "ApiGateway:dispatch:Error:\n" + e.getMessage()); responseCallbacks.onProcessFailure(apiResponse); } } else { Log.e("request failed", "ApiGateway:response:\n" + apiResponse.getHttpResponseCode()); responseCallbacks.onRequestFailure(apiResponse); } responseCallbacks.onComplete(); }
ApiGateway { protected void dispatch(T apiResponse, ApiResponseCallbacks<T> responseCallbacks) { if (apiResponse.isSuccess()) { try { responseCallbacks.onSuccess(apiResponse); } catch (Exception e) { e.printStackTrace(); Log.e(e.getClass().getName(), "ApiGateway:dispatch:Error:\n" + e.getMessage()); responseCallbacks.onProcessFailure(apiResponse); } } else { Log.e("request failed", "ApiGateway:response:\n" + apiResponse.getHttpResponseCode()); responseCallbacks.onRequestFailure(apiResponse); } responseCallbacks.onComplete(); } }
ApiGateway { protected void dispatch(T apiResponse, ApiResponseCallbacks<T> responseCallbacks) { if (apiResponse.isSuccess()) { try { responseCallbacks.onSuccess(apiResponse); } catch (Exception e) { e.printStackTrace(); Log.e(e.getClass().getName(), "ApiGateway:dispatch:Error:\n" + e.getMessage()); responseCallbacks.onProcessFailure(apiResponse); } } else { Log.e("request failed", "ApiGateway:response:\n" + apiResponse.getHttpResponseCode()); responseCallbacks.onRequestFailure(apiResponse); } responseCallbacks.onComplete(); }  }
ApiGateway { protected void dispatch(T apiResponse, ApiResponseCallbacks<T> responseCallbacks) { if (apiResponse.isSuccess()) { try { responseCallbacks.onSuccess(apiResponse); } catch (Exception e) { e.printStackTrace(); Log.e(e.getClass().getName(), "ApiGateway:dispatch:Error:\n" + e.getMessage()); responseCallbacks.onProcessFailure(apiResponse); } } else { Log.e("request failed", "ApiGateway:response:\n" + apiResponse.getHttpResponseCode()); responseCallbacks.onRequestFailure(apiResponse); } responseCallbacks.onComplete(); }  T makeSyncRequest(ApiRequest<T> apiRequest); @TargetApi(Build.VERSION_CODES.CUPCAKE) void makeRequest(ApiRequest<T> apiRequest, final ApiResponseCallbacks<T> responseCallbacks); }
ApiGateway { protected void dispatch(T apiResponse, ApiResponseCallbacks<T> responseCallbacks) { if (apiResponse.isSuccess()) { try { responseCallbacks.onSuccess(apiResponse); } catch (Exception e) { e.printStackTrace(); Log.e(e.getClass().getName(), "ApiGateway:dispatch:Error:\n" + e.getMessage()); responseCallbacks.onProcessFailure(apiResponse); } } else { Log.e("request failed", "ApiGateway:response:\n" + apiResponse.getHttpResponseCode()); responseCallbacks.onRequestFailure(apiResponse); } responseCallbacks.onComplete(); }  T makeSyncRequest(ApiRequest<T> apiRequest); @TargetApi(Build.VERSION_CODES.CUPCAKE) void makeRequest(ApiRequest<T> apiRequest, final ApiResponseCallbacks<T> responseCallbacks);  }