From 2730d77f828644b570eb558e917217ecf0d9e12c Mon Sep 17 00:00:00 2001 From: Brian Clozel Date: Thu, 20 Aug 2026 14:13:22 +0200 Subject: [PATCH] Polishing contribution Closes gh-34993 --- .../request/MockHttpServletRequestBuilderTests.java | 11 +++-------- .../java/org/springframework/http/HttpHeaders.java | 11 +++++------ .../web/HttpMediaTypeNotSupportedException.java | 2 +- .../server/UnsupportedMediaTypeStatusException.java | 2 +- .../testfixture/method/MvcAnnotationPredicates.java | 5 ----- 5 files changed, 10 insertions(+), 21 deletions(-) diff --git a/spring-test/src/test/java/org/springframework/test/web/servlet/request/MockHttpServletRequestBuilderTests.java b/spring-test/src/test/java/org/springframework/test/web/servlet/request/MockHttpServletRequestBuilderTests.java index aef9db9753b..3a20b9efb17 100644 --- a/spring-test/src/test/java/org/springframework/test/web/servlet/request/MockHttpServletRequestBuilderTests.java +++ b/spring-test/src/test/java/org/springframework/test/web/servlet/request/MockHttpServletRequestBuilderTests.java @@ -31,8 +31,6 @@ import jakarta.servlet.ServletContext; import jakarta.servlet.http.Cookie; import org.assertj.core.api.ThrowingConsumer; import org.junit.jupiter.api.Test; -import org.junit.jupiter.params.ParameterizedTest; -import org.junit.jupiter.params.provider.ValueSource; import org.springframework.http.HttpHeaders; import org.springframework.http.HttpMethod; @@ -420,21 +418,18 @@ class MockHttpServletRequestBuilderTests { assertThat(request.getParameterMap().get("foo")).containsExactly("bar", "baz"); } - @ValueSource(strings = {"POST", "QUERY"}) - @ParameterizedTest() - void requestParameterFromRequestBodyFormData(String methodName) { + @Test + void requestParameterFromRequestBodyFormData() { String contentType = "application/x-www-form-urlencoded;charset=UTF-8"; String body = "name+1=value+1&name+2=value+A&name+2=value+B&name+3"; - HttpMethod method = HttpMethod.valueOf(methodName); - MockHttpServletRequest request = new MockHttpServletRequestBuilder(method).uri("/foo") + MockHttpServletRequest request = new MockHttpServletRequestBuilder(POST).uri("/foo") .contentType(contentType).content(body.getBytes(UTF_8)) .buildRequest(this.servletContext); assertThat(request.getParameterMap().get("name 1")).containsExactly("value 1"); assertThat(request.getParameterMap().get("name 2")).containsExactly("value A", "value B"); assertThat(request.getParameterMap().get("name 3")).containsExactly((String) null); - } @Test diff --git a/spring-web/src/main/java/org/springframework/http/HttpHeaders.java b/spring-web/src/main/java/org/springframework/http/HttpHeaders.java index 969bbf85d57..bcedd663b45 100644 --- a/spring-web/src/main/java/org/springframework/http/HttpHeaders.java +++ b/spring-web/src/main/java/org/springframework/http/HttpHeaders.java @@ -124,18 +124,17 @@ public class HttpHeaders implements Serializable { * @see Section 3.1 of RFC 5789 */ public static final String ACCEPT_PATCH = "Accept-Patch"; - /** - * The HTTP {@code Accept-Ranges} header field name. - * @see Section 5.3.5 of RFC 7233 - */ - public static final String ACCEPT_RANGES = "Accept-Ranges"; - /** * The HTTP {@code Accept-Query} header field name. * @since 7.1 * @see Section 3 of RFC 10008 */ public static final String ACCEPT_QUERY = "Accept-Query"; + /** + * The HTTP {@code Accept-Ranges} header field name. + * @see Section 5.3.5 of RFC 7233 + */ + public static final String ACCEPT_RANGES = "Accept-Ranges"; /** * The CORS {@code Access-Control-Allow-Credentials} response header field name. * @see CORS W3C recommendation diff --git a/spring-web/src/main/java/org/springframework/web/HttpMediaTypeNotSupportedException.java b/spring-web/src/main/java/org/springframework/web/HttpMediaTypeNotSupportedException.java index 03fa71c85e2..52991fce189 100644 --- a/spring-web/src/main/java/org/springframework/web/HttpMediaTypeNotSupportedException.java +++ b/spring-web/src/main/java/org/springframework/web/HttpMediaTypeNotSupportedException.java @@ -132,7 +132,7 @@ public class HttpMediaTypeNotSupportedException extends HttpMediaTypeException { if (HttpMethod.PATCH.equals(this.httpMethod)) { headers.setAcceptPatch(getSupportedMediaTypes()); } - if (HttpMethod.QUERY.equals(this.httpMethod)) { + else if (HttpMethod.QUERY.equals(this.httpMethod)) { headers.setAcceptQuery(getSupportedMediaTypes()); } return headers; diff --git a/spring-web/src/main/java/org/springframework/web/server/UnsupportedMediaTypeStatusException.java b/spring-web/src/main/java/org/springframework/web/server/UnsupportedMediaTypeStatusException.java index 62cb851198f..6b5124e7645 100644 --- a/spring-web/src/main/java/org/springframework/web/server/UnsupportedMediaTypeStatusException.java +++ b/spring-web/src/main/java/org/springframework/web/server/UnsupportedMediaTypeStatusException.java @@ -161,7 +161,7 @@ public class UnsupportedMediaTypeStatusException extends ResponseStatusException if (this.method == HttpMethod.PATCH) { headers.setAcceptPatch(this.supportedMediaTypes); } - if (this.method == HttpMethod.QUERY) { + else if (this.method == HttpMethod.QUERY) { headers.setAcceptQuery(this.supportedMediaTypes); } return headers; diff --git a/spring-web/src/testFixtures/java/org/springframework/web/testfixture/method/MvcAnnotationPredicates.java b/spring-web/src/testFixtures/java/org/springframework/web/testfixture/method/MvcAnnotationPredicates.java index d8043e46386..83ce9de8bb1 100644 --- a/spring-web/src/testFixtures/java/org/springframework/web/testfixture/method/MvcAnnotationPredicates.java +++ b/spring-web/src/testFixtures/java/org/springframework/web/testfixture/method/MvcAnnotationPredicates.java @@ -113,11 +113,6 @@ public class MvcAnnotationPredicates { return new RequestMappingPredicate(path).method(RequestMethod.HEAD); } - public static RequestMappingPredicate queryMapping(String... path) { - return new RequestMappingPredicate(path).method(RequestMethod.QUERY); - } - - public static class ModelAttributePredicate implements Predicate {