30
30
import static org .assertj .core .api .Assertions .assertThatExceptionOfType ;
31
31
32
32
/**
33
- * Test fixture for HeaderContentNegotiationStrategy tests .
33
+ * Tests for {@link HeaderContentNegotiationStrategy} .
34
34
*
35
35
* @author Rossen Stoyanchev
36
36
* @author Juergen Hoeller
@@ -49,31 +49,27 @@ void resolveMediaTypes() throws Exception {
49
49
this .servletRequest .addHeader ("Accept" , "text/plain; q=0.5, text/html, text/x-dvi; q=0.8, text/x-c" );
50
50
List <MediaType > mediaTypes = this .strategy .resolveMediaTypes (this .webRequest );
51
51
52
- assertThat (mediaTypes ).hasSize (4 );
53
- assertThat (mediaTypes .get (0 ).toString ()).isEqualTo ("text/html" );
54
- assertThat (mediaTypes .get (1 ).toString ()).isEqualTo ("text/x-c" );
55
- assertThat (mediaTypes .get (2 ).toString ()).isEqualTo ("text/x-dvi;q=0.8" );
56
- assertThat (mediaTypes .get (3 ).toString ()).isEqualTo ("text/plain;q=0.5" );
52
+ assertThat (mediaTypes ).map (Object ::toString )
53
+ .containsExactly ("text/html" , "text/x-c" , "text/x-dvi;q=0.8" , "text/plain;q=0.5" );
57
54
}
58
55
59
- @ Test // SPR-14506
60
- public void resolveMediaTypesFromMultipleHeaderValues () throws Exception {
56
+ @ Test // gh-19075
57
+ void resolveMediaTypesFromMultipleHeaderValues () throws Exception {
61
58
this .servletRequest .addHeader ("Accept" , "text/plain; q=0.5, text/html" );
62
59
this .servletRequest .addHeader ("Accept" , "text/x-dvi; q=0.8, text/x-c" );
63
60
List <MediaType > mediaTypes = this .strategy .resolveMediaTypes (this .webRequest );
64
61
65
- assertThat (mediaTypes ).hasSize (4 );
66
- assertThat (mediaTypes .get (0 ).toString ()).isEqualTo ("text/html" );
67
- assertThat (mediaTypes .get (1 ).toString ()).isEqualTo ("text/x-c" );
68
- assertThat (mediaTypes .get (2 ).toString ()).isEqualTo ("text/x-dvi;q=0.8" );
69
- assertThat (mediaTypes .get (3 ).toString ()).isEqualTo ("text/plain;q=0.5" );
62
+ assertThat (mediaTypes ).map (Object ::toString )
63
+ .containsExactly ("text/html" , "text/x-c" , "text/x-dvi;q=0.8" , "text/plain;q=0.5" );
70
64
}
71
65
72
66
@ Test
73
67
void resolveMediaTypesParseError () {
74
68
this .servletRequest .addHeader ("Accept" , "textplain; q=0.5" );
75
- assertThatExceptionOfType (HttpMediaTypeNotAcceptableException .class ).isThrownBy (() ->
76
- this .strategy .resolveMediaTypes (this .webRequest ));
69
+ assertThatExceptionOfType (HttpMediaTypeNotAcceptableException .class )
70
+ .isThrownBy (() -> this .strategy .resolveMediaTypes (this .webRequest ))
71
+ .withMessageStartingWith ("Could not parse 'Accept' header" )
72
+ .withMessageContaining ("Invalid mime type" );
77
73
}
78
74
79
75
}
0 commit comments