GuestAuthenticator implements Authenticator { boolean canRetry(Response response) { int responseCount = 1; while ((response = response.priorResponse()) != null) { responseCount++; } return responseCount < MAX_RETRIES; } GuestAuthenticator(GuestSessionProvider guestSessionProvider); @Override Request authenticate(Route route, Response response);  }
@Test public void testCanRetry_firstRetry() { assertTrue(authenticator.canRetry(response)); }
@Test public void testCanRetry_secondRetry() { final Response failedResponse = new Response.Builder() .code(401) .message("Unauthorized") .protocol(Protocol.HTTP_1_1) .request(request) .priorResponse(response) .build(); assertFalse(authenticator.canRetry(failedResponse)); }