Browse Source

Polishing

(cherry picked from commit 836a0b3a40)
pull/33048/head
Sam Brannen 2 years ago
parent
commit
755968fd2c
  1. 26
      spring-web/src/test/java/org/springframework/web/accept/HeaderContentNegotiationStrategyTests.java

26
spring-web/src/test/java/org/springframework/web/accept/HeaderContentNegotiationStrategyTests.java

@ -30,7 +30,7 @@ import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatExceptionOfType; import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
/** /**
* Test fixture for HeaderContentNegotiationStrategy tests. * Tests for {@link HeaderContentNegotiationStrategy}.
* *
* @author Rossen Stoyanchev * @author Rossen Stoyanchev
* @author Juergen Hoeller * @author Juergen Hoeller
@ -49,31 +49,27 @@ public class HeaderContentNegotiationStrategyTests {
this.servletRequest.addHeader("Accept", "text/plain; q=0.5, text/html, text/x-dvi; q=0.8, text/x-c"); this.servletRequest.addHeader("Accept", "text/plain; q=0.5, text/html, text/x-dvi; q=0.8, text/x-c");
List<MediaType> mediaTypes = this.strategy.resolveMediaTypes(this.webRequest); List<MediaType> mediaTypes = this.strategy.resolveMediaTypes(this.webRequest);
assertThat(mediaTypes).hasSize(4); assertThat(mediaTypes).map(Object::toString)
assertThat(mediaTypes.get(0).toString()).isEqualTo("text/html"); .containsExactly("text/html", "text/x-c", "text/x-dvi;q=0.8", "text/plain;q=0.5");
assertThat(mediaTypes.get(1).toString()).isEqualTo("text/x-c");
assertThat(mediaTypes.get(2).toString()).isEqualTo("text/x-dvi;q=0.8");
assertThat(mediaTypes.get(3).toString()).isEqualTo("text/plain;q=0.5");
} }
@Test // SPR-14506 @Test // gh-19075
public void resolveMediaTypesFromMultipleHeaderValues() throws Exception { void resolveMediaTypesFromMultipleHeaderValues() throws Exception {
this.servletRequest.addHeader("Accept", "text/plain; q=0.5, text/html"); this.servletRequest.addHeader("Accept", "text/plain; q=0.5, text/html");
this.servletRequest.addHeader("Accept", "text/x-dvi; q=0.8, text/x-c"); this.servletRequest.addHeader("Accept", "text/x-dvi; q=0.8, text/x-c");
List<MediaType> mediaTypes = this.strategy.resolveMediaTypes(this.webRequest); List<MediaType> mediaTypes = this.strategy.resolveMediaTypes(this.webRequest);
assertThat(mediaTypes).hasSize(4); assertThat(mediaTypes).map(Object::toString)
assertThat(mediaTypes.get(0).toString()).isEqualTo("text/html"); .containsExactly("text/html", "text/x-c", "text/x-dvi;q=0.8", "text/plain;q=0.5");
assertThat(mediaTypes.get(1).toString()).isEqualTo("text/x-c");
assertThat(mediaTypes.get(2).toString()).isEqualTo("text/x-dvi;q=0.8");
assertThat(mediaTypes.get(3).toString()).isEqualTo("text/plain;q=0.5");
} }
@Test @Test
public void resolveMediaTypesParseError() throws Exception { public void resolveMediaTypesParseError() throws Exception {
this.servletRequest.addHeader("Accept", "textplain; q=0.5"); this.servletRequest.addHeader("Accept", "textplain; q=0.5");
assertThatExceptionOfType(HttpMediaTypeNotAcceptableException.class).isThrownBy(() -> assertThatExceptionOfType(HttpMediaTypeNotAcceptableException.class)
this.strategy.resolveMediaTypes(this.webRequest)); .isThrownBy(() -> this.strategy.resolveMediaTypes(this.webRequest))
.withMessageStartingWith("Could not parse 'Accept' header")
.withMessageContaining("Invalid mime type");
} }
} }

Loading…
Cancel
Save