@Test public void testOnResponseServerErrorCalledFor4XX5XX() { OnStatusCodeAwareResponseListener onStatusCodeAwareResponseListener = mock(OnStatusCodeAwareResponseListener.class); ForwardingResponse forwardingResponse = new ForwardingResponse(onStatusCodeAwareResponseListener); RequestStats requestStats = new RequestStats(1); requestStats.statusCode = (400); requestStats.hostName = ("flipkart.com"); NetworkInfo info = mock(NetworkInfo.class); forwardingResponse.onResponseSuccess(info, requestStats); verify(onStatusCodeAwareResponseListener, times(1)).onResponseServerError(info, requestStats); reset(onStatusCodeAwareResponseListener); requestStats = new RequestStats(1); requestStats.statusCode = (499); requestStats.hostName = ("flipkart.com"); forwardingResponse.onResponseSuccess(info, requestStats); verify(onStatusCodeAwareResponseListener, times(1)).onResponseServerError(info, requestStats); reset(onStatusCodeAwareResponseListener); requestStats = new RequestStats(1); requestStats.statusCode = (500); requestStats.hostName = ("flipkart.com"); forwardingResponse.onResponseSuccess(info, requestStats); verify(onStatusCodeAwareResponseListener, times(1)).onResponseServerError(info, requestStats); reset(onStatusCodeAwareResponseListener); requestStats = new RequestStats(1); requestStats.statusCode = (599); requestStats.hostName = ("flipkart.com"); forwardingResponse.onResponseSuccess(info, requestStats); verify(onStatusCodeAwareResponseListener, times(1)).onResponseServerError(info, requestStats); reset(onStatusCodeAwareResponseListener); }
@Override public void onResponseSuccess(NetworkInfo info, RequestStats requestStats) { if (requestStats != null) { int statusCode = requestStats.statusCode; if ((statusCode >= HttpStatusCode.HTTP_2XX_START && statusCode <= HttpStatusCode.HTTP_2XX_END) || (statusCode >= HttpStatusCode.HTTP_3XX_START && statusCode <= HttpStatusCode.HTTP_3XX_END)) { mOnStatusCodeAwareResponseListener.onResponseServerSuccess(info, requestStats); } else if ((statusCode >= HttpStatusCode.HTTP_4XX_START && statusCode <= HttpStatusCode.HTTP_4XX_END) || (statusCode >= HttpStatusCode.HTTP_5XX_START && statusCode <= HttpStatusCode.HTTP_5XX_END)) { mOnStatusCodeAwareResponseListener.onResponseServerError(info, requestStats); } } }
ForwardingResponse implements OnResponseListener { @Override public void onResponseSuccess(NetworkInfo info, RequestStats requestStats) { if (requestStats != null) { int statusCode = requestStats.statusCode; if ((statusCode >= HttpStatusCode.HTTP_2XX_START && statusCode <= HttpStatusCode.HTTP_2XX_END) || (statusCode >= HttpStatusCode.HTTP_3XX_START && statusCode <= HttpStatusCode.HTTP_3XX_END)) { mOnStatusCodeAwareResponseListener.onResponseServerSuccess(info, requestStats); } else if ((statusCode >= HttpStatusCode.HTTP_4XX_START && statusCode <= HttpStatusCode.HTTP_4XX_END) || (statusCode >= HttpStatusCode.HTTP_5XX_START && statusCode <= HttpStatusCode.HTTP_5XX_END)) { mOnStatusCodeAwareResponseListener.onResponseServerError(info, requestStats); } } } }
ForwardingResponse implements OnResponseListener { @Override public void onResponseSuccess(NetworkInfo info, RequestStats requestStats) { if (requestStats != null) { int statusCode = requestStats.statusCode; if ((statusCode >= HttpStatusCode.HTTP_2XX_START && statusCode <= HttpStatusCode.HTTP_2XX_END) || (statusCode >= HttpStatusCode.HTTP_3XX_START && statusCode <= HttpStatusCode.HTTP_3XX_END)) { mOnStatusCodeAwareResponseListener.onResponseServerSuccess(info, requestStats); } else if ((statusCode >= HttpStatusCode.HTTP_4XX_START && statusCode <= HttpStatusCode.HTTP_4XX_END) || (statusCode >= HttpStatusCode.HTTP_5XX_START && statusCode <= HttpStatusCode.HTTP_5XX_END)) { mOnStatusCodeAwareResponseListener.onResponseServerError(info, requestStats); } } } ForwardingResponse(OnStatusCodeAwareResponseListener onStatusCodeAwareResponseListener); }
ForwardingResponse implements OnResponseListener { @Override public void onResponseSuccess(NetworkInfo info, RequestStats requestStats) { if (requestStats != null) { int statusCode = requestStats.statusCode; if ((statusCode >= HttpStatusCode.HTTP_2XX_START && statusCode <= HttpStatusCode.HTTP_2XX_END) || (statusCode >= HttpStatusCode.HTTP_3XX_START && statusCode <= HttpStatusCode.HTTP_3XX_END)) { mOnStatusCodeAwareResponseListener.onResponseServerSuccess(info, requestStats); } else if ((statusCode >= HttpStatusCode.HTTP_4XX_START && statusCode <= HttpStatusCode.HTTP_4XX_END) || (statusCode >= HttpStatusCode.HTTP_5XX_START && statusCode <= HttpStatusCode.HTTP_5XX_END)) { mOnStatusCodeAwareResponseListener.onResponseServerError(info, requestStats); } } } ForwardingResponse(OnStatusCodeAwareResponseListener onStatusCodeAwareResponseListener); @Override void onResponseSuccess(NetworkInfo info, RequestStats requestStats); @Override void onResponseError(NetworkInfo info, RequestStats requestStats, Exception e); }
ForwardingResponse implements OnResponseListener { @Override public void onResponseSuccess(NetworkInfo info, RequestStats requestStats) { if (requestStats != null) { int statusCode = requestStats.statusCode; if ((statusCode >= HttpStatusCode.HTTP_2XX_START && statusCode <= HttpStatusCode.HTTP_2XX_END) || (statusCode >= HttpStatusCode.HTTP_3XX_START && statusCode <= HttpStatusCode.HTTP_3XX_END)) { mOnStatusCodeAwareResponseListener.onResponseServerSuccess(info, requestStats); } else if ((statusCode >= HttpStatusCode.HTTP_4XX_START && statusCode <= HttpStatusCode.HTTP_4XX_END) || (statusCode >= HttpStatusCode.HTTP_5XX_START && statusCode <= HttpStatusCode.HTTP_5XX_END)) { mOnStatusCodeAwareResponseListener.onResponseServerError(info, requestStats); } } } ForwardingResponse(OnStatusCodeAwareResponseListener onStatusCodeAwareResponseListener); @Override void onResponseSuccess(NetworkInfo info, RequestStats requestStats); @Override void onResponseError(NetworkInfo info, RequestStats requestStats, Exception e);  }