StringPart extends AbstractPart { @Override public InputStream getContent() throws IOException { byte[] bytes = getBytesFromContent(); if (bytes == null) { return null; } InputStream is = new ByteArrayInputStream(bytes); return is; } StringPart(String name, String content);  StringPart(String name, String content, String charset);  StringPart(String name, String content, String charset, ContentType contentType); @Override ContentType getContentType(); @Override InputStream getContent();  }
@Test(expected = IOException.class) public void shouldThrowIOExceptionWhenInvalidCharset() throws IOException { String invalidCharset = "@MSADG"; Part part = new StringPart(name, content, invalidCharset, ContentType.CONTENT_TYPE_TEXT_PLAIN); part.getContent(); }
@Test public void shouldReturnContentOfString() throws IOException { Part part = new StringPart(name, content); ByteArrayOutputStream out = new ByteArrayOutputStream(); InputStream is = part.getContent(); PartTestUtils.readStream(is, out); String result = new String(out.toByteArray()); assertThat(result, is(content)); }