16
16
17
17
package org .springframework .http .codec ;
18
18
19
+ import java .lang .reflect .InvocationTargetException ;
20
+ import java .lang .reflect .Method ;
19
21
import java .nio .charset .StandardCharsets ;
20
22
import java .util .Arrays ;
21
23
import java .util .Collections ;
31
33
import reactor .core .publisher .Mono ;
32
34
import reactor .test .StepVerifier ;
33
35
34
- import org .springframework .core .codec .Encoder ;
35
36
import org .springframework .core .io .buffer .DataBuffer ;
36
37
import org .springframework .core .io .buffer .DefaultDataBufferFactory ;
37
38
import org .springframework .http .MediaType ;
38
39
import org .springframework .mock .http .server .reactive .test .MockServerHttpResponse ;
39
40
import org .springframework .util .MimeType ;
40
41
import org .springframework .util .MimeTypeUtils ;
42
+ import org .springframework .util .ReflectionUtils ;
41
43
42
44
import static java .nio .charset .StandardCharsets .ISO_8859_1 ;
43
45
import static java .nio .charset .StandardCharsets .UTF_8 ;
@@ -64,7 +66,7 @@ public class EncoderHttpMessageWriterTests {
64
66
65
67
66
68
@ Mock
67
- private Encoder <String > encoder ;
69
+ private HttpMessageEncoder <String > encoder ;
68
70
69
71
private ArgumentCaptor <MediaType > mediaTypeCaptor ;
70
72
@@ -177,6 +179,17 @@ public void emptyBodyWritten() {
177
179
assertEquals (0 , this .response .getHeaders ().getContentLength ());
178
180
}
179
181
182
+ @ Test // gh-22936
183
+ public void isStreamingMediaType () throws InvocationTargetException , IllegalAccessException {
184
+ HttpMessageWriter <String > writer = getWriter (TEXT_HTML );
185
+ MediaType streamingMediaType = new MediaType (TEXT_PLAIN , Collections .singletonMap ("streaming" , "true" ));
186
+ when (this .encoder .getStreamingMediaTypes ()).thenReturn (Arrays .asList (streamingMediaType ));
187
+ Method method = ReflectionUtils .findMethod (writer .getClass (), "isStreamingMediaType" , MediaType .class );
188
+ ReflectionUtils .makeAccessible (method );
189
+ assertTrue ((Boolean ) method .invoke (writer , streamingMediaType ));
190
+ assertFalse ((Boolean ) method .invoke (writer , new MediaType (TEXT_PLAIN , Collections .singletonMap ("streaming" , "false" ))));
191
+ assertFalse ((Boolean ) method .invoke (writer , TEXT_HTML ));
192
+ }
180
193
181
194
private HttpMessageWriter <String > getWriter (MimeType ... mimeTypes ) {
182
195
return getWriter (Flux .empty (), mimeTypes );
0 commit comments