Use Duration.ZERO whenever possible

This commit is contained in:
Sam Brannen 2025-07-03 16:55:09 +02:00
parent 58061ae295
commit c6a8df4a9d
8 changed files with 13 additions and 13 deletions

View File

@ -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,

View File

@ -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();
}

View File

@ -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);

View File

@ -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)))

View File

@ -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())

View File

@ -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 <em>after</em>
* <p>If not, then an {@link AssertionError} is thrown. Typically used from a JUnit <em>after</em>
* method.
*/
public void checkForLeaks() {
checkForLeaks(Duration.ofSeconds(0));
checkForLeaks(Duration.ZERO);
}
/**

View File

@ -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);
}

View File

@ -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);
}