diff --git a/spring-test/src/main/java/org/springframework/test/web/servlet/request/MockHttpServletRequestBuilder.java b/spring-test/src/main/java/org/springframework/test/web/servlet/request/MockHttpServletRequestBuilder.java
index e02986e07b..1663bd2fb5 100644
--- a/spring-test/src/main/java/org/springframework/test/web/servlet/request/MockHttpServletRequestBuilder.java
+++ b/spring-test/src/main/java/org/springframework/test/web/servlet/request/MockHttpServletRequestBuilder.java
@@ -142,7 +142,7 @@ public class MockHttpServletRequestBuilder
/**
* Add a request parameter to the {@link MockHttpServletRequest}.
- * If called more than once, the new values are added.
+ *
If called more than once, new values get added to existing ones.
* @param name the parameter name
* @param values one or more values
*/
@@ -152,10 +152,11 @@ public class MockHttpServletRequestBuilder
}
/**
- * Add request parameters to the {@link MockHttpServletRequest} for example
- * such as when testing a form submission. If called more than once, the new
- * values are added.
+ * Add a map of request parameters to the {@link MockHttpServletRequest},
+ * for example when testing a form submission.
+ *
If called more than once, new values get added to existing ones.
* @param params the parameters to add
+ * @since 4.2.4
*/
public MockHttpServletRequestBuilder params(MultiValueMap params) {
for (String name : params.keySet()) {
@@ -300,7 +301,7 @@ public class MockHttpServletRequestBuilder
* @param value the attribute value
*/
public MockHttpServletRequestBuilder requestAttr(String name, Object value) {
- addAttributeToMap(this.attributes, name, value);
+ addToMap(this.attributes, name, value);
return this;
}
@@ -310,7 +311,7 @@ public class MockHttpServletRequestBuilder
* @param value the session attribute value
*/
public MockHttpServletRequestBuilder sessionAttr(String name, Object value) {
- addAttributeToMap(this.sessionAttributes, name, value);
+ addToMap(this.sessionAttributes, name, value);
return this;
}
@@ -332,7 +333,7 @@ public class MockHttpServletRequestBuilder
* @param value the flash attribute value
*/
public MockHttpServletRequestBuilder flashAttr(String name, Object value) {
- addAttributeToMap(this.flashAttributes, name, value);
+ addToMap(this.flashAttributes, name, value);
return this;
}
@@ -712,19 +713,19 @@ public class MockHttpServletRequestBuilder
return request;
}
+
+ private static void addToMap(Map map, String name, Object value) {
+ Assert.hasLength(name, "'name' must not be empty");
+ Assert.notNull(value, "'value' must not be null");
+ map.put(name, value);
+ }
+
private static void addToMultiValueMap(MultiValueMap map, String name, T[] values) {
Assert.hasLength(name, "'name' must not be empty");
- Assert.notNull(values, "'values' is required");
Assert.notEmpty(values, "'values' must not be empty");
for (T value : values) {
map.add(name, value);
}
}
- private static void addAttributeToMap(Map map, String name, Object value) {
- Assert.hasLength(name, "'name' must not be empty");
- Assert.notNull(value, "'value' must not be null");
- map.put(name, value);
- }
-
}
diff --git a/spring-webmvc/src/main/java/org/springframework/web/servlet/resource/ResourceUrlProvider.java b/spring-webmvc/src/main/java/org/springframework/web/servlet/resource/ResourceUrlProvider.java
index b8e9f73d6f..5537a48cdc 100644
--- a/spring-webmvc/src/main/java/org/springframework/web/servlet/resource/ResourceUrlProvider.java
+++ b/spring-webmvc/src/main/java/org/springframework/web/servlet/resource/ResourceUrlProvider.java
@@ -165,7 +165,7 @@ public class ResourceUrlProvider implements ApplicationListener