// Given the HelloWorldService returns Hello world | |
BDDMockito.given(helloWorldService.returnHelloWorld()).willReturn("Hello world"); | |
// Create a Retry with default configuration | |
final RetryConfig tryAgain = RetryConfig.<String>custom().retryOnResult(s -> s.contains("Hello world")) | |
.maxAttempts(2).build(); | |
Retry retry = Retry.of("id", tryAgain); | |
// Decorate the invocation of the HelloWorldService | |
Supplier<String> supplier = Retry.decorateSupplier(retry, helloWorldService::returnHelloWorld); | |
// When | |
String result = supplier.get(); | |
// Then the helloWorldService should be invoked 1 time | |
BDDMockito.then(helloWorldService).should(Mockito.times(2)).returnHelloWorld(); | |
assertThat(result).isEqualTo("Hello world"); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment