### Question:
MultipartUtils { public static InputStream serializeMultipartForm(final Multipart form) throws IOException { try (final ByteArrayOutputStream outputStream = new ByteArrayOutputStream()) { serializeMultipartForm(form, outputStream); return new ByteArrayInputStream(outputStream.toByteArray()); } } MultipartUtils(); static InputStream serializeMultipartForm(final Multipart form); static void serializeMultipartForm(final Multipart form, final OutputStream outputStream);  }### Answer:
@Test public void testEmpty() throws IOException { final Multipart form = new Multipart(); final InputStream inputStream = MultipartUtils.serializeMultipartForm(form); final Collection<Part> parts = Multipart.read(form.getContentType(), -1, inputStream).getParts(); assertTrue(parts.isEmpty()); }
@Test public void testSimple() throws IOException { final Multipart form = new Multipart(); form.param("a", "b"); final InputStream inputStream = MultipartUtils.serializeMultipartForm(form); final List<Part> parts = new ArrayList<>(Multipart.read(form.getContentType(), -1, inputStream).getParts()); assertEquals(1, parts.size()); assertEquals("a", parts.get(0).getName()); assertEquals("b", IOUtils.toString(parts.get(0).getInputStream(), StandardCharsets.UTF_8)); }
@Test public void testFileUpload() throws IOException { final Multipart form = new Multipart(); form.param("a", "b"); form.param("myfile", "config.properties", new FileInputStream("src/test/resources/config.properties")); final InputStream inputStream = MultipartUtils.serializeMultipartForm(form); final List<Part> parts = new ArrayList<>(Multipart.read(form.getContentType(), -1, inputStream).getParts()); assertEquals(2, parts.size()); assertEquals("a", parts.get(0).getName()); assertEquals("b", IOUtils.toString(parts.get(0).getInputStream(), StandardCharsets.UTF_8)); assertEquals("myfile", parts.get(1).getName()); assertEquals("a=b\n", IOUtils.toString(parts.get(1).getInputStream(), StandardCharsets.UTF_8)); }