FilePart extends AbstractPart { @Override public InputStream getContent() throws IOException { if (!file.exists()) { throw new IOException("The file of parts doesn't exist. [PATH : ] " + file.getAbsolutePath()); } InputStream is = new BufferedInputStream(new FileInputStream(file)); return is; } FilePart(File file);  FilePart(String name, File file);  FilePart(String name, File file, ContentType contentType); @Override ContentType getContentType(); @Override InputStream getContent(); String getFilename();  }
@Test(expected = IOException.class) public void shouldThrowExceptionWhenFileNotExist() throws IOException { String filename = "justfortest.txt"; String path = "/hello/world/" + filename; File newFile = new File(path); Part part = new FilePart(newFile); part.getContent(); }
@Test public void shouldReturnContentOfFile() throws IOException { Part part = new FilePart(name, file); ByteArrayOutputStream out = new ByteArrayOutputStream(); InputStream is = part.getContent(); PartTestUtils.readStream(is, out); String result = new String(out.toByteArray()); assertThat(result, is(content)); }