@Test public void responseOnTheFirstTry() throws InterruptedException { RetryableCalls retryableCalls = new RetryableCalls(); MockWebServer server = new MockWebServer(); Retrofit retrofit = new Retrofit.Builder() .baseUrl(server.url("/")) .addCallAdapterFactory(retryableCalls.getFactory()) .addConverterFactory(new ToStringConverterFactory()) .build(); Service service = retrofit.create(Service.class); final AtomicReference<Response<String>> responseRef = new AtomicReference<>(); final CountDownLatch latch = new CountDownLatch(1); server.enqueue(new MockResponse().setBody("Hi")); RetryableCall<String> call = service.getString(); call.enqueue(new RetryableCallback<String>() { @Override public void onResponse(RetryableCall<String> call, Response<String> response) { responseRef.set(response); latch.countDown(); } @Override public void onFailure(RetryableCall<String> call, Throwable t) { throw new AssertionError(); } @Override public void onFailureButCanRetry(RetryableCall<String> call, IOException e) { throw new AssertionError(); } }); assertThat(latch.await(10, SECONDS)).isTrue(); Response<String> response = responseRef.get(); assertThat(response.isSuccessful()).isTrue(); assertThat(response.body()).isEqualTo("Hi"); }
public CallAdapter.Factory getFactory() { return factory; }
RetryableCalls { public CallAdapter.Factory getFactory() { return factory; } }
RetryableCalls { public CallAdapter.Factory getFactory() { return factory; }  }
RetryableCalls { public CallAdapter.Factory getFactory() { return factory; }  CallAdapter.Factory getFactory(); void retryAllCalls(); void clearCalls(); }
RetryableCalls { public CallAdapter.Factory getFactory() { return factory; }  CallAdapter.Factory getFactory(); void retryAllCalls(); void clearCalls();  }