Polishing

(cherry picked from commit 382a931)
This commit is contained in:
Juergen Hoeller 2016-07-22 22:28:20 +02:00
parent 9ed087d5da
commit 9451177c35
2 changed files with 14 additions and 27 deletions

View File

@ -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<String, String> mimeTypes = new HashMap<>();
public Map<String, String> getMimeTypes() {
return this.mimeTypes;
}

View File

@ -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<PartialMatch> partialMatches = new ArrayList<PartialMatch>();
public PartialMatchHelper(Set<RequestMappingInfo> 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<String> declaredMethods) {
this.headers.setAllow(initAllowedHttpMethods(declaredMethods));
}