@Test public void testParseNetworkErrorCantRetry() throws VolleyError { when(requeuePolicy.shouldRequeue(any(NetworkResponse.class))).thenReturn(Boolean.TRUE); final RetryPolicy retryPolicy = mock(RetryPolicy.class); doThrow(VolleyError.class).when(retryPolicy).retry(any(VolleyError.class)); when(request.getRetryPolicy()).thenReturn(retryPolicy); final VolleyError error = mock(VolleyError.class); final VolleyError volleyError = decorator.parseNetworkError(error); assertNotNull(volleyError); verify(requeuePolicy, never()).executeBeforeRequeueing(any(Listener.class), any(ErrorListener.class)); }
@Nullable @Override protected VolleyError parseNetworkError(final VolleyError volleyError) { final NetworkResponse response = volleyError.networkResponse; if (requeuePolicy.shouldRequeue(response)) { try { wrapped.getRetryPolicy().retry(new VolleyError("Retry strategy decided to retry.")); } catch (final VolleyError e) { return e; } requeuePolicy.executeBeforeRequeueing( new Listener<Object>() { @Override public void onResponse(final Object arg0) { queue.add(RequeueAfterRequestDecorator.this); } }, new ErrorListener() { @Override public void onErrorResponse(final VolleyError error) { Log.e(VolleyLog.TAG, "Failed to retry", error.getCause()); } }); return null; } return wrapped.parseNetworkError(volleyError); }
RequeueAfterRequestDecorator extends RequestDecorator<T> { @Nullable @Override protected VolleyError parseNetworkError(final VolleyError volleyError) { final NetworkResponse response = volleyError.networkResponse; if (requeuePolicy.shouldRequeue(response)) { try { wrapped.getRetryPolicy().retry(new VolleyError("Retry strategy decided to retry.")); } catch (final VolleyError e) { return e; } requeuePolicy.executeBeforeRequeueing( new Listener<Object>() { @Override public void onResponse(final Object arg0) { queue.add(RequeueAfterRequestDecorator.this); } }, new ErrorListener() { @Override public void onErrorResponse(final VolleyError error) { Log.e(VolleyLog.TAG, "Failed to retry", error.getCause()); } }); return null; } return wrapped.parseNetworkError(volleyError); } }
RequeueAfterRequestDecorator extends RequestDecorator<T> { @Nullable @Override protected VolleyError parseNetworkError(final VolleyError volleyError) { final NetworkResponse response = volleyError.networkResponse; if (requeuePolicy.shouldRequeue(response)) { try { wrapped.getRetryPolicy().retry(new VolleyError("Retry strategy decided to retry.")); } catch (final VolleyError e) { return e; } requeuePolicy.executeBeforeRequeueing( new Listener<Object>() { @Override public void onResponse(final Object arg0) { queue.add(RequeueAfterRequestDecorator.this); } }, new ErrorListener() { @Override public void onErrorResponse(final VolleyError error) { Log.e(VolleyLog.TAG, "Failed to retry", error.getCause()); } }); return null; } return wrapped.parseNetworkError(volleyError); } private  RequeueAfterRequestDecorator(@NonNull final Request<T> request,
					@NonNull final RequeuePolicy requeuePolicy); }
RequeueAfterRequestDecorator extends RequestDecorator<T> { @Nullable @Override protected VolleyError parseNetworkError(final VolleyError volleyError) { final NetworkResponse response = volleyError.networkResponse; if (requeuePolicy.shouldRequeue(response)) { try { wrapped.getRetryPolicy().retry(new VolleyError("Retry strategy decided to retry.")); } catch (final VolleyError e) { return e; } requeuePolicy.executeBeforeRequeueing( new Listener<Object>() { @Override public void onResponse(final Object arg0) { queue.add(RequeueAfterRequestDecorator.this); } }, new ErrorListener() { @Override public void onErrorResponse(final VolleyError error) { Log.e(VolleyLog.TAG, "Failed to retry", error.getCause()); } }); return null; } return wrapped.parseNetworkError(volleyError); } private  RequeueAfterRequestDecorator(@NonNull final Request<T> request,
					@NonNull final RequeuePolicy requeuePolicy); static RequeueAfterRequestDecorator<T> wrap(
					@NonNull final Request<T> request, @NonNull final RequeuePolicy requeuePolicy); @Override Request<?> setRequestQueue(final RequestQueue requestQueue); }
RequeueAfterRequestDecorator extends RequestDecorator<T> { @Nullable @Override protected VolleyError parseNetworkError(final VolleyError volleyError) { final NetworkResponse response = volleyError.networkResponse; if (requeuePolicy.shouldRequeue(response)) { try { wrapped.getRetryPolicy().retry(new VolleyError("Retry strategy decided to retry.")); } catch (final VolleyError e) { return e; } requeuePolicy.executeBeforeRequeueing( new Listener<Object>() { @Override public void onResponse(final Object arg0) { queue.add(RequeueAfterRequestDecorator.this); } }, new ErrorListener() { @Override public void onErrorResponse(final VolleyError error) { Log.e(VolleyLog.TAG, "Failed to retry", error.getCause()); } }); return null; } return wrapped.parseNetworkError(volleyError); } private  RequeueAfterRequestDecorator(@NonNull final Request<T> request,
					@NonNull final RequeuePolicy requeuePolicy); static RequeueAfterRequestDecorator<T> wrap(
					@NonNull final Request<T> request, @NonNull final RequeuePolicy requeuePolicy); @Override Request<?> setRequestQueue(final RequestQueue requestQueue);  }