|
31 | 31 |
|
32 | 32 | import static org.junit.jupiter.api.Assertions.assertFalse; |
33 | 33 | import static org.mockito.Mockito.mock; |
| 34 | +import static org.mockito.Mockito.never; |
34 | 35 | import static org.mockito.Mockito.verify; |
35 | 36 | import static org.mockito.Mockito.when; |
36 | 37 |
|
@@ -201,4 +202,34 @@ void testShouldRetryWithContext_noPreviousSettings() { |
201 | 202 |
|
202 | 203 | assertFalse(algorithm.shouldRetry(context, previousThrowable, previousResult, null)); |
203 | 204 | } |
| 205 | + |
| 206 | + @Test |
| 207 | + void testShouldRetry_prevThrowableNotNull_shouldRetryBasedOnResultFalse_callsTimedAlgorithm() { |
| 208 | + ResultRetryAlgorithm<Object> resultAlgorithm = mock(ResultRetryAlgorithm.class); |
| 209 | + TimedRetryAlgorithm timedAlgorithm = mock(TimedRetryAlgorithm.class); |
| 210 | + RetryAlgorithm<Object> algorithm = new RetryAlgorithm<>(resultAlgorithm, timedAlgorithm); |
| 211 | + Throwable previousThrowable = new Throwable(); |
| 212 | + Object previousResult = new Object(); |
| 213 | + TimedAttemptSettings previousSettings = mock(TimedAttemptSettings.class); |
| 214 | + when(resultAlgorithm.shouldRetry(previousThrowable, previousResult)).thenReturn(false); |
| 215 | + |
| 216 | + algorithm.shouldRetry(previousThrowable, previousResult, previousSettings); |
| 217 | + |
| 218 | + verify(timedAlgorithm).shouldRetry(previousSettings); |
| 219 | + } |
| 220 | + |
| 221 | + @Test |
| 222 | + void testShouldRetry_prevThrowableNull_shouldRetryBasedOnResultFalse_shortCircuits() { |
| 223 | + ResultRetryAlgorithm<Object> resultAlgorithm = mock(ResultRetryAlgorithm.class); |
| 224 | + TimedRetryAlgorithm timedAlgorithm = mock(TimedRetryAlgorithm.class); |
| 225 | + RetryAlgorithm<Object> algorithm = new RetryAlgorithm<>(resultAlgorithm, timedAlgorithm); |
| 226 | + Object previousResult = new Object(); |
| 227 | + TimedAttemptSettings previousSettings = mock(TimedAttemptSettings.class); |
| 228 | + when(resultAlgorithm.shouldRetry(null, previousResult)).thenReturn(false); |
| 229 | + |
| 230 | + boolean shouldRetry = algorithm.shouldRetry(null, previousResult, previousSettings); |
| 231 | + |
| 232 | + assertFalse(shouldRetry); |
| 233 | + verify(timedAlgorithm, never()).shouldRetry(previousSettings); |
| 234 | + } |
204 | 235 | } |
0 commit comments