1
1
/*
2
- * Copyright 2002-2018 the original author or authors.
2
+ * Copyright 2002-2019 the original author or authors.
3
3
*
4
4
* Licensed under the Apache License, Version 2.0 (the "License");
5
5
* you may not use this file except in compliance with the License.
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 .*;
43
45
import static org .junit .Assert .*;
@@ -59,7 +61,7 @@ public class EncoderHttpMessageWriterTests {
59
61
60
62
61
63
@ Mock
62
- private Encoder <String > encoder ;
64
+ private HttpMessageEncoder <String > encoder ;
63
65
64
66
private ArgumentCaptor <MediaType > mediaTypeCaptor ;
65
67
@@ -172,6 +174,17 @@ public void emptyBodyWritten() {
172
174
assertEquals (0 , this .response .getHeaders ().getContentLength ());
173
175
}
174
176
177
+ @ Test // gh-22936
178
+ public void isStreamingMediaType () throws InvocationTargetException , IllegalAccessException {
179
+ HttpMessageWriter <String > writer = getWriter (TEXT_HTML );
180
+ MediaType streamingMediaType = new MediaType (TEXT_PLAIN , Collections .singletonMap ("streaming" , "true" ));
181
+ when (this .encoder .getStreamingMediaTypes ()).thenReturn (Arrays .asList (streamingMediaType ));
182
+ Method method = ReflectionUtils .findMethod (writer .getClass (), "isStreamingMediaType" , MediaType .class );
183
+ ReflectionUtils .makeAccessible (method );
184
+ assertTrue ((Boolean ) method .invoke (writer , streamingMediaType ));
185
+ assertFalse ((Boolean ) method .invoke (writer , new MediaType (TEXT_PLAIN , Collections .singletonMap ("streaming" , "false" ))));
186
+ assertFalse ((Boolean ) method .invoke (writer , TEXT_HTML ));
187
+ }
175
188
176
189
private HttpMessageWriter <String > getWriter (MimeType ... mimeTypes ) {
177
190
return getWriter (Flux .empty (), mimeTypes );
0 commit comments