I am using retryTemplate and I have no idea how to do the unit tests for this. Can any one help?
I have this piece of code (for example) and I would like to test that the first time I call Card.create fails but the second one it works.
@Autowired
private RetryTemplate retryTemplate;
public String registerCard(final String cardNumber) throws ApiException {
final Card response = retryTemplate.execute(new RetryCallback<Card, ApiException>() {
@Override public Card doWithRetry(RetryContext retryContext) throws ApiException {
return Card.create(map);
}
}) ;
return response.get("number").toString();
}
RetryTemplate has maxAttemps = 2 and backOff = 1500.
Best regards.
In your test, case add a
RetryListener
implementation to theRetryTemplate
; use the methods on the listener to monitor the retry activity.