@Test public void testOnHttpExchangeError() { OnResponseListener onResponseListener = mock(OnResponseListener.class); OnResponseListener onResponseListener1 = mock(OnResponseListener.class); PersistentStatsHandler persistentStatsHandler = new PersistentStatsHandler(RuntimeEnvironment.application); persistentStatsHandler.addListener(onResponseListener); Assert.assertTrue(persistentStatsHandler.mOnResponseListeners.size() == 1); RequestStats requestStats = new RequestStats(1); persistentStatsHandler.onHttpExchangeError(requestStats, new IOException("")); verify(onResponseListener, times(1)).onResponseError(any(NetworkInfo.class), eq(requestStats), any(IOException.class)); persistentStatsHandler.addListener(onResponseListener1); reset(onResponseListener); Assert.assertTrue(persistentStatsHandler.mOnResponseListeners.size() == 2); persistentStatsHandler.onHttpExchangeError(requestStats, new IOException("")); verify(onResponseListener, times(1)).onResponseError(any(NetworkInfo.class), eq(requestStats), any(IOException.class)); verify(onResponseListener1, times(1)).onResponseError(any(NetworkInfo.class), eq(requestStats), any(IOException.class)); }
@Override public void onHttpExchangeError(RequestStats requestStats, IOException e) { if (Utils.isLoggingEnabled) { Log.d("Response Http Error :", requestStats + ""); } for (OnResponseListener onResponseListener : mOnResponseListeners) { if (onResponseListener != null) { onResponseListener.onResponseError(getActiveNetworkInfo(), requestStats, e); } } }
PersistentStatsHandler implements NetworkRequestStatsHandler { @Override public void onHttpExchangeError(RequestStats requestStats, IOException e) { if (Utils.isLoggingEnabled) { Log.d("Response Http Error :", requestStats + ""); } for (OnResponseListener onResponseListener : mOnResponseListeners) { if (onResponseListener != null) { onResponseListener.onResponseError(getActiveNetworkInfo(), requestStats, e); } } } }
PersistentStatsHandler implements NetworkRequestStatsHandler { @Override public void onHttpExchangeError(RequestStats requestStats, IOException e) { if (Utils.isLoggingEnabled) { Log.d("Response Http Error :", requestStats + ""); } for (OnResponseListener onResponseListener : mOnResponseListeners) { if (onResponseListener != null) { onResponseListener.onResponseError(getActiveNetworkInfo(), requestStats, e); } } } PersistentStatsHandler(Context context); @VisibleForTesting  PersistentStatsHandler(Context context, PreferenceManager preferenceManager); }
PersistentStatsHandler implements NetworkRequestStatsHandler { @Override public void onHttpExchangeError(RequestStats requestStats, IOException e) { if (Utils.isLoggingEnabled) { Log.d("Response Http Error :", requestStats + ""); } for (OnResponseListener onResponseListener : mOnResponseListeners) { if (onResponseListener != null) { onResponseListener.onResponseError(getActiveNetworkInfo(), requestStats, e); } } } PersistentStatsHandler(Context context); @VisibleForTesting  PersistentStatsHandler(Context context, PreferenceManager preferenceManager); NetworkInfo getActiveNetworkInfo(); void addListener(OnResponseListener onResponseListener); void removeListener(OnResponseListener onResponseListener); void setMaxSizeForPersistence(int size); float getAverageNetworkSpeed(); ConnectionQuality getConnectionQuality(); @Override void onResponseReceived(final RequestStats requestStats); @Override void onHttpExchangeError(RequestStats requestStats, IOException e); @Override void onResponseInputStreamError(RequestStats requestStats, Exception e); }
PersistentStatsHandler implements NetworkRequestStatsHandler { @Override public void onHttpExchangeError(RequestStats requestStats, IOException e) { if (Utils.isLoggingEnabled) { Log.d("Response Http Error :", requestStats + ""); } for (OnResponseListener onResponseListener : mOnResponseListeners) { if (onResponseListener != null) { onResponseListener.onResponseError(getActiveNetworkInfo(), requestStats, e); } } } PersistentStatsHandler(Context context); @VisibleForTesting  PersistentStatsHandler(Context context, PreferenceManager preferenceManager); NetworkInfo getActiveNetworkInfo(); void addListener(OnResponseListener onResponseListener); void removeListener(OnResponseListener onResponseListener); void setMaxSizeForPersistence(int size); float getAverageNetworkSpeed(); ConnectionQuality getConnectionQuality(); @Override void onResponseReceived(final RequestStats requestStats); @Override void onHttpExchangeError(RequestStats requestStats, IOException e); @Override void onResponseInputStreamError(RequestStats requestStats, Exception e);  }