Browse Source

Polishing

pull/940/head
Juergen Hoeller 9 years ago
parent
commit
997278e3ed
  1. 29
      spring-test/src/main/java/org/springframework/test/web/servlet/request/MockHttpServletRequestBuilder.java
  2. 4
      spring-webmvc/src/main/java/org/springframework/web/servlet/resource/ResourceUrlProvider.java
  3. 2
      spring-webmvc/src/main/java/org/springframework/web/servlet/resource/VersionResourceResolver.java

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

@ -142,7 +142,7 @@ public class MockHttpServletRequestBuilder @@ -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.
* <p>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 @@ -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.
* <p>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<String, String> params) {
for (String name : params.keySet()) {
@ -300,7 +301,7 @@ public class MockHttpServletRequestBuilder @@ -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 @@ -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 @@ -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 @@ -712,19 +713,19 @@ public class MockHttpServletRequestBuilder
return request;
}
private static void addToMap(Map<String, Object> 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 <T> void addToMultiValueMap(MultiValueMap<String, T> 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<String, Object> 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);
}
}

4
spring-webmvc/src/main/java/org/springframework/web/servlet/resource/ResourceUrlProvider.java

@ -165,7 +165,7 @@ public class ResourceUrlProvider implements ApplicationListener<ContextRefreshed @@ -165,7 +165,7 @@ public class ResourceUrlProvider implements ApplicationListener<ContextRefreshed
* URL path to expose for public use.
* @param request the current request
* @param requestUrl the request URL path to resolve
* @return the resolved public URL path or {@code null} if unresolved
* @return the resolved public URL path, or {@code null} if unresolved
*/
public final String getForRequestUrl(HttpServletRequest request, String requestUrl) {
if (logger.isTraceEnabled()) {
@ -177,7 +177,7 @@ public class ResourceUrlProvider implements ApplicationListener<ContextRefreshed @@ -177,7 +177,7 @@ public class ResourceUrlProvider implements ApplicationListener<ContextRefreshed
String suffix = requestUrl.substring(suffixIndex);
String lookupPath = requestUrl.substring(prefixIndex, suffixIndex);
String resolvedLookupPath = getForLookupPath(lookupPath);
return (resolvedLookupPath != null) ? prefix + resolvedLookupPath + suffix : null;
return (resolvedLookupPath != null ? prefix + resolvedLookupPath + suffix : null);
}
private int getLookupPathIndex(HttpServletRequest request) {

2
spring-webmvc/src/main/java/org/springframework/web/servlet/resource/VersionResourceResolver.java

@ -168,7 +168,7 @@ public class VersionResourceResolver extends AbstractResourceResolver { @@ -168,7 +168,7 @@ public class VersionResourceResolver extends AbstractResourceResolver {
String actualVersion = versionStrategy.getResourceVersion(baseResource);
if (candidateVersion.equals(actualVersion)) {
if (logger.isTraceEnabled()) {
logger.trace("Resource matches extracted version: "+ candidateVersion);
logger.trace("Resource matches extracted version ["+ candidateVersion + "]");
}
if (request != null) {
request.setAttribute(RESOURCE_VERSION_ATTRIBUTE, candidateVersion);

Loading…
Cancel
Save