RetryOnStatusCodeCondition implements RetryCondition { @Override public boolean shouldRetry(RetryPolicyContext context) { if (context.httpStatusCode() != null) { for (Integer statusCode : statusCodesToRetryOn) { if (statusCode.equals(context.httpStatusCode())) { return true; } } } return false; } RetryOnStatusCodeCondition(List<Integer> statusCodesToRetryOn); @Override boolean shouldRetry(RetryPolicyContext context);  }
@Test public void retryableStatusCode_ReturnsTrue() { assertTrue(condition.shouldRetry(RetryPolicyContexts.withStatusCode(404))); }
@Test public void nonRetryableStatusCode_ReturnsTrue() { assertFalse(condition.shouldRetry(RetryPolicyContexts.withStatusCode(400))); }
@Test public void noStatusCodeInContext_ReturnFalse() { assertFalse(condition.shouldRetry(RetryPolicyContexts.withStatusCode(null))); }
@Test public void noStatusCodesInList_ReturnsFalse() { final RetryCondition noStatusCodes = new RetryOnStatusCodeCondition(Collections.<Integer>emptyList()); assertFalse(noStatusCodes.shouldRetry(RetryPolicyContexts.withStatusCode(404))); }