diff --git a/spring-core/src/main/java/org/springframework/core/retry/support/MaxRetryAttemptsPolicy.java b/spring-core/src/main/java/org/springframework/core/retry/support/MaxRetryAttemptsPolicy.java index 50938cd0be7..f2733953913 100644 --- a/spring-core/src/main/java/org/springframework/core/retry/support/MaxRetryAttemptsPolicy.java +++ b/spring-core/src/main/java/org/springframework/core/retry/support/MaxRetryAttemptsPolicy.java @@ -27,7 +27,7 @@ import org.springframework.util.Assert; * @author Sam Brannen * @since 7.0 */ -public class MaxRetryAttemptsPolicy implements RetryPolicy { +public final class MaxRetryAttemptsPolicy implements RetryPolicy { /** * The default maximum number of retry attempts: {@value}. diff --git a/spring-core/src/main/java/org/springframework/core/retry/support/MaxRetryDurationPolicy.java b/spring-core/src/main/java/org/springframework/core/retry/support/MaxRetryDurationPolicy.java index ea4b377c1d4..104b20d7ba6 100644 --- a/spring-core/src/main/java/org/springframework/core/retry/support/MaxRetryDurationPolicy.java +++ b/spring-core/src/main/java/org/springframework/core/retry/support/MaxRetryDurationPolicy.java @@ -30,7 +30,7 @@ import org.springframework.util.Assert; * @author Sam Brannen * @since 7.0 */ -public class MaxRetryDurationPolicy implements RetryPolicy { +public final class MaxRetryDurationPolicy implements RetryPolicy { /** * The default maximum retry duration: 3 seconds. diff --git a/spring-core/src/main/java/org/springframework/core/retry/support/PredicateRetryPolicy.java b/spring-core/src/main/java/org/springframework/core/retry/support/PredicateRetryPolicy.java index 4e294f12e18..902a46a81db 100644 --- a/spring-core/src/main/java/org/springframework/core/retry/support/PredicateRetryPolicy.java +++ b/spring-core/src/main/java/org/springframework/core/retry/support/PredicateRetryPolicy.java @@ -28,7 +28,7 @@ import org.springframework.core.retry.RetryPolicy; * @author Sam Brannen * @since 7.0 */ -public class PredicateRetryPolicy implements RetryPolicy { +public final class PredicateRetryPolicy implements RetryPolicy { private final Predicate predicate; diff --git a/spring-core/src/test/java/org/springframework/core/retry/RetryTemplateTests.java b/spring-core/src/test/java/org/springframework/core/retry/RetryTemplateTests.java index f2d20fd75d9..13a9e9ec86e 100644 --- a/spring-core/src/test/java/org/springframework/core/retry/RetryTemplateTests.java +++ b/spring-core/src/test/java/org/springframework/core/retry/RetryTemplateTests.java @@ -20,7 +20,6 @@ import java.time.Duration; import org.junit.jupiter.api.Test; -import org.springframework.core.retry.support.MaxRetryAttemptsPolicy; import org.springframework.util.backoff.FixedBackOff; import static org.assertj.core.api.Assertions.assertThat; @@ -110,20 +109,15 @@ class RetryTemplateTests { } }; - MaxRetryAttemptsPolicy retryPolicy = new MaxRetryAttemptsPolicy() { - @Override - public RetryExecution start() { - return new RetryExecution() { - - int retryAttempts; + RetryPolicy retryPolicy = () -> new RetryExecution() { + int retryAttempts; - @Override - public boolean shouldRetry(Throwable throwable) { - return this.retryAttempts++ < 3 && throwable instanceof TechnicalException; - } - }; + @Override + public boolean shouldRetry(Throwable throwable) { + return (this.retryAttempts++ < 3 && throwable instanceof TechnicalException); } }; + retryTemplate.setRetryPolicy(retryPolicy); retryTemplate.setBackOffPolicy(new FixedBackOff(Duration.ofMillis(10)));