Created
December 4, 2018 17:32
-
-
Save Romeh/7624e982068709ebc2a7b62f7cb961d3 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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