Skip to content

Commit 175b78d

Browse files
committed
Address code review
- Fix listeners initialization in CompositeRetryListener - Fix mocking usage in MaxRetryAttemptsPolicyTests
1 parent ca4bc84 commit 175b78d

File tree

2 files changed

+9
-7
lines changed

2 files changed

+9
-7
lines changed

spring-core/src/main/java/org/springframework/core/retry/support/CompositeRetryListener.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,10 +46,11 @@ public CompositeRetryListener() {
4646

4747
/**
4848
* Create a new {@link CompositeRetryListener} with a list of delegates.
49-
* @param listeners the delegate listeners to register
49+
* @param listeners the delegate listeners to register. Must not be empty.
5050
*/
5151
public CompositeRetryListener(List<RetryListener> listeners) {
52-
this.listeners = listeners;
52+
Assert.notEmpty(listeners, "RetryListener List must not be empty");
53+
this.listeners = List.copyOf(listeners);
5354
}
5455

5556
/**

spring-core/src/test/java/org/springframework/core/retry/support/MaxRetryAttemptsPolicyTests.java

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,12 @@
1717
package org.springframework.core.retry.support;
1818

1919
import org.junit.jupiter.api.Test;
20-
import org.mockito.Mockito;
2120

2221
import org.springframework.core.retry.RetryExecution;
2322

2423
import static org.assertj.core.api.Assertions.assertThat;
2524
import static org.assertj.core.api.Assertions.assertThatThrownBy;
25+
import static org.mockito.Mockito.mock;
2626

2727
/**
2828
* Tests for {@link MaxRetryAttemptsPolicy}.
@@ -35,15 +35,16 @@ class MaxRetryAttemptsPolicyTests {
3535
void testDefaultMaxRetryAttempts() {
3636
// given
3737
MaxRetryAttemptsPolicy retryPolicy = new MaxRetryAttemptsPolicy();
38+
Throwable throwable = mock();
3839

3940
// when
4041
RetryExecution retryExecution = retryPolicy.start();
4142

4243
// then
43-
assertThat(retryExecution.shouldRetry(Mockito.any(Exception.class))).isTrue();
44-
assertThat(retryExecution.shouldRetry(Mockito.any(Exception.class))).isTrue();
45-
assertThat(retryExecution.shouldRetry(Mockito.any(Exception.class))).isTrue();
46-
assertThat(retryExecution.shouldRetry(Mockito.any(Exception.class))).isFalse();
44+
assertThat(retryExecution.shouldRetry(throwable)).isTrue();
45+
assertThat(retryExecution.shouldRetry(throwable)).isTrue();
46+
assertThat(retryExecution.shouldRetry(throwable)).isTrue();
47+
assertThat(retryExecution.shouldRetry(throwable)).isFalse();
4748
}
4849

4950
@Test

0 commit comments

Comments
 (0)