BaseRefreshableAuthenticator implements Authenticator { protected boolean canRetry(Response response) { int responseCount = 1; while ((response = response.priorResponse()) != null) { responseCount++; } return responseCount < MAX_RETRIES; }  @Override final Request refresh(Response response);  }
@Test public void testCanRetry_whenUnderMax_returnsTrue() throws Exception { Response underMax = response.newBuilder().priorResponse(response).build(); assertTrue(authenticator.canRetry(underMax)); }
@Test public void testCanRetry_whenOverMax_returnsFalse() throws Exception { Response wrapper1 = response.newBuilder().priorResponse(response).build(); Response wrapper2 = wrapper1.newBuilder().priorResponse(wrapper1).build(); Response wrapper3 = wrapper2.newBuilder().priorResponse(wrapper2).build(); Response wrapper4 = wrapper3.newBuilder().priorResponse(wrapper3).build(); assertFalse(authenticator.canRetry(wrapper4)); }