Caller caller = new Caller();
caller.setMaxAttempts(3);
// no attempts made so far (allowed for some exceptions)
assertFalse(caller.isAnotherAttemptAllowed(null));
assertTrue(caller.isAnotherAttemptAllowed(new RequestTimeoutException(null, 0)));
assertFalse(caller.isAnotherAttemptAllowed(new Exception("Hello")));
// 1 attempt made so far (allowed for some exceptions)
caller.incrementAttempts();
assertFalse(caller.isAnotherAttemptAllowed(null));
assertTrue(caller.isAnotherAttemptAllowed(new RequestTimeoutException(null, 0)));
assertFalse(caller.isAnotherAttemptAllowed(new Exception("Hello")));
// 2 attempts made so far (allowed for some exceptions)
caller.incrementAttempts();
assertFalse(caller.isAnotherAttemptAllowed(null));
assertTrue(caller.isAnotherAttemptAllowed(new RequestTimeoutException(null, 0)));
assertFalse(caller.isAnotherAttemptAllowed(new Exception("Hello")));
// 3 attempts made so far (disallowed because we've already made the maximum number of retries)
caller.incrementAttempts();
assertFalse(caller.isAnotherAttemptAllowed(null));
assertFalse(caller.isAnotherAttemptAllowed(new RequestTimeoutException(null, 0)));
assertFalse(caller.isAnotherAttemptAllowed(new Exception("Hello")));
}