Merge branch '5.1.x'

This commit is contained in:
Rossen Stoyanchev
2019-05-01 04:03:21 -04:00
5 changed files with 56 additions and 5 deletions

View File

@@ -23,7 +23,11 @@ import javax.servlet.http.HttpServletRequest;
import org.junit.Test;
import org.springframework.http.MediaType;
import org.springframework.mock.web.test.MockHttpServletRequest;
import org.springframework.web.accept.ContentNegotiationManager;
import org.springframework.web.accept.FixedContentNegotiationStrategy;
import org.springframework.web.accept.HeaderContentNegotiationStrategy;
import org.springframework.web.servlet.mvc.condition.ProducesRequestCondition.ProduceMediaTypeExpression;
import static org.junit.Assert.*;
@@ -149,6 +153,24 @@ public class ProducesRequestConditionTests {
assertNotNull(condition.getMatchingCondition(request));
}
@Test // gh-22853
public void matchAndCompare() {
ContentNegotiationManager manager = new ContentNegotiationManager(
new HeaderContentNegotiationStrategy(),
new FixedContentNegotiationStrategy(MediaType.TEXT_HTML));
ProducesRequestCondition none = new ProducesRequestCondition(new String[0], null, manager);
ProducesRequestCondition html = new ProducesRequestCondition(new String[] {"text/html"}, null, manager);
MockHttpServletRequest request = new MockHttpServletRequest();
request.addHeader("Accept", "*/*");
ProducesRequestCondition noneMatch = none.getMatchingCondition(request);
ProducesRequestCondition htmlMatch = html.getMatchingCondition(request);
assertEquals(1, noneMatch.compareTo(htmlMatch, request));
}
@Test
public void compareTo() {
ProducesRequestCondition html = new ProducesRequestCondition("text/html");