Skip to content

Commit a3e7fd4

Browse files
committed
Allow MockHttpServletRequestBuilder to support AssertJ
This commit moves the features of MockHttpServletRequestBuilder in an abstract class so that another class can offer the same feature whilst providing AssertJ support. This wasn't possible previously as the builder's return type would lose the concrete builder types. This change benefits MockMultipartHttpServletRequestBuilder that can use the same mechanism to offer additional settings. This change also makes it so that a builder instance can be created using only the HttpMethod. Previously, the URI had to be provided as well and that makes it impossible to specify it using the builder. See gh-32913
1 parent 726ac91 commit a3e7fd4

File tree

5 files changed

+964
-889
lines changed

5 files changed

+964
-889
lines changed

spring-test/src/main/java/org/springframework/test/web/servlet/client/MockMvcHttpConnector.java

+3-2
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@
5454
import org.springframework.test.web.servlet.MockMvc;
5555
import org.springframework.test.web.servlet.MvcResult;
5656
import org.springframework.test.web.servlet.RequestBuilder;
57+
import org.springframework.test.web.servlet.request.AbstractMockHttpServletRequestBuilder;
5758
import org.springframework.test.web.servlet.request.MockHttpServletRequestBuilder;
5859
import org.springframework.test.web.servlet.request.MockMultipartHttpServletRequestBuilder;
5960
import org.springframework.test.web.servlet.request.MockMvcRequestBuilders;
@@ -134,7 +135,7 @@ private RequestBuilder adaptRequest(
134135
// Initialize the client request
135136
requestCallback.apply(httpRequest).block(TIMEOUT);
136137

137-
MockHttpServletRequestBuilder requestBuilder =
138+
AbstractMockHttpServletRequestBuilder<?> requestBuilder =
138139
initRequestBuilder(httpMethod, uri, httpRequest, contentRef.get());
139140

140141
requestBuilder.headers(httpRequest.getHeaders());
@@ -149,7 +150,7 @@ private RequestBuilder adaptRequest(
149150
return requestBuilder;
150151
}
151152

152-
private MockHttpServletRequestBuilder initRequestBuilder(
153+
private AbstractMockHttpServletRequestBuilder<?> initRequestBuilder(
153154
HttpMethod httpMethod, URI uri, MockClientHttpRequest httpRequest, @Nullable byte[] bytes) {
154155

155156
String contentType = httpRequest.getHeaders().getFirst(HttpHeaders.CONTENT_TYPE);

0 commit comments

Comments
 (0)