21
21
import java .io .InputStream ;
22
22
import java .io .StringReader ;
23
23
import java .nio .charset .StandardCharsets ;
24
+ import java .util .ArrayList ;
24
25
import java .util .List ;
25
26
import javax .xml .transform .Source ;
26
27
import javax .xml .transform .stream .StreamSource ;
48
49
import static org .mockito .Mockito .verify ;
49
50
50
51
/**
52
+ * Unit tests for {@link FormHttpMessageConverter} and
53
+ * {@link AllEncompassingFormHttpMessageConverter}.
54
+ *
51
55
* @author Arjen Poutsma
52
56
* @author Rossen Stoyanchev
57
+ * @author Sam Brannen
53
58
*/
54
59
public class FormHttpMessageConverterTests {
55
60
@@ -58,21 +63,31 @@ public class FormHttpMessageConverterTests {
58
63
59
64
@ Test
60
65
public void canRead () {
61
- assertThat (this .converter .canRead (MultiValueMap .class ,
62
- new MediaType ("application" , "x-www-form-urlencoded" ))).isTrue ();
63
- assertThat (this .converter .canRead (MultiValueMap .class ,
64
- new MediaType ("multipart" , "form-data" ))).isFalse ();
66
+ assertThat (this .converter .canRead (MultiValueMap .class , new MediaType ("application" , "x-www-form-urlencoded" ))).isTrue ();
67
+ assertThat (this .converter .canRead (MultiValueMap .class , new MediaType ("multipart" , "form-data" ))).isFalse ();
65
68
}
66
69
67
70
@ Test
68
71
public void canWrite () {
69
- assertThat (this .converter .canWrite (MultiValueMap .class ,
70
- new MediaType ("application" , "x-www-form-urlencoded" ))).isTrue ();
71
- assertThat (this .converter .canWrite (MultiValueMap .class ,
72
- new MediaType ("multipart" , "form-data" ))).isTrue ();
73
- assertThat (this .converter .canWrite (MultiValueMap .class ,
74
- new MediaType ("multipart" , "form-data" , StandardCharsets .UTF_8 ))).isTrue ();
75
- assertThat (this .converter .canWrite (MultiValueMap .class , MediaType .ALL )).isTrue ();
72
+ assertCanWrite (MultiValueMap .class , new MediaType ("application" , "x-www-form-urlencoded" ));
73
+ assertCanWrite (MultiValueMap .class , new MediaType ("multipart" , "form-data" ));
74
+ assertCanWrite (MultiValueMap .class , new MediaType ("multipart" , "form-data" , StandardCharsets .UTF_8 ));
75
+ assertCanWrite (MultiValueMap .class , MediaType .ALL );
76
+ }
77
+
78
+ @ Test
79
+ public void canWriteMultipartMixedAndMultipartRelated () {
80
+ List <MediaType > supportedMediaTypes = new ArrayList <>(this .converter .getSupportedMediaTypes ());
81
+ supportedMediaTypes .add (new MediaType ("multipart" , "mixed" ));
82
+ supportedMediaTypes .add (new MediaType ("multipart" , "related" ));
83
+ this .converter .setSupportedMediaTypes (supportedMediaTypes );
84
+
85
+ assertCanWrite (MultiValueMap .class , new MediaType ("multipart" , "mixed" ));
86
+ assertCanWrite (MultiValueMap .class , new MediaType ("multipart" , "related" ));
87
+ }
88
+
89
+ private void assertCanWrite (Class <?> clazz , MediaType mediaType ) {
90
+ assertThat (this .converter .canWrite (clazz , mediaType )).isTrue ();
76
91
}
77
92
78
93
@ Test
@@ -181,9 +196,7 @@ public String getFilename() {
181
196
verify (outputMessage .getBody (), never ()).close ();
182
197
}
183
198
184
- // SPR-13309
185
-
186
- @ Test
199
+ @ Test // SPR-13309
187
200
public void writeMultipartOrder () throws Exception {
188
201
MyBean myBean = new MyBean ();
189
202
myBean .setString ("foo" );
0 commit comments