Skip to content

Commit 5afd8d1

Browse files
committed
Merge remote-tracking branch 'origin/4.1.x' into 4.2.x
Signed-off-by: Olga Maciaszek-Sharma <[email protected]> # Conflicts: # docs/package.json
2 parents 0395134 + 76cbd13 commit 5afd8d1

File tree

6 files changed

+196
-194
lines changed

6 files changed

+196
-194
lines changed

spring-cloud-commons/src/test/java/org/springframework/cloud/client/loadbalancer/RetryLoadBalancerInterceptorTests.java

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2012-2020 the original author or authors.
2+
* Copyright 2012-2025 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -29,7 +29,6 @@
2929
import java.util.concurrent.ConcurrentHashMap;
3030

3131
import org.junit.jupiter.api.AfterEach;
32-
import org.junit.jupiter.api.Assertions;
3332
import org.junit.jupiter.api.BeforeEach;
3433
import org.junit.jupiter.api.Test;
3534
import org.junit.jupiter.api.extension.ExtendWith;
@@ -56,6 +55,9 @@
5655
import org.springframework.retry.listener.RetryListenerSupport;
5756

5857
import static org.assertj.core.api.Assertions.assertThat;
58+
import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
59+
import static org.assertj.core.api.Assertions.assertThatIOException;
60+
import static org.assertj.core.api.Assertions.assertThatIllegalStateException;
5961
import static org.assertj.core.api.BDDAssertions.then;
6062
import static org.mockito.ArgumentMatchers.any;
6163
import static org.mockito.ArgumentMatchers.eq;
@@ -117,7 +119,7 @@ public void interceptDisableRetry() throws Throwable {
117119

118120
when(lbRequestFactory.createRequest(any(), any(), any())).thenReturn(mock(LoadBalancerRequest.class));
119121

120-
Assertions.assertThrows(IOException.class, () -> interceptor.intercept(request, body, execution));
122+
assertThatIOException().isThrownBy(() -> interceptor.intercept(request, body, execution));
121123
verify(lbRequestFactory).createRequest(request, body, execution);
122124
}
123125

@@ -130,7 +132,7 @@ public void interceptInvalidHost() throws Throwable {
130132
loadBalancedRetryFactory, lbFactory);
131133
byte[] body = new byte[] {};
132134
ClientHttpRequestExecution execution = mock(ClientHttpRequestExecution.class);
133-
Assertions.assertThrows(IllegalStateException.class, () -> interceptor.intercept(request, body, execution));
135+
assertThatIllegalStateException().isThrownBy(() -> interceptor.intercept(request, body, execution));
134136
}
135137

136138
@Test
@@ -288,7 +290,7 @@ public void interceptFailedRetry() throws Exception {
288290
new MyLoadBalancedRetryFactory(policy), lbFactory);
289291
byte[] body = new byte[] {};
290292
ClientHttpRequestExecution execution = mock(ClientHttpRequestExecution.class);
291-
Assertions.assertThrows(IOException.class, () -> interceptor.intercept(request, body, execution));
293+
assertThatIOException().isThrownBy(() -> interceptor.intercept(request, body, execution));
292294
verify(lbRequestFactory).createRequest(request, body, execution);
293295
}
294296

@@ -370,8 +372,8 @@ public <T, E extends Throwable> boolean open(RetryContext context, RetryCallback
370372
new MyLoadBalancedRetryFactory(policy, backOffPolicy, new RetryListener[] { myRetryListener }),
371373
lbFactory);
372374
ClientHttpRequestExecution execution = mock(ClientHttpRequestExecution.class);
373-
Assertions.assertThrows(TerminatedRetryException.class,
374-
() -> interceptor.intercept(request, new byte[] {}, execution));
375+
assertThatExceptionOfType(TerminatedRetryException.class)
376+
.isThrownBy(() -> interceptor.intercept(request, new byte[] {}, execution));
375377
}
376378

377379
@Test

spring-cloud-context-integration-tests/src/test/java/org/springframework/cloud/context/integration/RefreshScopeIntegrationTests.java

Lines changed: 31 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2013-2020 the original author or authors.
2+
* Copyright 2013-2025 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -19,7 +19,6 @@
1919
import org.apache.commons.logging.Log;
2020
import org.apache.commons.logging.LogFactory;
2121
import org.junit.jupiter.api.AfterEach;
22-
import org.junit.jupiter.api.Assertions;
2322
import org.junit.jupiter.api.BeforeEach;
2423
import org.junit.jupiter.api.Test;
2524

@@ -42,6 +41,7 @@
4241
import org.springframework.jmx.export.annotation.ManagedResource;
4342
import org.springframework.test.annotation.DirtiesContext;
4443

44+
import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
4545
import static org.assertj.core.api.BDDAssertions.then;
4646

4747
@SpringBootTest(classes = TestConfiguration.class)
@@ -71,27 +71,27 @@ public void close() {
7171
@Test
7272
@DirtiesContext
7373
public void testSimpleProperties() {
74-
then(this.service.getMessage()).isEqualTo("Hello scope!");
75-
then(this.service instanceof Advised).isTrue();
74+
then(service.getMessage()).isEqualTo("Hello scope!");
75+
then(service instanceof Advised).isTrue();
7676
// Change the dynamic property source...
77-
this.properties.setMessage("Foo");
77+
properties.setMessage("Foo");
7878
// ...but don't refresh, so the bean stays the same:
79-
then(this.service.getMessage()).isEqualTo("Hello scope!");
79+
then(service.getMessage()).isEqualTo("Hello scope!");
8080
then(ExampleService.getInitCount()).isEqualTo(0);
8181
then(ExampleService.getDestroyCount()).isEqualTo(0);
8282
}
8383

8484
@Test
8585
@DirtiesContext
8686
public void testRefresh() {
87-
then(this.service.getMessage()).isEqualTo("Hello scope!");
88-
String id1 = this.service.toString();
87+
then(service.getMessage()).isEqualTo("Hello scope!");
88+
String id1 = service.toString();
8989
// Change the dynamic property source...
90-
this.properties.setMessage("Foo");
90+
properties.setMessage("Foo");
9191
// ...and then refresh, so the bean is re-initialized:
92-
this.scope.refreshAll();
93-
String id2 = this.service.toString();
94-
then(this.service.getMessage()).isEqualTo("Foo");
92+
scope.refreshAll();
93+
String id2 = service.toString();
94+
then(service.getMessage()).isEqualTo("Foo");
9595
then(ExampleService.getInitCount()).isEqualTo(1);
9696
then(ExampleService.getDestroyCount()).isEqualTo(1);
9797
then(id2).isNotSameAs(id1);
@@ -102,15 +102,15 @@ public void testRefresh() {
102102
@Test
103103
@DirtiesContext
104104
public void testRefreshBean() {
105-
then(this.service.getMessage()).isEqualTo("Hello scope!");
106-
String id1 = this.service.toString();
105+
then(service.getMessage()).isEqualTo("Hello scope!");
106+
String id1 = service.toString();
107107
// Change the dynamic property source...
108-
this.properties.setMessage("Foo");
108+
properties.setMessage("Foo");
109109
// ...and then refresh, so the bean is re-initialized:
110-
this.scope.refresh("service");
111-
String id2 = this.service.toString();
112-
then(this.service.getMessage()).isEqualTo("Foo");
113-
then(this.service.getMessage()).isEqualTo("Foo");
110+
scope.refresh("service");
111+
String id2 = service.toString();
112+
then(service.getMessage()).isEqualTo("Foo");
113+
then(service.getMessage()).isEqualTo("Foo");
114114
then(ExampleService.getInitCount()).isEqualTo(1);
115115
then(ExampleService.getDestroyCount()).isEqualTo(1);
116116
then(id2).isNotSameAs(id1);
@@ -122,7 +122,7 @@ public void testRefreshBean() {
122122
@Test
123123
@DirtiesContext
124124
public void testCheckedException() {
125-
Assertions.assertThrows(ServiceException.class, () -> this.service.throwsException());
125+
assertThatExceptionOfType(ServiceException.class).isThrownBy(() -> service.throwsException());
126126
}
127127

128128
public interface Service {
@@ -168,28 +168,28 @@ public void setDelay(long delay) {
168168

169169
@Override
170170
public void afterPropertiesSet() {
171-
logger.debug("Initializing message: " + this.message);
171+
logger.debug("Initializing message: " + message);
172172
initCount++;
173173
}
174174

175175
@Override
176176
public void destroy() {
177-
logger.debug("Destroying message: " + this.message);
177+
logger.debug("Destroying message: " + message);
178178
destroyCount++;
179-
this.message = null;
179+
message = null;
180180
}
181181

182182
@Override
183183
public String getMessage() {
184-
logger.debug("Getting message: " + this.message);
184+
logger.debug("Getting message: " + message);
185185
try {
186-
Thread.sleep(this.delay);
186+
Thread.sleep(delay);
187187
}
188188
catch (InterruptedException e) {
189189
Thread.currentThread().interrupt();
190190
}
191-
logger.info("Returning message: " + this.message);
192-
return this.message;
191+
logger.info("Returning message: " + message);
192+
return message;
193193
}
194194

195195
public void setMessage(String message) {
@@ -226,8 +226,8 @@ protected static class TestConfiguration {
226226
@RefreshScope
227227
public ExampleService service() {
228228
ExampleService service = new ExampleService();
229-
service.setMessage(this.properties.getMessage());
230-
service.setDelay(this.properties.getDelay());
229+
service.setMessage(properties.getMessage());
230+
service.setDelay(properties.getDelay());
231231
return service;
232232
}
233233

@@ -243,7 +243,7 @@ protected static class TestProperties {
243243

244244
@ManagedAttribute
245245
public String getMessage() {
246-
return this.message;
246+
return message;
247247
}
248248

249249
public void setMessage(String message) {
@@ -252,7 +252,7 @@ public void setMessage(String message) {
252252

253253
@ManagedAttribute
254254
public int getDelay() {
255-
return this.delay;
255+
return delay;
256256
}
257257

258258
public void setDelay(int delay) {

0 commit comments

Comments
 (0)