Skip to content

Commit 7d68d06

Browse files
committed
Polishing
1 parent debe78b commit 7d68d06

24 files changed

+258
-272
lines changed

spring-test/src/main/java/org/springframework/test/util/XmlExpectationsHelper.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2018 the original author or authors.
2+
* Copyright 2002-2022 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.

spring-test/src/test/java/org/springframework/test/context/configuration/interfaces/BootstrapWithTestInterface.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2019 the original author or authors.
2+
* Copyright 2002-2022 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.

spring-test/src/test/java/org/springframework/test/context/configuration/interfaces/ContextConfigurationTestInterface.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2018 the original author or authors.
2+
* Copyright 2002-2022 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.

spring-test/src/test/java/org/springframework/test/context/configuration/interfaces/WebAppConfigurationTestInterface.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2018 the original author or authors.
2+
* Copyright 2002-2022 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.

spring-test/src/test/java/org/springframework/test/context/junit4/rules/ProgrammaticTxMgmtSpringRuleTests.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2019 the original author or authors.
2+
* Copyright 2002-2022 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.

spring-test/src/test/java/org/springframework/test/context/junit4/spr9051/AnnotatedConfigClassesWithoutAtConfigurationTests.java

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2019 the original author or authors.
2+
* Copyright 2002-2022 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.
@@ -16,8 +16,6 @@
1616

1717
package org.springframework.test.context.junit4.spr9051;
1818

19-
import java.util.Arrays;
20-
import java.util.HashSet;
2119
import java.util.Set;
2220
import java.util.concurrent.atomic.AtomicInteger;
2321

@@ -93,9 +91,8 @@ public void testSPR_9051() throws Exception {
9391
assertThat(enigma).isNotNull();
9492
assertThat(lifecycleBean).isNotNull();
9593
assertThat(lifecycleBean.isInitialized()).isTrue();
96-
Set<String> names = new HashSet<>();
97-
names.add(enigma);
98-
names.add(lifecycleBean.getName());
99-
assertThat(new HashSet<>(Arrays.asList("enigma #1", "enigma #2"))).isEqualTo(names);
94+
Set<String> names = Set.of(enigma, lifecycleBean.getName());
95+
assertThat(names).containsExactlyInAnyOrder("enigma #1", "enigma #2");
10096
}
97+
10198
}

spring-test/src/test/java/org/springframework/test/context/testng/transaction/programmatic/ProgrammaticTxMgmtTestNGTests.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2019 the original author or authors.
2+
* Copyright 2002-2022 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.

spring-test/src/test/java/org/springframework/test/context/transaction/programmatic/ProgrammaticTxMgmtTests.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2019 the original author or authors.
2+
* Copyright 2002-2022 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.

spring-test/src/test/java/org/springframework/test/web/client/MockRestServiceServerTests.java

Lines changed: 16 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2020 the original author or authors.
2+
* Copyright 2002-2022 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.
@@ -38,13 +38,13 @@
3838
*
3939
* @author Rossen Stoyanchev
4040
*/
41-
public class MockRestServiceServerTests {
41+
class MockRestServiceServerTests {
4242

4343
private final RestTemplate restTemplate = new RestTemplate();
4444

4545

4646
@Test
47-
public void buildMultipleTimes() {
47+
void buildMultipleTimes() {
4848
MockRestServiceServerBuilder builder = MockRestServiceServer.bindTo(this.restTemplate);
4949

5050
MockRestServiceServer server = builder.build();
@@ -66,7 +66,7 @@ public void buildMultipleTimes() {
6666
}
6767

6868
@Test
69-
public void exactExpectOrder() {
69+
void exactExpectOrder() {
7070
MockRestServiceServer server = MockRestServiceServer.bindTo(this.restTemplate)
7171
.ignoreExpectOrder(false).build();
7272

@@ -77,7 +77,7 @@ public void exactExpectOrder() {
7777
}
7878

7979
@Test
80-
public void ignoreExpectOrder() {
80+
void ignoreExpectOrder() {
8181
MockRestServiceServer server = MockRestServiceServer.bindTo(this.restTemplate)
8282
.ignoreExpectOrder(true).build();
8383

@@ -89,7 +89,7 @@ public void ignoreExpectOrder() {
8989
}
9090

9191
@Test
92-
public void resetAndReuseServer() {
92+
void resetAndReuseServer() {
9393
MockRestServiceServer server = MockRestServiceServer.bindTo(this.restTemplate).build();
9494

9595
server.expect(requestTo("/foo")).andRespond(withSuccess());
@@ -103,7 +103,7 @@ public void resetAndReuseServer() {
103103
}
104104

105105
@Test
106-
public void resetAndReuseServerWithUnorderedExpectationManager() {
106+
void resetAndReuseServerWithUnorderedExpectationManager() {
107107
MockRestServiceServer server = MockRestServiceServer.bindTo(this.restTemplate)
108108
.ignoreExpectOrder(true).build();
109109

@@ -120,7 +120,7 @@ public void resetAndReuseServerWithUnorderedExpectationManager() {
120120
}
121121

122122
@Test // gh-24486
123-
public void resetClearsRequestFailures() {
123+
void resetClearsRequestFailures() {
124124
MockRestServiceServer server = MockRestServiceServer.bindTo(this.restTemplate).build();
125125
server.expect(once(), requestTo("/remoteurl")).andRespond(withSuccess());
126126
this.restTemplate.postForEntity("/remoteurl", null, String.class);
@@ -138,7 +138,7 @@ public void resetClearsRequestFailures() {
138138
}
139139

140140
@Test // SPR-16132
141-
public void followUpRequestAfterFailure() {
141+
void followUpRequestAfterFailure() {
142142
MockRestServiceServer server = MockRestServiceServer.bindTo(this.restTemplate).build();
143143

144144
server.expect(requestTo("/some-service/some-endpoint"))
@@ -159,7 +159,7 @@ public void followUpRequestAfterFailure() {
159159
}
160160

161161
@Test // gh-21799
162-
public void verifyShouldFailIfRequestsFailed() {
162+
void verifyShouldFailIfRequestsFailed() {
163163
MockRestServiceServer server = MockRestServiceServer.bindTo(this.restTemplate).build();
164164
server.expect(once(), requestTo("/remoteurl")).andRespond(withSuccess());
165165

@@ -174,20 +174,19 @@ public void verifyShouldFailIfRequestsFailed() {
174174
}
175175

176176
@Test
177-
public void verifyWithTimeout() {
177+
void verifyWithTimeout() {
178178
MockRestServiceServerBuilder builder = MockRestServiceServer.bindTo(this.restTemplate);
179179

180180
MockRestServiceServer server1 = builder.build();
181181
server1.expect(requestTo("/foo")).andRespond(withSuccess());
182182
server1.expect(requestTo("/bar")).andRespond(withSuccess());
183183
this.restTemplate.getForObject("/foo", Void.class);
184184

185-
assertThatThrownBy(() -> server1.verify(Duration.ofMillis(100))).hasMessage(
186-
"""
187-
Further request(s) expected leaving 1 unsatisfied expectation(s).
188-
1 request(s) executed:
189-
GET /foo, headers: [Accept:"application/json, application/*+json"]
190-
""");
185+
assertThatThrownBy(() -> server1.verify(Duration.ofMillis(100))).hasMessage("""
186+
Further request(s) expected leaving 1 unsatisfied expectation(s).
187+
1 request(s) executed:
188+
GET /foo, headers: [Accept:"application/json, application/*+json"]
189+
""");
191190

192191
MockRestServiceServer server2 = builder.build();
193192
server2.expect(requestTo("/foo")).andRespond(withSuccess());

spring-test/src/test/java/org/springframework/test/web/client/SimpleRequestExpectationManagerTests.java

Lines changed: 28 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2019 the original author or authors.
2+
* Copyright 2002-2022 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.
@@ -26,7 +26,6 @@
2626
import org.springframework.http.client.ClientHttpRequest;
2727
import org.springframework.mock.http.client.MockClientHttpRequest;
2828

29-
import static org.assertj.core.api.Assertions.assertThat;
3029
import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
3130
import static org.springframework.http.HttpMethod.GET;
3231
import static org.springframework.http.HttpMethod.POST;
@@ -44,31 +43,28 @@
4443
*
4544
* @author Rossen Stoyanchev
4645
*/
47-
public class SimpleRequestExpectationManagerTests {
46+
class SimpleRequestExpectationManagerTests {
4847

4948
private final SimpleRequestExpectationManager manager = new SimpleRequestExpectationManager();
5049

5150

5251
@Test
53-
public void unexpectedRequest() throws Exception {
54-
try {
55-
this.manager.validateRequest(createRequest(GET, "/foo"));
56-
}
57-
catch (AssertionError error) {
58-
assertThat(error.getMessage()).isEqualTo(("""
52+
void unexpectedRequest() throws Exception {
53+
assertThatExceptionOfType(AssertionError.class)
54+
.isThrownBy(() -> this.manager.validateRequest(createRequest(GET, "/foo")))
55+
.withMessage("""
5956
No further requests expected: HTTP GET /foo
6057
0 request(s) executed.
61-
"""));
62-
}
58+
""");
6359
}
6460

6561
@Test
66-
public void zeroExpectedRequests() throws Exception {
62+
void zeroExpectedRequests() throws Exception {
6763
this.manager.verify();
6864
}
6965

7066
@Test
71-
public void sequentialRequests() throws Exception {
67+
void sequentialRequests() throws Exception {
7268
this.manager.expectRequest(once(), requestTo("/foo")).andExpect(method(GET)).andRespond(withSuccess());
7369
this.manager.expectRequest(once(), requestTo("/bar")).andExpect(method(GET)).andRespond(withSuccess());
7470

@@ -78,13 +74,13 @@ public void sequentialRequests() throws Exception {
7874
}
7975

8076
@Test
81-
public void sequentialRequestsTooMany() throws Exception {
77+
void sequentialRequestsTooMany() throws Exception {
8278
this.manager.expectRequest(max(1), requestTo("/foo")).andExpect(method(GET)).andRespond(withSuccess());
8379
this.manager.expectRequest(max(1), requestTo("/bar")).andExpect(method(GET)).andRespond(withSuccess());
8480
this.manager.validateRequest(createRequest(GET, "/foo"));
8581
this.manager.validateRequest(createRequest(GET, "/bar"));
86-
assertThatExceptionOfType(AssertionError.class).isThrownBy(() ->
87-
this.manager.validateRequest(createRequest(GET, "/baz")))
82+
assertThatExceptionOfType(AssertionError.class)
83+
.isThrownBy(() -> this.manager.validateRequest(createRequest(GET, "/baz")))
8884
.withMessage("""
8985
No further requests expected: HTTP GET /baz
9086
2 request(s) executed:
@@ -94,12 +90,12 @@ public void sequentialRequestsTooMany() throws Exception {
9490
}
9591

9692
@Test
97-
public void sequentialRequestsTooFew() throws Exception {
93+
void sequentialRequestsTooFew() throws Exception {
9894
this.manager.expectRequest(min(1), requestTo("/foo")).andExpect(method(GET)).andRespond(withSuccess());
9995
this.manager.expectRequest(min(1), requestTo("/bar")).andExpect(method(GET)).andRespond(withSuccess());
10096
this.manager.validateRequest(createRequest(GET, "/foo"));
101-
assertThatExceptionOfType(AssertionError.class).isThrownBy(() ->
102-
this.manager.verify())
97+
assertThatExceptionOfType(AssertionError.class)
98+
.isThrownBy(() -> this.manager.verify())
10399
.withMessage("""
104100
Further request(s) expected leaving 1 unsatisfied expectation(s).
105101
1 request(s) executed:
@@ -108,7 +104,7 @@ Further request(s) expected leaving 1 unsatisfied expectation(s).
108104
}
109105

110106
@Test
111-
public void repeatedRequests() throws Exception {
107+
void repeatedRequests() throws Exception {
112108
this.manager.expectRequest(times(3), requestTo("/foo")).andExpect(method(GET)).andRespond(withSuccess());
113109
this.manager.expectRequest(times(3), requestTo("/bar")).andExpect(method(GET)).andRespond(withSuccess());
114110

@@ -122,15 +118,15 @@ public void repeatedRequests() throws Exception {
122118
}
123119

124120
@Test
125-
public void repeatedRequestsTooMany() throws Exception {
121+
void repeatedRequestsTooMany() throws Exception {
126122
this.manager.expectRequest(max(2), requestTo("/foo")).andExpect(method(GET)).andRespond(withSuccess());
127123
this.manager.expectRequest(max(2), requestTo("/bar")).andExpect(method(GET)).andRespond(withSuccess());
128124
this.manager.validateRequest(createRequest(GET, "/foo"));
129125
this.manager.validateRequest(createRequest(GET, "/bar"));
130126
this.manager.validateRequest(createRequest(GET, "/foo"));
131127
this.manager.validateRequest(createRequest(GET, "/bar"));
132-
assertThatExceptionOfType(AssertionError.class).isThrownBy(() ->
133-
this.manager.validateRequest(createRequest(GET, "/foo")))
128+
assertThatExceptionOfType(AssertionError.class)
129+
.isThrownBy(() -> this.manager.validateRequest(createRequest(GET, "/foo")))
134130
.withMessage("""
135131
No further requests expected: HTTP GET /foo
136132
4 request(s) executed:
@@ -142,14 +138,14 @@ public void repeatedRequestsTooMany() throws Exception {
142138
}
143139

144140
@Test
145-
public void repeatedRequestsTooFew() throws Exception {
141+
void repeatedRequestsTooFew() throws Exception {
146142
this.manager.expectRequest(min(2), requestTo("/foo")).andExpect(method(GET)).andRespond(withSuccess());
147143
this.manager.expectRequest(min(2), requestTo("/bar")).andExpect(method(GET)).andRespond(withSuccess());
148144
this.manager.validateRequest(createRequest(GET, "/foo"));
149145
this.manager.validateRequest(createRequest(GET, "/bar"));
150146
this.manager.validateRequest(createRequest(GET, "/foo"));
151-
assertThatExceptionOfType(AssertionError.class).isThrownBy(() ->
152-
this.manager.verify())
147+
assertThatExceptionOfType(AssertionError.class)
148+
.isThrownBy(() -> this.manager.verify())
153149
.withMessageContaining("""
154150
3 request(s) executed:
155151
GET /foo
@@ -159,17 +155,17 @@ public void repeatedRequestsTooFew() throws Exception {
159155
}
160156

161157
@Test
162-
public void repeatedRequestsNotInOrder() throws Exception {
158+
void repeatedRequestsNotInOrder() throws Exception {
163159
this.manager.expectRequest(twice(), requestTo("/foo")).andExpect(method(GET)).andRespond(withSuccess());
164160
this.manager.expectRequest(twice(), requestTo("/bar")).andExpect(method(GET)).andRespond(withSuccess());
165161
this.manager.expectRequest(twice(), requestTo("/baz")).andExpect(method(GET)).andRespond(withSuccess());
166-
assertThatExceptionOfType(AssertionError.class).isThrownBy(() ->
167-
this.manager.validateRequest(createRequest(POST, "/foo")))
162+
assertThatExceptionOfType(AssertionError.class)
163+
.isThrownBy(() -> this.manager.validateRequest(createRequest(POST, "/foo")))
168164
.withMessage("Unexpected HttpMethod expected:<GET> but was:<POST>");
169165
}
170166

171167
@Test // SPR-15672
172-
public void sequentialRequestsWithDifferentCount() throws Exception {
168+
void sequentialRequestsWithDifferentCount() throws Exception {
173169
this.manager.expectRequest(times(2), requestTo("/foo")).andExpect(method(GET)).andRespond(withSuccess());
174170
this.manager.expectRequest(once(), requestTo("/bar")).andExpect(method(GET)).andRespond(withSuccess());
175171

@@ -179,7 +175,7 @@ public void sequentialRequestsWithDifferentCount() throws Exception {
179175
}
180176

181177
@Test // SPR-15719
182-
public void repeatedRequestsInSequentialOrder() throws Exception {
178+
void repeatedRequestsInSequentialOrder() throws Exception {
183179
this.manager.expectRequest(times(2), requestTo("/foo")).andExpect(method(GET)).andRespond(withSuccess());
184180
this.manager.expectRequest(times(2), requestTo("/bar")).andExpect(method(GET)).andRespond(withSuccess());
185181

@@ -190,7 +186,7 @@ public void repeatedRequestsInSequentialOrder() throws Exception {
190186
}
191187

192188
@Test // SPR-16132
193-
public void sequentialRequestsWithFirstFailing() throws Exception {
189+
void sequentialRequestsWithFirstFailing() throws Exception {
194190
this.manager.expectRequest(once(), requestTo("/foo")).
195191
andExpect(method(GET)).andRespond(request -> { throw new SocketException("pseudo network error"); });
196192
this.manager.expectRequest(once(), requestTo("/handle-error")).

0 commit comments

Comments
 (0)