Skip to content

Commit 4fb5b87

Browse files
committed
Merge pull request #955 from snicoll
* gh-955: Polish "Raise the minimum support version of Spring Framework to 7.0" Raise the minimum support version of Spring Framework to 7.0 Closes gh-955
2 parents db16f27 + 34c9366 commit 4fb5b87

File tree

24 files changed

+100
-114
lines changed

24 files changed

+100
-114
lines changed

docs/src/docs/asciidoc/documenting-your-api.adoc

-2
Original file line numberDiff line numberDiff line change
@@ -802,8 +802,6 @@ Uses the static `parameterWithName` method on `org.springframework.restdocs.requ
802802

803803
The result is a snippet named `path-parameters.adoc` that contains a table describing the path parameters that are supported by the resource.
804804

805-
TIP: If you use MockMvc with Spring Framework 6.1 or earlier, to make the path parameters available for documentation, you must build the request by using one of the methods on `RestDocumentationRequestBuilders` rather than `MockMvcRequestBuilders`.
806-
807805
When documenting path parameters, the test fails if an undocumented path parameter is used in the request.
808806
Similarly, the test also fails if a documented path parameter is not found in the request and the path parameter has not been marked as optional.
809807

docs/src/docs/asciidoc/getting-started.adoc

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ If you want to jump straight in, a number of https://github.com/spring-projects/
1818
Spring REST Docs has the following minimum requirements:
1919

2020
* Java 17
21-
* Spring Framework 6
21+
* Spring Framework 7
2222

2323
Additionally, the `spring-restdocs-restassured` module requires REST Assured 5.2.
2424

gradle.properties

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,4 @@ org.gradle.parallel=true
66

77
javaFormatVersion=0.0.43
88
jmustacheVersion=1.15
9-
springFrameworkVersion=6.1.13
9+
springFrameworkVersion=7.0.0-M1

spring-restdocs-core/build.gradle

-7
Original file line numberDiff line numberDiff line change
@@ -82,10 +82,3 @@ components.java.withVariantsFromConfiguration(configurations.testFixturesApiElem
8282
components.java.withVariantsFromConfiguration(configurations.testFixturesRuntimeElements) {
8383
skip()
8484
}
85-
86-
compatibilityTest {
87-
dependency("Spring Framework") { springFramework ->
88-
springFramework.groupId = "org.springframework"
89-
springFramework.versions = ["6.0.+", "6.2.+"]
90-
}
91-
}

spring-restdocs-core/src/main/java/org/springframework/restdocs/cli/CliOperationRequest.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2014-2023 the original author or authors.
2+
* Copyright 2014-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.
@@ -76,7 +76,7 @@ public String getContentAsString() {
7676
@Override
7777
public HttpHeaders getHeaders() {
7878
HttpHeaders filteredHeaders = new HttpHeaders();
79-
for (Entry<String, List<String>> header : this.delegate.getHeaders().entrySet()) {
79+
for (Entry<String, List<String>> header : this.delegate.getHeaders().headerSet()) {
8080
if (allowedHeader(header)) {
8181
filteredHeaders.put(header.getKey(), header.getValue());
8282
}

spring-restdocs-core/src/main/java/org/springframework/restdocs/cli/CurlRequestSnippet.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2014-2022 the original author or authors.
2+
* Copyright 2014-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.
@@ -132,7 +132,7 @@ private void writeHttpMethod(OperationRequest request, StringBuilder builder) {
132132
}
133133

134134
private void writeHeaders(CliOperationRequest request, List<String> lines) {
135-
for (Entry<String, List<String>> entry : request.getHeaders().entrySet()) {
135+
for (Entry<String, List<String>> entry : request.getHeaders().headerSet()) {
136136
for (String header : entry.getValue()) {
137137
if (StringUtils.hasText(request.getContentAsString()) && HttpHeaders.CONTENT_TYPE.equals(entry.getKey())
138138
&& MediaType.APPLICATION_FORM_URLENCODED.equals(request.getHeaders().getContentType())) {

spring-restdocs-core/src/main/java/org/springframework/restdocs/cli/HttpieRequestSnippet.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2014-2023 the original author or authors.
2+
* Copyright 2014-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.
@@ -160,7 +160,7 @@ private void writeFormDataIfNecessary(OperationRequest request, List<String> lin
160160

161161
private void writeHeaders(OperationRequest request, List<String> lines) {
162162
HttpHeaders headers = request.getHeaders();
163-
for (Entry<String, List<String>> entry : headers.entrySet()) {
163+
for (Entry<String, List<String>> entry : headers.headerSet()) {
164164
if (entry.getKey().equals(HttpHeaders.CONTENT_TYPE)
165165
&& headers.getContentType().isCompatibleWith(MediaType.APPLICATION_FORM_URLENCODED)) {
166166
continue;

spring-restdocs-core/src/main/java/org/springframework/restdocs/headers/RequestHeadersSnippet.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2014-2019 the original author or authors.
2+
* Copyright 2014-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.
@@ -57,7 +57,7 @@ protected RequestHeadersSnippet(List<HeaderDescriptor> descriptors, Map<String,
5757

5858
@Override
5959
protected Set<String> extractActualHeaders(Operation operation) {
60-
return operation.getRequest().getHeaders().keySet();
60+
return operation.getRequest().getHeaders().headerNames();
6161
}
6262

6363
/**

spring-restdocs-core/src/main/java/org/springframework/restdocs/headers/ResponseHeadersSnippet.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2014-2019 the original author or authors.
2+
* Copyright 2014-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.
@@ -57,7 +57,7 @@ protected ResponseHeadersSnippet(List<HeaderDescriptor> descriptors, Map<String,
5757

5858
@Override
5959
protected Set<String> extractActualHeaders(Operation operation) {
60-
return operation.getResponse().getHeaders().keySet();
60+
return operation.getResponse().getHeaders().headerNames();
6161
}
6262

6363
/**

spring-restdocs-core/src/main/java/org/springframework/restdocs/http/HttpRequestSnippet.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2014-2024 the original author or authors.
2+
* Copyright 2014-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.
@@ -91,7 +91,7 @@ private boolean includeParametersInUri(OperationRequest request) {
9191
private List<Map<String, String>> getHeaders(OperationRequest request) {
9292
List<Map<String, String>> headers = new ArrayList<>();
9393

94-
for (Entry<String, List<String>> header : request.getHeaders().entrySet()) {
94+
for (Entry<String, List<String>> header : request.getHeaders().headerSet()) {
9595
for (String value : header.getValue()) {
9696
if (HttpHeaders.CONTENT_TYPE.equals(header.getKey()) && !request.getParts().isEmpty()) {
9797
headers.add(header(header.getKey(), String.format("%s; boundary=%s", value, MULTIPART_BOUNDARY)));

spring-restdocs-core/src/main/java/org/springframework/restdocs/http/HttpResponseSnippet.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2014-2022 the original author or authors.
2+
* Copyright 2014-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.
@@ -73,7 +73,7 @@ private String responseBody(OperationResponse response) {
7373

7474
private List<Map<String, String>> headers(OperationResponse response) {
7575
List<Map<String, String>> headers = new ArrayList<>();
76-
for (Entry<String, List<String>> header : response.getHeaders().entrySet()) {
76+
for (Entry<String, List<String>> header : response.getHeaders().headerSet()) {
7777
List<String> values = header.getValue();
7878
for (String value : values) {
7979
headers.add(header(header.getKey(), value));

spring-restdocs-core/src/main/java/org/springframework/restdocs/operation/preprocess/HeadersModifyingOperationPreprocessor.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2014-2023 the original author or authors.
2+
* Copyright 2014-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.
@@ -210,7 +210,7 @@ private RemoveHeadersByNamePatternModification(Pattern namePattern) {
210210

211211
@Override
212212
public void applyTo(HttpHeaders headers) {
213-
headers.keySet().removeIf((name) -> this.namePattern.matcher(name).matches());
213+
headers.headerNames().removeIf((name) -> this.namePattern.matcher(name).matches());
214214
}
215215

216216
}

spring-restdocs-core/src/main/java/org/springframework/restdocs/operation/preprocess/UriModifyingOperationPreprocessor.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2014-2023 the original author or authors.
2+
* Copyright 2014-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.
@@ -147,7 +147,7 @@ public OperationResponse preprocess(OperationResponse response) {
147147

148148
private HttpHeaders modify(HttpHeaders headers) {
149149
HttpHeaders modified = new HttpHeaders();
150-
for (Entry<String, List<String>> header : headers.entrySet()) {
150+
for (Entry<String, List<String>> header : headers.headerSet()) {
151151
for (String value : header.getValue()) {
152152
modified.add(header.getKey(), this.contentModifier.modify(value));
153153
}

spring-restdocs-core/src/test/java/org/springframework/restdocs/config/RestDocumentationConfigurerTests.java

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2014-2023 the original author or authors.
2+
* Copyright 2014-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.
@@ -210,7 +210,7 @@ public void customDefaultOperationRequestPreprocessor() {
210210
headers.add("Foo", "value");
211211
OperationRequest request = new OperationRequestFactory().create(URI.create("http://localhost:8080"),
212212
HttpMethod.GET, null, headers, null, Collections.emptyList());
213-
assertThat(preprocessor.preprocess(request).getHeaders()).doesNotContainKey("Foo");
213+
assertThat(preprocessor.preprocess(request).getHeaders().headerNames()).doesNotContain("Foo");
214214
}
215215

216216
@Test
@@ -224,7 +224,7 @@ public void customDefaultOperationResponsePreprocessor() {
224224
HttpHeaders headers = new HttpHeaders();
225225
headers.add("Foo", "value");
226226
OperationResponse response = new OperationResponseFactory().create(HttpStatus.OK, headers, null);
227-
assertThat(preprocessor.preprocess(response).getHeaders()).doesNotContainKey("Foo");
227+
assertThat(preprocessor.preprocess(response).getHeaders().headerNames()).doesNotContain("Foo");
228228
}
229229

230230
private RestDocumentationContext createContext() {

spring-restdocs-core/src/test/java/org/springframework/restdocs/operation/preprocess/HeadersModifyingOperationPreprocessorTests.java

+47-36
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2014-2023 the original author or authors.
2+
* Copyright 2014-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.
@@ -33,6 +33,7 @@
3333
import org.springframework.restdocs.operation.OperationResponseFactory;
3434

3535
import static org.assertj.core.api.Assertions.assertThat;
36+
import static org.assertj.core.api.Assertions.entry;
3637

3738
/**
3839
* Tests for {@link HeadersModifyingOperationPreprocessor}.
@@ -47,81 +48,91 @@ public class HeadersModifyingOperationPreprocessorTests {
4748
@Test
4849
public void addNewHeader() {
4950
this.preprocessor.add("a", "alpha");
50-
assertThat(this.preprocessor.preprocess(createRequest()).getHeaders()).containsEntry("a",
51-
Arrays.asList("alpha"));
52-
assertThat(this.preprocessor.preprocess(createResponse()).getHeaders()).containsEntry("a",
53-
Arrays.asList("alpha"));
51+
assertThat(this.preprocessor.preprocess(createRequest()).getHeaders().get("a"))
52+
.isEqualTo(Arrays.asList("alpha"));
53+
assertThat(this.preprocessor.preprocess(createResponse()).getHeaders().get("a"))
54+
.isEqualTo(Arrays.asList("alpha"));
5455
}
5556

5657
@Test
5758
public void addValueToExistingHeader() {
5859
this.preprocessor.add("a", "alpha");
59-
assertThat(this.preprocessor.preprocess(createRequest((headers) -> headers.add("a", "apple"))).getHeaders())
60-
.containsEntry("a", Arrays.asList("apple", "alpha"));
61-
assertThat(this.preprocessor.preprocess(createResponse((headers) -> headers.add("a", "apple"))).getHeaders())
62-
.containsEntry("a", Arrays.asList("apple", "alpha"));
60+
assertThat(this.preprocessor.preprocess(createRequest((headers) -> headers.add("a", "apple")))
61+
.getHeaders()
62+
.headerSet()).contains(entry("a", Arrays.asList("apple", "alpha")));
63+
assertThat(this.preprocessor.preprocess(createResponse((headers) -> headers.add("a", "apple")))
64+
.getHeaders()
65+
.headerSet()).contains(entry("a", Arrays.asList("apple", "alpha")));
6366
}
6467

6568
@Test
6669
public void setNewHeader() {
6770
this.preprocessor.set("a", "alpha", "avocado");
68-
assertThat(this.preprocessor.preprocess(createRequest()).getHeaders()).containsEntry("a",
69-
Arrays.asList("alpha", "avocado"));
70-
assertThat(this.preprocessor.preprocess(createResponse()).getHeaders()).containsEntry("a",
71-
Arrays.asList("alpha", "avocado"));
71+
assertThat(this.preprocessor.preprocess(createRequest()).getHeaders().headerSet())
72+
.contains(entry("a", Arrays.asList("alpha", "avocado")));
73+
assertThat(this.preprocessor.preprocess(createResponse()).getHeaders().headerSet())
74+
.contains(entry("a", Arrays.asList("alpha", "avocado")));
7275
}
7376

7477
@Test
7578
public void setExistingHeader() {
7679
this.preprocessor.set("a", "alpha", "avocado");
77-
assertThat(this.preprocessor.preprocess(createRequest((headers) -> headers.add("a", "apple"))).getHeaders())
78-
.containsEntry("a", Arrays.asList("alpha", "avocado"));
79-
assertThat(this.preprocessor.preprocess(createResponse((headers) -> headers.add("a", "apple"))).getHeaders())
80-
.containsEntry("a", Arrays.asList("alpha", "avocado"));
80+
assertThat(this.preprocessor.preprocess(createRequest((headers) -> headers.add("a", "apple")))
81+
.getHeaders()
82+
.headerSet()).contains(entry("a", Arrays.asList("alpha", "avocado")));
83+
assertThat(this.preprocessor.preprocess(createResponse((headers) -> headers.add("a", "apple")))
84+
.getHeaders()
85+
.headerSet()).contains(entry("a", Arrays.asList("alpha", "avocado")));
8186
}
8287

8388
@Test
8489
public void removeNonExistentHeader() {
8590
this.preprocessor.remove("a");
86-
assertThat(this.preprocessor.preprocess(createRequest()).getHeaders()).doesNotContainKey("a");
87-
assertThat(this.preprocessor.preprocess(createResponse()).getHeaders()).doesNotContainKey("a");
91+
assertThat(this.preprocessor.preprocess(createRequest()).getHeaders().headerNames()).doesNotContain("a");
92+
assertThat(this.preprocessor.preprocess(createResponse()).getHeaders().headerNames()).doesNotContain("a");
8893
}
8994

9095
@Test
9196
public void removeHeader() {
9297
this.preprocessor.remove("a");
93-
assertThat(this.preprocessor.preprocess(createRequest((headers) -> headers.add("a", "apple"))).getHeaders())
94-
.doesNotContainKey("a");
95-
assertThat(this.preprocessor.preprocess(createResponse((headers) -> headers.add("a", "apple"))).getHeaders())
96-
.doesNotContainKey("a");
98+
assertThat(this.preprocessor.preprocess(createRequest((headers) -> headers.add("a", "apple")))
99+
.getHeaders()
100+
.headerNames()).doesNotContain("a");
101+
assertThat(this.preprocessor.preprocess(createResponse((headers) -> headers.add("a", "apple")))
102+
.getHeaders()
103+
.headerNames()).doesNotContain("a");
97104
}
98105

99106
@Test
100107
public void removeHeaderValueForNonExistentHeader() {
101108
this.preprocessor.remove("a", "apple");
102-
assertThat(this.preprocessor.preprocess(createRequest()).getHeaders()).doesNotContainKey("a");
103-
assertThat(this.preprocessor.preprocess(createResponse()).getHeaders()).doesNotContainKey("a");
109+
assertThat(this.preprocessor.preprocess(createRequest()).getHeaders().headerNames()).doesNotContain("a");
110+
assertThat(this.preprocessor.preprocess(createResponse()).getHeaders().headerNames()).doesNotContain("a");
104111
}
105112

106113
@Test
107114
public void removeHeaderValueWithMultipleValues() {
108115
this.preprocessor.remove("a", "apple");
109116
assertThat(
110117
this.preprocessor.preprocess(createRequest((headers) -> headers.addAll("a", List.of("apple", "alpha"))))
111-
.getHeaders())
112-
.containsEntry("a", Arrays.asList("alpha"));
118+
.getHeaders()
119+
.headerSet())
120+
.contains(entry("a", Arrays.asList("alpha")));
113121
assertThat(this.preprocessor
114122
.preprocess(createResponse((headers) -> headers.addAll("a", List.of("apple", "alpha"))))
115-
.getHeaders()).containsEntry("a", Arrays.asList("alpha"));
123+
.getHeaders()
124+
.headerSet()).contains(entry("a", Arrays.asList("alpha")));
116125
}
117126

118127
@Test
119128
public void removeHeaderValueWithSingleValueRemovesEntryEntirely() {
120129
this.preprocessor.remove("a", "apple");
121-
assertThat(this.preprocessor.preprocess(createRequest((headers) -> headers.add("a", "apple"))).getHeaders())
122-
.doesNotContainKey("a");
123-
assertThat(this.preprocessor.preprocess(createResponse((headers) -> headers.add("a", "apple"))).getHeaders())
124-
.doesNotContainKey("a");
130+
assertThat(this.preprocessor.preprocess(createRequest((headers) -> headers.add("a", "apple")))
131+
.getHeaders()
132+
.headerNames()).doesNotContain("a");
133+
assertThat(this.preprocessor.preprocess(createResponse((headers) -> headers.add("a", "apple")))
134+
.getHeaders()
135+
.headerNames()).doesNotContain("a");
125136
}
126137

127138
@Test
@@ -133,10 +144,10 @@ public void removeHeadersByNamePattern() {
133144
headers.add("bravo", "bravo");
134145
};
135146
this.preprocessor.removeMatching("^a.*");
136-
assertThat(this.preprocessor.preprocess(createRequest(headersCustomizer)).getHeaders()).containsOnlyKeys("Host",
137-
"bravo");
138-
assertThat(this.preprocessor.preprocess(createResponse(headersCustomizer)).getHeaders())
139-
.containsOnlyKeys("bravo");
147+
assertThat(this.preprocessor.preprocess(createRequest(headersCustomizer)).getHeaders().headerNames())
148+
.containsOnly("Host", "bravo");
149+
assertThat(this.preprocessor.preprocess(createResponse(headersCustomizer)).getHeaders().headerNames())
150+
.containsOnly("bravo");
140151
}
141152

142153
private OperationRequest createRequest() {

spring-restdocs-mockmvc/build.gradle

-7
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,3 @@ dependencies {
2222
testImplementation("org.hamcrest:hamcrest-library")
2323
testImplementation("org.mockito:mockito-core")
2424
}
25-
26-
compatibilityTest {
27-
dependency("Spring Framework") { springFramework ->
28-
springFramework.groupId = "org.springframework"
29-
springFramework.versions = ["6.0.+", "6.2.+"]
30-
}
31-
}

spring-restdocs-mockmvc/src/main/java/org/springframework/restdocs/mockmvc/MockMvcResponseConverter.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2014-2022 the original author or authors.
2+
* Copyright 2014-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.
@@ -68,7 +68,7 @@ private HttpHeaders extractHeaders(MockHttpServletResponse response) {
6868
}
6969
}
7070

71-
if (response.getCookies() != null && !headers.containsKey(HttpHeaders.SET_COOKIE)) {
71+
if (response.getCookies() != null && !headers.containsHeader(HttpHeaders.SET_COOKIE)) {
7272
for (Cookie cookie : response.getCookies()) {
7373
headers.add(HttpHeaders.SET_COOKIE, generateSetCookieHeader(cookie));
7474
}

0 commit comments

Comments
 (0)