2121import java .io .InputStream ;
2222import java .io .StringReader ;
2323import java .nio .charset .StandardCharsets ;
24+ import java .util .ArrayList ;
2425import java .util .List ;
2526import javax .xml .transform .Source ;
2627import javax .xml .transform .stream .StreamSource ;
4849import static org .mockito .Mockito .verify ;
4950
5051/**
52+ * Unit tests for {@link FormHttpMessageConverter} and
53+ * {@link AllEncompassingFormHttpMessageConverter}.
54+ *
5155 * @author Arjen Poutsma
5256 * @author Rossen Stoyanchev
57+ * @author Sam Brannen
5358 */
5459public class FormHttpMessageConverterTests {
5560
@@ -58,21 +63,31 @@ public class FormHttpMessageConverterTests {
5863
5964 @ Test
6065 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 ();
6568 }
6669
6770 @ Test
6871 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 ();
7691 }
7792
7893 @ Test
@@ -181,9 +196,7 @@ public String getFilename() {
181196 verify (outputMessage .getBody (), never ()).close ();
182197 }
183198
184- // SPR-13309
185-
186- @ Test
199+ @ Test // SPR-13309
187200 public void writeMultipartOrder () throws Exception {
188201 MyBean myBean = new MyBean ();
189202 myBean .setString ("foo" );
0 commit comments