From c6a8df4a9db06e377f0884f3a40b70b873b7f381 Mon Sep 17 00:00:00 2001 From: Sam Brannen <104798+sbrannen@users.noreply.github.com> Date: Thu, 3 Jul 2025 16:55:09 +0200 Subject: [PATCH] Use Duration.ZERO whenever possible --- .../springframework/resilience/retry/MethodRetrySpec.java | 2 +- .../scheduling/config/ScheduledTaskTests.java | 2 +- .../core/retry/MaxAttemptsRetryPolicyTests.java | 2 +- .../org/springframework/core/retry/RetryPolicyTests.java | 2 +- .../springframework/core/retry/RetryTemplateTests.java | 8 ++++---- .../testfixture/io/buffer/LeakAwareDataBufferFactory.java | 4 ++-- .../web/reactive/DispatcherHandlerTests.java | 4 ++-- .../RequestParamMapMethodArgumentResolverTests.java | 2 +- 8 files changed, 13 insertions(+), 13 deletions(-) diff --git a/spring-context/src/main/java/org/springframework/resilience/retry/MethodRetrySpec.java b/spring-context/src/main/java/org/springframework/resilience/retry/MethodRetrySpec.java index d747f1f8504..515d9e4190f 100644 --- a/spring-context/src/main/java/org/springframework/resilience/retry/MethodRetrySpec.java +++ b/spring-context/src/main/java/org/springframework/resilience/retry/MethodRetrySpec.java @@ -52,7 +52,7 @@ public record MethodRetrySpec( Duration maxDelay) { public MethodRetrySpec(MethodRetryPredicate predicate, long maxAttempts, Duration delay) { - this(predicate, maxAttempts, delay, Duration.ofMillis(0), 1.0, Duration.ofMillis(Long.MAX_VALUE)); + this(predicate, maxAttempts, delay, Duration.ZERO, 1.0, Duration.ofMillis(Long.MAX_VALUE)); } public MethodRetrySpec(MethodRetryPredicate predicate, long maxAttempts, Duration delay, diff --git a/spring-context/src/test/java/org/springframework/scheduling/config/ScheduledTaskTests.java b/spring-context/src/test/java/org/springframework/scheduling/config/ScheduledTaskTests.java index 7db4a2acd13..79f42c13055 100644 --- a/spring-context/src/test/java/org/springframework/scheduling/config/ScheduledTaskTests.java +++ b/spring-context/src/test/java/org/springframework/scheduling/config/ScheduledTaskTests.java @@ -90,7 +90,7 @@ class ScheduledTaskTests { @Test void singleExecutionShouldNotHaveNextExecution() { - ScheduledTask scheduledTask = taskRegistrar.scheduleOneTimeTask(new OneTimeTask(countingRunnable, Duration.ofSeconds(0))); + ScheduledTask scheduledTask = taskRegistrar.scheduleOneTimeTask(new OneTimeTask(countingRunnable, Duration.ZERO)); Awaitility.await().atMost(Duration.ofSeconds(5)).until(() -> countingRunnable.executionCount > 0); assertThat(scheduledTask.nextExecution()).isNull(); } diff --git a/spring-core/src/test/java/org/springframework/core/retry/MaxAttemptsRetryPolicyTests.java b/spring-core/src/test/java/org/springframework/core/retry/MaxAttemptsRetryPolicyTests.java index 1fadc24f235..d7e559e9592 100644 --- a/spring-core/src/test/java/org/springframework/core/retry/MaxAttemptsRetryPolicyTests.java +++ b/spring-core/src/test/java/org/springframework/core/retry/MaxAttemptsRetryPolicyTests.java @@ -39,7 +39,7 @@ class MaxAttemptsRetryPolicyTests { @Test void maxAttempts() { - var retryPolicy = RetryPolicy.builder().maxAttempts(2).delay(Duration.ofMillis(0)).build(); + var retryPolicy = RetryPolicy.builder().maxAttempts(2).delay(Duration.ZERO).build(); var backOffExecution = retryPolicy.getBackOff().start(); var throwable = mock(Throwable.class); diff --git a/spring-core/src/test/java/org/springframework/core/retry/RetryPolicyTests.java b/spring-core/src/test/java/org/springframework/core/retry/RetryPolicyTests.java index 5ba4469c5c2..62b0a42e3f4 100644 --- a/spring-core/src/test/java/org/springframework/core/retry/RetryPolicyTests.java +++ b/spring-core/src/test/java/org/springframework/core/retry/RetryPolicyTests.java @@ -209,7 +209,7 @@ class RetryPolicyTests { @Test void maxDelayPreconditions() { assertThatIllegalArgumentException() - .isThrownBy(() -> RetryPolicy.builder().maxDelay(Duration.ofMillis(0))) + .isThrownBy(() -> RetryPolicy.builder().maxDelay(Duration.ZERO)) .withMessage("Invalid duration (0ms): maxDelay must be positive."); assertThatIllegalArgumentException() .isThrownBy(() -> RetryPolicy.builder().maxDelay(Duration.ofMillis(-1))) 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 d7a40388558..96f47a2d1ef 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 @@ -51,7 +51,7 @@ class RetryTemplateTests { void configureRetryTemplate() { var retryPolicy = RetryPolicy.builder() .maxAttempts(3) - .delay(Duration.ofMillis(0)) + .delay(Duration.ZERO) .build(); retryTemplate.setRetryPolicy(retryPolicy); @@ -171,7 +171,7 @@ class RetryTemplateTests { var retryPolicy = RetryPolicy.builder() .maxAttempts(Integer.MAX_VALUE) - .delay(Duration.ofMillis(0)) + .delay(Duration.ZERO) .includes(IOException.class) .build(); @@ -194,13 +194,13 @@ class RetryTemplateTests { argumentSet("Excludes", RetryPolicy.builder() .maxAttempts(Integer.MAX_VALUE) - .delay(Duration.ofMillis(0)) + .delay(Duration.ZERO) .excludes(FileNotFoundException.class) .build()), argumentSet("Includes & Excludes", RetryPolicy.builder() .maxAttempts(Integer.MAX_VALUE) - .delay(Duration.ofMillis(0)) + .delay(Duration.ZERO) .includes(IOException.class) .excludes(FileNotFoundException.class) .build()) diff --git a/spring-core/src/testFixtures/java/org/springframework/core/testfixture/io/buffer/LeakAwareDataBufferFactory.java b/spring-core/src/testFixtures/java/org/springframework/core/testfixture/io/buffer/LeakAwareDataBufferFactory.java index aa7751bdde0..368fe698ab1 100644 --- a/spring-core/src/testFixtures/java/org/springframework/core/testfixture/io/buffer/LeakAwareDataBufferFactory.java +++ b/spring-core/src/testFixtures/java/org/springframework/core/testfixture/io/buffer/LeakAwareDataBufferFactory.java @@ -76,11 +76,11 @@ public class LeakAwareDataBufferFactory implements DataBufferFactory { /** * Checks whether all the data buffers allocated by this factory have also been released. - * If not, then an {@link AssertionError} is thrown. Typically used from a JUnit after + *
If not, then an {@link AssertionError} is thrown. Typically used from a JUnit after * method. */ public void checkForLeaks() { - checkForLeaks(Duration.ofSeconds(0)); + checkForLeaks(Duration.ZERO); } /** diff --git a/spring-webflux/src/test/java/org/springframework/web/reactive/DispatcherHandlerTests.java b/spring-webflux/src/test/java/org/springframework/web/reactive/DispatcherHandlerTests.java index d282aee71f7..8b53591bf4c 100644 --- a/spring-webflux/src/test/java/org/springframework/web/reactive/DispatcherHandlerTests.java +++ b/spring-webflux/src/test/java/org/springframework/web/reactive/DispatcherHandlerTests.java @@ -71,7 +71,7 @@ class DispatcherHandlerTests { context.refresh(); MockServerWebExchange exchange = MockServerWebExchange.from(MockServerHttpRequest.get("/")); - new DispatcherHandler(context).handle(exchange).block(Duration.ofSeconds(0)); + new DispatcherHandler(context).handle(exchange).block(Duration.ZERO); assertThat(exchange.getResponse().getBodyAsString().block(Duration.ofSeconds(5))).isEqualTo("1"); } @@ -94,7 +94,7 @@ class DispatcherHandlerTests { .build(); MockServerWebExchange exchange = MockServerWebExchange.from(request); - new DispatcherHandler(context).handle(exchange).block(Duration.ofSeconds(0)); + new DispatcherHandler(context).handle(exchange).block(Duration.ZERO); verifyNoInteractions(webHandler); } diff --git a/spring-webflux/src/test/java/org/springframework/web/reactive/result/method/annotation/RequestParamMapMethodArgumentResolverTests.java b/spring-webflux/src/test/java/org/springframework/web/reactive/result/method/annotation/RequestParamMapMethodArgumentResolverTests.java index 7b7f0a396bc..162f1ededd2 100644 --- a/spring-webflux/src/test/java/org/springframework/web/reactive/result/method/annotation/RequestParamMapMethodArgumentResolverTests.java +++ b/spring-webflux/src/test/java/org/springframework/web/reactive/result/method/annotation/RequestParamMapMethodArgumentResolverTests.java @@ -91,7 +91,7 @@ class RequestParamMapMethodArgumentResolverTests { private Object resolve(MethodParameter parameter, ServerWebExchange exchange) { - return this.resolver.resolveArgument(parameter, null, exchange).block(Duration.ofMillis(0)); + return this.resolver.resolveArgument(parameter, null, exchange).block(Duration.ZERO); }