AndRetryCondition implements RetryCondition { @Override public boolean shouldRetry(RetryPolicyContext context) { for (RetryCondition retryCondition : conditions) { if (!retryCondition.shouldRetry(context)) { return false; } } return true; } AndRetryCondition(RetryCondition... conditions); @Override boolean shouldRetry(RetryPolicyContext context);  }
@Test public void allFalseConditions_ReturnsFalse() { assertFalse(andCondition.shouldRetry(RetryPolicyContexts.EMPTY)); }
@Test public void onlyFirstConditionIsTrue_ReturnsFalse() { when(conditionOne.shouldRetry(any(RetryPolicyContext.class))) .thenReturn(true); assertFalse(andCondition.shouldRetry(RetryPolicyContexts.EMPTY)); }
@Test public void onlySecondConditionIsTrue_ReturnsFalse() { when(conditionTwo.shouldRetry(any(RetryPolicyContext.class))) .thenReturn(true); assertFalse(andCondition.shouldRetry(RetryPolicyContexts.EMPTY)); }
@Test public void bothConditionsAreTrue_ReturnsTrue() { when(conditionOne.shouldRetry(any(RetryPolicyContext.class))) .thenReturn(true); when(conditionTwo.shouldRetry(any(RetryPolicyContext.class))) .thenReturn(true); assertTrue(andCondition.shouldRetry(RetryPolicyContexts.EMPTY)); }
@Test(expected = IllegalArgumentException.class) public void noConditions_ThrowsException() { new AndRetryCondition().shouldRetry(RetryPolicyContexts.EMPTY); }
@Test public void singleConditionThatReturnsTrue_ReturnsTrue() { when(conditionOne.shouldRetry(RetryPolicyContexts.EMPTY)) .thenReturn(true); assertTrue(new AndRetryCondition(conditionOne).shouldRetry(RetryPolicyContexts.EMPTY)); }
@Test public void singleConditionThatReturnsFalse_ReturnsFalse() { when(conditionOne.shouldRetry(RetryPolicyContexts.EMPTY)) .thenReturn(false); assertFalse(new AndRetryCondition(conditionOne).shouldRetry(RetryPolicyContexts.EMPTY)); }