@@ -142,7 +142,7 @@ public class MockHttpServletRequestBuilder
142
142
143
143
/**
144
144
* Add a request parameter to the {@link MockHttpServletRequest}.
145
- * If called more than once, the new values are added.
145
+ * <p> If called more than once, new values get added to existing ones .
146
146
* @param name the parameter name
147
147
* @param values one or more values
148
148
*/
@@ -152,10 +152,11 @@ public MockHttpServletRequestBuilder param(String name, String... values) {
152
152
}
153
153
154
154
/**
155
- * Add request parameters to the {@link MockHttpServletRequest} for example
156
- * such as when testing a form submission. If called more than once, the new
157
- * values are added.
155
+ * Add a map of request parameters to the {@link MockHttpServletRequest},
156
+ * for example when testing a form submission.
157
+ * <p>If called more than once, new values get added to existing ones .
158
158
* @param params the parameters to add
159
+ * @since 4.2.4
159
160
*/
160
161
public MockHttpServletRequestBuilder params (MultiValueMap <String , String > params ) {
161
162
for (String name : params .keySet ()) {
@@ -300,7 +301,7 @@ public MockHttpServletRequestBuilder characterEncoding(String encoding) {
300
301
* @param value the attribute value
301
302
*/
302
303
public MockHttpServletRequestBuilder requestAttr (String name , Object value ) {
303
- addAttributeToMap (this .attributes , name , value );
304
+ addToMap (this .attributes , name , value );
304
305
return this ;
305
306
}
306
307
@@ -310,7 +311,7 @@ public MockHttpServletRequestBuilder requestAttr(String name, Object value) {
310
311
* @param value the session attribute value
311
312
*/
312
313
public MockHttpServletRequestBuilder sessionAttr (String name , Object value ) {
313
- addAttributeToMap (this .sessionAttributes , name , value );
314
+ addToMap (this .sessionAttributes , name , value );
314
315
return this ;
315
316
}
316
317
@@ -332,7 +333,7 @@ public MockHttpServletRequestBuilder sessionAttrs(Map<String, Object> sessionAtt
332
333
* @param value the flash attribute value
333
334
*/
334
335
public MockHttpServletRequestBuilder flashAttr (String name , Object value ) {
335
- addAttributeToMap (this .flashAttributes , name , value );
336
+ addToMap (this .flashAttributes , name , value );
336
337
return this ;
337
338
}
338
339
@@ -712,19 +713,19 @@ public MockHttpServletRequest postProcessRequest(MockHttpServletRequest request)
712
713
return request ;
713
714
}
714
715
716
+
717
+ private static void addToMap (Map <String , Object > map , String name , Object value ) {
718
+ Assert .hasLength (name , "'name' must not be empty" );
719
+ Assert .notNull (value , "'value' must not be null" );
720
+ map .put (name , value );
721
+ }
722
+
715
723
private static <T > void addToMultiValueMap (MultiValueMap <String , T > map , String name , T [] values ) {
716
724
Assert .hasLength (name , "'name' must not be empty" );
717
- Assert .notNull (values , "'values' is required" );
718
725
Assert .notEmpty (values , "'values' must not be empty" );
719
726
for (T value : values ) {
720
727
map .add (name , value );
721
728
}
722
729
}
723
730
724
- private static void addAttributeToMap (Map <String , Object > map , String name , Object value ) {
725
- Assert .hasLength (name , "'name' must not be empty" );
726
- Assert .notNull (value , "'value' must not be null" );
727
- map .put (name , value );
728
- }
729
-
730
731
}
0 commit comments