diff --git a/spring-web/src/test/java/org/springframework/web/accept/ContentNegotiationManagerFactoryBeanTests.java b/spring-web/src/test/java/org/springframework/web/accept/ContentNegotiationManagerFactoryBeanTests.java index e9d95c2a13a..baabc764498 100644 --- a/spring-web/src/test/java/org/springframework/web/accept/ContentNegotiationManagerFactoryBeanTests.java +++ b/spring-web/src/test/java/org/springframework/web/accept/ContentNegotiationManagerFactoryBeanTests.java @@ -30,10 +30,11 @@ import org.springframework.web.HttpMediaTypeNotAcceptableException; import org.springframework.web.context.request.NativeWebRequest; import org.springframework.web.context.request.ServletWebRequest; -import static org.junit.Assert.assertEquals; +import static org.junit.Assert.*; /** * Test fixture for {@link ContentNegotiationManagerFactoryBean} tests. + * * @author Rossen Stoyanchev */ public class ContentNegotiationManagerFactoryBeanTests { @@ -119,9 +120,7 @@ public class ContentNegotiationManagerFactoryBeanTests { assertEquals(Collections.emptyList(), manager.resolveMediaTypes(this.webRequest)); } - // SPR-10170 - - @Test(expected = HttpMediaTypeNotAcceptableException.class) + @Test(expected = HttpMediaTypeNotAcceptableException.class) // SPR-10170 public void favorPathWithIgnoreUnknownPathExtensionTurnedOff() throws Exception { this.factoryBean.setFavorPathExtension(true); this.factoryBean.setIgnoreUnknownPathExtensions(false); @@ -152,9 +151,7 @@ public class ContentNegotiationManagerFactoryBeanTests { manager.resolveMediaTypes(this.webRequest)); } - // SPR-10170 - - @Test(expected = HttpMediaTypeNotAcceptableException.class) + @Test(expected = HttpMediaTypeNotAcceptableException.class) // SPR-10170 public void favorParameterWithUnknownMediaType() throws HttpMediaTypeNotAcceptableException { this.factoryBean.setFavorParameter(true); this.factoryBean.afterPropertiesSet(); @@ -188,16 +185,12 @@ public class ContentNegotiationManagerFactoryBeanTests { manager.resolveMediaTypes(this.webRequest)); // SPR-10513 - this.servletRequest.addHeader("Accept", MediaType.ALL_VALUE); - assertEquals(Collections.singletonList(MediaType.APPLICATION_JSON), manager.resolveMediaTypes(this.webRequest)); } - // SPR-12286 - - @Test + @Test // SPR-12286 public void setDefaultContentTypeWithStrategy() throws Exception { this.factoryBean.setDefaultContentTypeStrategy(new FixedContentNegotiationStrategy(MediaType.APPLICATION_JSON)); this.factoryBean.afterPropertiesSet(); @@ -216,7 +209,6 @@ public class ContentNegotiationManagerFactoryBeanTests { private final Map mimeTypes = new HashMap<>(); - public Map getMimeTypes() { return this.mimeTypes; } diff --git a/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/method/RequestMappingInfoHandlerMapping.java b/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/method/RequestMappingInfoHandlerMapping.java index df3a198f863..2c57650d1d6 100644 --- a/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/method/RequestMappingInfoHandlerMapping.java +++ b/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/method/RequestMappingInfoHandlerMapping.java @@ -65,7 +65,7 @@ public abstract class RequestMappingInfoHandlerMapping extends AbstractHandlerMe } catch (NoSuchMethodException ex) { // Should never happen - throw new IllegalStateException("No handler for HTTP OPTIONS", ex); + throw new IllegalStateException("Failed to retrieve internal handler method for HTTP OPTIONS", ex); } } @@ -183,7 +183,6 @@ public abstract class RequestMappingInfoHandlerMapping extends AbstractHandlerMe /** * Iterate all RequestMappingInfo's once again, look if any match by URL at * least and raise exceptions according to what doesn't match. - * * @throws HttpRequestMethodNotSupportedException if there are matches by URL * but not by HTTP method * @throws HttpMediaTypeNotAcceptableException if there are matches by URL @@ -243,7 +242,6 @@ public abstract class RequestMappingInfoHandlerMapping extends AbstractHandlerMe private final List partialMatches = new ArrayList(); - public PartialMatchHelper(Set infos, HttpServletRequest request) { for (RequestMappingInfo info : infos) { if (info.getPatternsCondition().getMatchingCondition(request) != null) { @@ -252,7 +250,6 @@ public abstract class RequestMappingInfoHandlerMapping extends AbstractHandlerMe } } - /** * Whether there any partial matches. */ @@ -387,20 +384,18 @@ public abstract class RequestMappingInfoHandlerMapping extends AbstractHandlerMe private final boolean paramsMatch; - /** * @param info RequestMappingInfo that matches the URL path. * @param request the current request */ public PartialMatch(RequestMappingInfo info, HttpServletRequest request) { this.info = info; - this.methodsMatch = info.getMethodsCondition().getMatchingCondition(request) != null; - this.consumesMatch = info.getConsumesCondition().getMatchingCondition(request) != null; - this.producesMatch = info.getProducesCondition().getMatchingCondition(request) != null; - this.paramsMatch = info.getParamsCondition().getMatchingCondition(request) != null; + this.methodsMatch = (info.getMethodsCondition().getMatchingCondition(request) != null); + this.consumesMatch = (info.getConsumesCondition().getMatchingCondition(request) != null); + this.producesMatch = (info.getProducesCondition().getMatchingCondition(request) != null); + this.paramsMatch = (info.getParamsCondition().getMatchingCondition(request) != null); } - public RequestMappingInfo getInfo() { return this.info; } @@ -410,15 +405,15 @@ public abstract class RequestMappingInfoHandlerMapping extends AbstractHandlerMe } public boolean hasConsumesMatch() { - return hasMethodsMatch() && this.consumesMatch; + return (hasMethodsMatch() && this.consumesMatch); } public boolean hasProducesMatch() { - return hasConsumesMatch() && this.producesMatch; + return (hasConsumesMatch() && this.producesMatch); } public boolean hasParamsMatch() { - return hasProducesMatch() && this.paramsMatch; + return (hasProducesMatch() && this.paramsMatch); } @Override @@ -428,6 +423,7 @@ public abstract class RequestMappingInfoHandlerMapping extends AbstractHandlerMe } } + /** * Default handler for HTTP OPTIONS. */ @@ -435,7 +431,6 @@ public abstract class RequestMappingInfoHandlerMapping extends AbstractHandlerMe private final HttpHeaders headers = new HttpHeaders(); - public HttpOptionsHandler(Set declaredMethods) { this.headers.setAllow(initAllowedHttpMethods(declaredMethods)); }