@Test public void shouldWriteExpectedOutput() throws IOException { String contentString = "test test test"; byte[] content = contentString.getBytes(); final InputStream in = new ByteArrayInputStream(content); AbstractPart mock = createPartWithInputStream(name, in); ByteArrayOutputStream out = new ByteArrayOutputStream(); Part part = new TestPart(name, mock); String expected = "Content-Disposition: form-data; name=\"" + name + "\"\r\n\r\n" + contentString + "\r\n"; part.write(out); byte[] result = out.toByteArray(); assertThat(new String(result), is(expected)); }
@Override public void write(OutputStream out) throws IOException { writeContentDisposition(out); writeName(out); writeExtraHeaderIfNotNull(out); writeCRLF(out); writeContentTypeIfNotNull(out); writeCRLF(out); writeContent(out); writeCRLF(out); }
AbstractPart implements Part { @Override public void write(OutputStream out) throws IOException { writeContentDisposition(out); writeName(out); writeExtraHeaderIfNotNull(out); writeCRLF(out); writeContentTypeIfNotNull(out); writeCRLF(out); writeContent(out); writeCRLF(out); } }
AbstractPart implements Part { @Override public void write(OutputStream out) throws IOException { writeContentDisposition(out); writeName(out); writeExtraHeaderIfNotNull(out); writeCRLF(out); writeContentTypeIfNotNull(out); writeCRLF(out); writeContent(out); writeCRLF(out); } AbstractPart(String name); }
AbstractPart implements Part { @Override public void write(OutputStream out) throws IOException { writeContentDisposition(out); writeName(out); writeExtraHeaderIfNotNull(out); writeCRLF(out); writeContentTypeIfNotNull(out); writeCRLF(out); writeContent(out); writeCRLF(out); } AbstractPart(String name); @Override void write(OutputStream out); @Override String getName(); }
AbstractPart implements Part { @Override public void write(OutputStream out) throws IOException { writeContentDisposition(out); writeName(out); writeExtraHeaderIfNotNull(out); writeCRLF(out); writeContentTypeIfNotNull(out); writeCRLF(out); writeContent(out); writeCRLF(out); } AbstractPart(String name); @Override void write(OutputStream out); @Override String getName();  }