@Test public void retryableCallIsCanceledBeforeEnqueue() 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 CountDownLatch latch = new CountDownLatch(1);
  server.enqueue(new MockResponse().setBody("Hi"));
  RetryableCall<String> call = service.getString();
  assertThat(call.isCanceled()).isFalse();
  call.cancel();
  assertThat(call.isCanceled()).isTrue();
  call.enqueue(new RetryableCallback<String>() {
    @Override public void onResponse(RetryableCall<String> call, Response<String> response) {
      throw new AssertionError();
    }
    @Override public void onFailure(RetryableCall<String> call, Throwable t) {
      latch.countDown();
    }
    @Override public void onFailureButCanRetry(RetryableCall<String> call, IOException e) {
      throw new AssertionError();
    }
  });
  assertThat(latch.await(10, SECONDS)).isTrue();
}