Browse Source

Polishing

pull/23050/head
Juergen Hoeller 6 years ago
parent
commit
4ec9aff01d
  1. 10
      spring-core/src/test/java/org/springframework/core/type/AnnotationMetadataTests.java
  2. 48
      spring-web/src/main/java/org/springframework/web/util/UrlPathHelper.java
  3. 12
      spring-web/src/test/java/org/springframework/http/converter/json/Jackson2ObjectMapperBuilderTests.java

10
spring-core/src/test/java/org/springframework/core/type/AnnotationMetadataTests.java

@ -52,7 +52,7 @@ import static org.junit.Assert.*; @@ -52,7 +52,7 @@ import static org.junit.Assert.*;
public class AnnotationMetadataTests {
@Test
public void standardAnnotationMetadata() throws Exception {
public void standardAnnotationMetadata() {
AnnotationMetadata metadata = new StandardAnnotationMetadata(AnnotatedComponent.class, true);
doTestAnnotationInfo(metadata);
doTestMethodAnnotationInfo(metadata);
@ -68,7 +68,7 @@ public class AnnotationMetadataTests { @@ -68,7 +68,7 @@ public class AnnotationMetadataTests {
}
@Test
public void standardAnnotationMetadataForSubclass() throws Exception {
public void standardAnnotationMetadataForSubclass() {
AnnotationMetadata metadata = new StandardAnnotationMetadata(AnnotatedComponentSubClass.class, true);
doTestSubClassAnnotationInfo(metadata);
}
@ -104,7 +104,7 @@ public class AnnotationMetadataTests { @@ -104,7 +104,7 @@ public class AnnotationMetadataTests {
}
@Test
public void standardAnnotationMetadataForInterface() throws Exception {
public void standardAnnotationMetadataForInterface() {
AnnotationMetadata metadata = new StandardAnnotationMetadata(AnnotationMetadata.class, true);
doTestMetadataForInterfaceClass(metadata);
}
@ -132,7 +132,7 @@ public class AnnotationMetadataTests { @@ -132,7 +132,7 @@ public class AnnotationMetadataTests {
}
@Test
public void standardAnnotationMetadataForAnnotation() throws Exception {
public void standardAnnotationMetadataForAnnotation() {
AnnotationMetadata metadata = new StandardAnnotationMetadata(Component.class, true);
doTestMetadataForAnnotationClass(metadata);
}
@ -172,7 +172,7 @@ public class AnnotationMetadataTests { @@ -172,7 +172,7 @@ public class AnnotationMetadataTests {
* 'true' as is done in the main test above.
*/
@Test
public void standardAnnotationMetadata_nestedAnnotationsAsMap_false() throws Exception {
public void standardAnnotationMetadata_nestedAnnotationsAsMap_false() {
AnnotationMetadata metadata = new StandardAnnotationMetadata(AnnotatedComponent.class);
AnnotationAttributes specialAttrs = (AnnotationAttributes) metadata.getAnnotationAttributes(SpecialAttr.class.getName());
Annotation[] nestedAnnoArray = (Annotation[]) specialAttrs.get("nestedAnnoArray");

48
spring-web/src/main/java/org/springframework/web/util/UrlPathHelper.java

@ -1,5 +1,5 @@ @@ -1,5 +1,5 @@
/*
* Copyright 2002-2018 the original author or authors.
* Copyright 2002-2019 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@ -21,7 +21,6 @@ import java.nio.charset.UnsupportedCharsetException; @@ -21,7 +21,6 @@ import java.nio.charset.UnsupportedCharsetException;
import java.util.LinkedHashMap;
import java.util.Map;
import java.util.Properties;
import javax.servlet.ServletContext;
import javax.servlet.http.HttpServletRequest;
import org.apache.commons.logging.Log;
@ -34,7 +33,7 @@ import org.springframework.util.StringUtils; @@ -34,7 +33,7 @@ import org.springframework.util.StringUtils;
/**
* Helper class for URL path matching. Provides support for URL paths in
* RequestDispatcher includes and support for consistent URL decoding.
* {@code RequestDispatcher} includes and support for consistent URL decoding.
*
* <p>Used by {@link org.springframework.web.servlet.handler.AbstractUrlHandlerMapping}
* and {@link org.springframework.web.servlet.support.RequestContext} for path matching
@ -44,6 +43,8 @@ import org.springframework.util.StringUtils; @@ -44,6 +43,8 @@ import org.springframework.util.StringUtils;
* @author Rob Harrop
* @author Rossen Stoyanchev
* @since 14.01.2004
* @see #getLookupPathForRequest
* @see javax.servlet.RequestDispatcher
*/
public class UrlPathHelper {
@ -70,8 +71,9 @@ public class UrlPathHelper { @@ -70,8 +71,9 @@ public class UrlPathHelper {
/**
* Whether URL lookups should always use the full path within current
* application context, i.e. within {@link ServletContext#getContextPath()}.
* Whether URL lookups should always use the full path within the current
* web application context, i.e. within
* {@link javax.servlet.ServletContext#getContextPath()}.
* <p>If set to {@literal false} the path within the current servlet mapping
* is used instead if applicable (i.e. in the case of a prefix based Servlet
* mapping such as "/myServlet/*").
@ -90,7 +92,7 @@ public class UrlPathHelper { @@ -90,7 +92,7 @@ public class UrlPathHelper {
* <p>By default this is set to {@literal true}.
* <p><strong>Note:</strong> Be aware the servlet path will not match when
* compared to encoded paths. Therefore use of {@code urlDecode=false} is
* not compatible with a prefix-based Servlet mappping and likewise implies
* not compatible with a prefix-based Servlet mapping and likewise implies
* also setting {@code alwaysUseFullPath=true}.
* @see #getServletPath
* @see #getContextPath
@ -157,8 +159,8 @@ public class UrlPathHelper { @@ -157,8 +159,8 @@ public class UrlPathHelper {
* <p>Detects include request URL if called within a RequestDispatcher include.
* @param request current HTTP request
* @return the lookup path
* @see #getPathWithinApplication
* @see #getPathWithinServletMapping
* @see #getPathWithinApplication
*/
public String getLookupPathForRequest(HttpServletRequest request) {
// Always use full path within current servlet context?
@ -187,6 +189,7 @@ public class UrlPathHelper { @@ -187,6 +189,7 @@ public class UrlPathHelper {
* <p>E.g.: servlet mapping = "/*.test"; request URI = "/a.test" -> "".
* @param request current HTTP request
* @return the path within the servlet mapping, or ""
* @see #getLookupPathForRequest
*/
public String getPathWithinServletMapping(HttpServletRequest request) {
String pathWithinApp = getPathWithinApplication(request);
@ -234,6 +237,7 @@ public class UrlPathHelper { @@ -234,6 +237,7 @@ public class UrlPathHelper {
* <p>Detects include request URL if called within a RequestDispatcher include.
* @param request current HTTP request
* @return the path within the web application
* @see #getLookupPathForRequest
*/
public String getPathWithinApplication(HttpServletRequest request) {
String contextPath = getContextPath(request);
@ -288,7 +292,7 @@ public class UrlPathHelper { @@ -288,7 +292,7 @@ public class UrlPathHelper {
/**
* Sanitize the given path. Uses the following rules:
* <ul>
* <li>replace all "//" by "/"</li>
* <li>replace all "//" by "/"</li>
* </ul>
*/
private String getSanitizedPath(final String path) {
@ -492,8 +496,8 @@ public class UrlPathHelper { @@ -492,8 +496,8 @@ public class UrlPathHelper {
/**
* Remove ";" (semicolon) content from the given request URI if the
* {@linkplain #setRemoveSemicolonContent(boolean) removeSemicolonContent}
* property is set to "true". Note that "jssessionid" is always removed.
* {@linkplain #setRemoveSemicolonContent removeSemicolonContent}
* property is set to "true". Note that "jsessionid" is always removed.
* @param requestUri the request URI string to remove ";" content from
* @return the updated URI string
*/
@ -524,12 +528,10 @@ public class UrlPathHelper { @@ -524,12 +528,10 @@ public class UrlPathHelper {
}
/**
* Decode the given URI path variables via
* {@link #decodeRequestString(HttpServletRequest, String)} unless
* {@link #setUrlDecode(boolean)} is set to {@code true} in which case it is
* assumed the URL path from which the variables were extracted is already
* decoded through a call to
* {@link #getLookupPathForRequest(HttpServletRequest)}.
* Decode the given URI path variables via {@link #decodeRequestString} unless
* {@link #setUrlDecode} is set to {@code true} in which case it is assumed
* the URL path from which the variables were extracted is already decoded
* through a call to {@link #getLookupPathForRequest(HttpServletRequest)}.
* @param request current HTTP request
* @param vars the URI variables extracted from the URL path
* @return the same Map or a new Map instance
@ -546,18 +548,16 @@ public class UrlPathHelper { @@ -546,18 +548,16 @@ public class UrlPathHelper {
}
/**
* Decode the given matrix variables via
* {@link #decodeRequestString(HttpServletRequest, String)} unless
* {@link #setUrlDecode(boolean)} is set to {@code true} in which case it is
* assumed the URL path from which the variables were extracted is already
* decoded through a call to
* {@link #getLookupPathForRequest(HttpServletRequest)}.
* Decode the given matrix variables via {@link #decodeRequestString} unless
* {@link #setUrlDecode} is set to {@code true} in which case it is assumed
* the URL path from which the variables were extracted is already decoded
* through a call to {@link #getLookupPathForRequest(HttpServletRequest)}.
* @param request current HTTP request
* @param vars the URI variables extracted from the URL path
* @return the same Map or a new Map instance
*/
public MultiValueMap<String, String> decodeMatrixVariables(HttpServletRequest request,
MultiValueMap<String, String> vars) {
public MultiValueMap<String, String> decodeMatrixVariables(
HttpServletRequest request, MultiValueMap<String, String> vars) {
if (this.urlDecode) {
return vars;

12
spring-web/src/test/java/org/springframework/http/converter/json/Jackson2ObjectMapperBuilderTests.java

@ -83,15 +83,8 @@ import org.junit.Test; @@ -83,15 +83,8 @@ import org.junit.Test;
import org.springframework.beans.FatalBeanException;
import org.springframework.util.StringUtils;
import static org.hamcrest.Matchers.containsString;
import static org.hamcrest.Matchers.not;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertSame;
import static org.junit.Assert.assertThat;
import static org.junit.Assert.assertTrue;
import static org.hamcrest.Matchers.*;
import static org.junit.Assert.*;
/**
* Test class for {@link Jackson2ObjectMapperBuilder}.
@ -695,6 +688,7 @@ public class Jackson2ObjectMapperBuilderTests { @@ -695,6 +688,7 @@ public class Jackson2ObjectMapperBuilderTests {
}
@SuppressWarnings("serial")
public static class MyXmlFactory extends XmlFactory {
}

Loading…
Cancel
Save