2525
2626import static org .assertj .core .api .Assertions .assertThat ;
2727import static org .mockito .Mockito .mock ;
28+ import static org .springframework .core .retry .RetryPolicy .Builder .DEFAULT_DELAY ;
2829import static org .springframework .util .backoff .BackOffExecution .STOP ;
2930
3031/**
@@ -38,14 +39,14 @@ class MaxAttemptsRetryPolicyTests {
3839
3940 @ Test
4041 void maxAttempts () {
41- var retryPolicy = RetryPolicy .builder ().maxAttempts (2 ).delay (Duration .ofMillis (1 )).build ();
42+ var retryPolicy = RetryPolicy .builder ().maxAttempts (2 ).delay (Duration .ofMillis (0 )).build ();
4243 var backOffExecution = retryPolicy .getBackOff ().start ();
4344 var throwable = mock (Throwable .class );
4445
4546 assertThat (retryPolicy .shouldRetry (throwable )).isTrue ();
46- assertThat (backOffExecution .nextBackOff ()).isGreaterThan ( 0 );
47+ assertThat (backOffExecution .nextBackOff ()).isZero ( );
4748 assertThat (retryPolicy .shouldRetry (throwable )).isTrue ();
48- assertThat (backOffExecution .nextBackOff ()).isGreaterThan ( 0 );
49+ assertThat (backOffExecution .nextBackOff ()).isZero ( );
4950
5051 assertThat (retryPolicy .shouldRetry (throwable )).isTrue ();
5152 assertThat (backOffExecution .nextBackOff ()).isEqualTo (STOP );
@@ -65,13 +66,13 @@ void maxAttemptsAndPredicate() {
6566
6667 // 4 retries
6768 assertThat (retryPolicy .shouldRetry (new NumberFormatException ())).isTrue ();
68- assertThat (backOffExecution .nextBackOff ()).isGreaterThan ( 0 );
69+ assertThat (backOffExecution .nextBackOff ()).isEqualTo ( 1 );
6970 assertThat (retryPolicy .shouldRetry (new IllegalStateException ())).isFalse ();
70- assertThat (backOffExecution .nextBackOff ()).isGreaterThan ( 0 );
71+ assertThat (backOffExecution .nextBackOff ()).isEqualTo ( 1 );
7172 assertThat (retryPolicy .shouldRetry (new IllegalStateException ())).isFalse ();
72- assertThat (backOffExecution .nextBackOff ()).isGreaterThan ( 0 );
73+ assertThat (backOffExecution .nextBackOff ()).isEqualTo ( 1 );
7374 assertThat (retryPolicy .shouldRetry (new CustomNumberFormatException ())).isTrue ();
74- assertThat (backOffExecution .nextBackOff ()).isGreaterThan ( 0 );
75+ assertThat (backOffExecution .nextBackOff ()).isEqualTo ( 1 );
7576
7677 // After policy exhaustion
7778 assertThat (retryPolicy .shouldRetry (new NumberFormatException ())).isTrue ();
@@ -92,17 +93,17 @@ void maxAttemptsWithIncludesAndExcludes() {
9293
9394 // 6 retries
9495 assertThat (retryPolicy .shouldRetry (new IOException ())).isTrue ();
95- assertThat (backOffExecution .nextBackOff ()).isGreaterThan ( 0 );
96+ assertThat (backOffExecution .nextBackOff ()).isEqualTo ( DEFAULT_DELAY );
9697 assertThat (retryPolicy .shouldRetry (new RuntimeException ())).isTrue ();
97- assertThat (backOffExecution .nextBackOff ()).isGreaterThan ( 0 );
98+ assertThat (backOffExecution .nextBackOff ()).isEqualTo ( DEFAULT_DELAY );
9899 assertThat (retryPolicy .shouldRetry (new FileNotFoundException ())).isFalse ();
99- assertThat (backOffExecution .nextBackOff ()).isGreaterThan ( 0 );
100+ assertThat (backOffExecution .nextBackOff ()).isEqualTo ( DEFAULT_DELAY );
100101 assertThat (retryPolicy .shouldRetry (new FileSystemException ("file" ))).isTrue ();
101- assertThat (backOffExecution .nextBackOff ()).isGreaterThan ( 0 );
102+ assertThat (backOffExecution .nextBackOff ()).isEqualTo ( DEFAULT_DELAY );
102103 assertThat (retryPolicy .shouldRetry (new CustomFileSystemException ("file" ))).isFalse ();
103- assertThat (backOffExecution .nextBackOff ()).isGreaterThan ( 0 );
104+ assertThat (backOffExecution .nextBackOff ()).isEqualTo ( DEFAULT_DELAY );
104105 assertThat (retryPolicy .shouldRetry (new IOException ())).isTrue ();
105- assertThat (backOffExecution .nextBackOff ()).isGreaterThan ( 0 );
106+ assertThat (backOffExecution .nextBackOff ()).isEqualTo ( DEFAULT_DELAY );
106107
107108 // After policy exhaustion
108109 assertThat (retryPolicy .shouldRetry (new IOException ())).isTrue ();
0 commit comments