Skip to content

Commit 9bda734

Browse files
committed
Improve method order in MockMvcRequestBuilders
1 parent 0b69a0b commit 9bda734

File tree

3 files changed

+74
-76
lines changed

3 files changed

+74
-76
lines changed

spring-test/src/main/java/org/springframework/test/web/servlet/request/MockHttpServletRequestBuilder.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -133,14 +133,14 @@ public class MockHttpServletRequestBuilder implements RequestBuilder, Mergeable
133133
* the {@code MockHttpServletRequest} can be plugged in via
134134
* {@link #with(RequestPostProcessor)}.
135135
* @param httpMethod the HTTP method (GET, POST, etc)
136-
* @param url the URL
136+
* @param uri the URL
137137
* @since 4.0.3
138138
*/
139-
MockHttpServletRequestBuilder(HttpMethod httpMethod, URI url) {
139+
MockHttpServletRequestBuilder(HttpMethod httpMethod, URI uri) {
140140
Assert.notNull(httpMethod, "httpMethod is required");
141-
Assert.notNull(url, "url is required");
141+
Assert.notNull(uri, "uri is required");
142142
this.method = httpMethod;
143-
this.uriComponents = UriComponentsBuilder.fromUri(url).build();
143+
this.uriComponents = UriComponentsBuilder.fromUri(uri).build();
144144
}
145145

146146
/**

spring-test/src/main/java/org/springframework/test/web/servlet/request/MockMultipartHttpServletRequestBuilder.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2013 the original author or authors.
2+
* Copyright 2002-2014 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.
@@ -59,11 +59,11 @@ public class MockMultipartHttpServletRequestBuilder extends MockHttpServletReque
5959
* <p>For other ways to initialize a {@code MockMultipartHttpServletRequest},
6060
* see {@link #with(RequestPostProcessor)} and the
6161
* {@link RequestPostProcessor} extension point.
62-
* @param url the URL
62+
* @param uri the URL
6363
* @since 4.0.3
6464
*/
65-
MockMultipartHttpServletRequestBuilder(URI url) {
66-
super(HttpMethod.POST, url);
65+
MockMultipartHttpServletRequestBuilder(URI uri) {
66+
super(HttpMethod.POST, uri);
6767
super.contentType(MediaType.MULTIPART_FORM_DATA);
6868
}
6969

spring-test/src/main/java/org/springframework/test/web/servlet/request/MockMvcRequestBuilders.java

Lines changed: 66 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,15 @@ public static MockHttpServletRequestBuilder get(String urlTemplate, Object... ur
4747
return new MockHttpServletRequestBuilder(HttpMethod.GET, urlTemplate, urlVariables);
4848
}
4949

50+
/**
51+
* Create a {@link MockHttpServletRequestBuilder} for a GET request.
52+
* @param uri the URL
53+
* @since 4.0.3
54+
*/
55+
public static MockHttpServletRequestBuilder get(URI uri) {
56+
return new MockHttpServletRequestBuilder(HttpMethod.GET, uri);
57+
}
58+
5059
/**
5160
* Create a {@link MockHttpServletRequestBuilder} for a POST request.
5261
* @param urlTemplate a URL template; the resulting URL will be encoded
@@ -56,6 +65,15 @@ public static MockHttpServletRequestBuilder post(String urlTemplate, Object... u
5665
return new MockHttpServletRequestBuilder(HttpMethod.POST, urlTemplate, urlVariables);
5766
}
5867

68+
/**
69+
* Create a {@link MockHttpServletRequestBuilder} for a POST request.
70+
* @param uri the URL
71+
* @since 4.0.3
72+
*/
73+
public static MockHttpServletRequestBuilder post(URI uri) {
74+
return new MockHttpServletRequestBuilder(HttpMethod.POST, uri);
75+
}
76+
5977
/**
6078
* Create a {@link MockHttpServletRequestBuilder} for a PUT request.
6179
* @param urlTemplate a URL template; the resulting URL will be encoded
@@ -65,6 +83,15 @@ public static MockHttpServletRequestBuilder put(String urlTemplate, Object... ur
6583
return new MockHttpServletRequestBuilder(HttpMethod.PUT, urlTemplate, urlVariables);
6684
}
6785

86+
/**
87+
* Create a {@link MockHttpServletRequestBuilder} for a PUT request.
88+
* @param uri the URL
89+
* @since 4.0.3
90+
*/
91+
public static MockHttpServletRequestBuilder put(URI uri) {
92+
return new MockHttpServletRequestBuilder(HttpMethod.PUT, uri);
93+
}
94+
6895
/**
6996
* Create a {@link MockHttpServletRequestBuilder} for a PATCH request.
7097
* @param urlTemplate a URL template; the resulting URL will be encoded
@@ -74,6 +101,15 @@ public static MockHttpServletRequestBuilder patch(String urlTemplate, Object...
74101
return new MockHttpServletRequestBuilder(HttpMethod.PATCH, urlTemplate, urlVariables);
75102
}
76103

104+
/**
105+
* Create a {@link MockHttpServletRequestBuilder} for a PATCH request.
106+
* @param uri the URL
107+
* @since 4.0.3
108+
*/
109+
public static MockHttpServletRequestBuilder patch(URI uri) {
110+
return new MockHttpServletRequestBuilder(HttpMethod.PATCH, uri);
111+
}
112+
77113
/**
78114
* Create a {@link MockHttpServletRequestBuilder} for a DELETE request.
79115
* @param urlTemplate a URL template; the resulting URL will be encoded
@@ -83,6 +119,15 @@ public static MockHttpServletRequestBuilder delete(String urlTemplate, Object...
83119
return new MockHttpServletRequestBuilder(HttpMethod.DELETE, urlTemplate, urlVariables);
84120
}
85121

122+
/**
123+
* Create a {@link MockHttpServletRequestBuilder} for a DELETE request.
124+
* @param uri the URL
125+
* @since 4.0.3
126+
*/
127+
public static MockHttpServletRequestBuilder delete(URI uri) {
128+
return new MockHttpServletRequestBuilder(HttpMethod.DELETE, uri);
129+
}
130+
86131
/**
87132
* Create a {@link MockHttpServletRequestBuilder} for an OPTIONS request.
88133
* @param urlTemplate a URL template; the resulting URL will be encoded
@@ -92,6 +137,14 @@ public static MockHttpServletRequestBuilder options(String urlTemplate, Object..
92137
return new MockHttpServletRequestBuilder(HttpMethod.OPTIONS, urlTemplate, urlVariables);
93138
}
94139

140+
/**
141+
* Create a {@link MockHttpServletRequestBuilder} for an OPTIONS request.
142+
* @param uri the URL
143+
* @since 4.0.3
144+
*/
145+
public static MockHttpServletRequestBuilder options(URI uri) {
146+
return new MockHttpServletRequestBuilder(HttpMethod.OPTIONS, uri);
147+
}
95148

96149
/**
97150
* Create a {@link MockHttpServletRequestBuilder} for a request with the given HTTP method.
@@ -104,86 +157,31 @@ public static MockHttpServletRequestBuilder request(HttpMethod httpMethod, Strin
104157
}
105158

106159
/**
107-
* Create a {@link MockHttpServletRequestBuilder} for a multipart request.
108-
* @param urlTemplate a URL template; the resulting URL will be encoded
109-
* @param urlVariables zero or more URL variables
110-
*/
111-
public static MockMultipartHttpServletRequestBuilder fileUpload(String urlTemplate, Object... urlVariables) {
112-
return new MockMultipartHttpServletRequestBuilder(urlTemplate, urlVariables);
113-
}
114-
115-
116-
/**
117-
* Create a {@link MockHttpServletRequestBuilder} for a GET request.
118-
* @param url the URL
119-
* @since 4.0.3
120-
*/
121-
public static MockHttpServletRequestBuilder get(URI url) {
122-
return new MockHttpServletRequestBuilder(HttpMethod.GET, url);
123-
}
124-
125-
/**
126-
* Create a {@link MockHttpServletRequestBuilder} for a POST request.
127-
* @param url the URL
128-
* @since 4.0.3
129-
*/
130-
public static MockHttpServletRequestBuilder post(URI url) {
131-
return new MockHttpServletRequestBuilder(HttpMethod.POST, url);
132-
}
133-
134-
/**
135-
* Create a {@link MockHttpServletRequestBuilder} for a PUT request.
136-
* @param url the URL
137-
* @since 4.0.3
138-
*/
139-
public static MockHttpServletRequestBuilder put(URI url) {
140-
return new MockHttpServletRequestBuilder(HttpMethod.PUT, url);
141-
}
142-
143-
/**
144-
* Create a {@link MockHttpServletRequestBuilder} for a PATCH request.
145-
* @param url the URL
146-
* @since 4.0.3
147-
*/
148-
public static MockHttpServletRequestBuilder patch(URI url) {
149-
return new MockHttpServletRequestBuilder(HttpMethod.PATCH, url);
150-
}
151-
152-
/**
153-
* Create a {@link MockHttpServletRequestBuilder} for a DELETE request.
154-
* @param url the URL
155-
* @since 4.0.3
156-
*/
157-
public static MockHttpServletRequestBuilder delete(URI url) {
158-
return new MockHttpServletRequestBuilder(HttpMethod.DELETE, url);
159-
}
160-
161-
/**
162-
* Create a {@link MockHttpServletRequestBuilder} for an OPTIONS request.
163-
* @param url the URL
160+
* Create a {@link MockHttpServletRequestBuilder} for a request with the given HTTP method.
161+
* @param httpMethod the HTTP method (GET, POST, etc)
162+
* @param uri the URL
164163
* @since 4.0.3
165164
*/
166-
public static MockHttpServletRequestBuilder options(URI url) {
167-
return new MockHttpServletRequestBuilder(HttpMethod.OPTIONS, url);
165+
public static MockHttpServletRequestBuilder request(HttpMethod httpMethod, URI uri) {
166+
return new MockHttpServletRequestBuilder(httpMethod, uri);
168167
}
169168

170169
/**
171-
* Create a {@link MockHttpServletRequestBuilder} for a request with the given HTTP method.
172-
* @param httpMethod the HTTP method (GET, POST, etc)
173-
* @param url the URL
174-
* @since 4.0.3
170+
* Create a {@link MockHttpServletRequestBuilder} for a multipart request.
171+
* @param urlTemplate a URL template; the resulting URL will be encoded
172+
* @param urlVariables zero or more URL variables
175173
*/
176-
public static MockHttpServletRequestBuilder request(HttpMethod httpMethod, URI url) {
177-
return new MockHttpServletRequestBuilder(httpMethod, url);
174+
public static MockMultipartHttpServletRequestBuilder fileUpload(String urlTemplate, Object... urlVariables) {
175+
return new MockMultipartHttpServletRequestBuilder(urlTemplate, urlVariables);
178176
}
179177

180178
/**
181179
* Create a {@link MockHttpServletRequestBuilder} for a multipart request.
182-
* @param url the URL
180+
* @param uri the URL
183181
* @since 4.0.3
184182
*/
185-
public static MockMultipartHttpServletRequestBuilder fileUpload(URI url) {
186-
return new MockMultipartHttpServletRequestBuilder(url);
183+
public static MockMultipartHttpServletRequestBuilder fileUpload(URI uri) {
184+
return new MockMultipartHttpServletRequestBuilder(uri);
187185
}
188186

189187
/**

0 commit comments

Comments
 (0)