### Question:
ContentUploader { public String upload(String filename) { if (StringUtil.isBlank(filename)) { throw new IllegalArgumentException("Empty path"); } return upload(new File(filename)); } ContentUploader(ContentManagerRemote contentManager); String upload(String filename); String upload(File file);  }### Answer:
@Test(expectedExceptions = { IllegalArgumentException.class }) public void uploadByFileNameShouldThrowIAEWhenFilenameIsNull() throws Exception { contentUploader.upload((String) null); }
@Test(expectedExceptions = { IllegalArgumentException.class }) public void uploadByFileNameShouldThrowIAEWhenFilenameIsBlank() throws Exception { contentUploader.upload(" "); }
@Test(expectedExceptions = { IllegalArgumentException.class }) public void uploadByFileNameShouldThrowIAEWhenFileDoesNotExist() throws Exception { File aFileWhichDoesNotExist = aFileWhichDoesNotExist(); assertFalse(aFileWhichDoesNotExist.exists()); contentUploader.upload(aFileWhichDoesNotExist.getAbsolutePath()); }
@Test(expectedExceptions = { IllegalArgumentException.class }) public void uploadByFileNameShouldThrowIAEWhenFileIsADirectory() throws Exception { File aFileWhichIsADirectory = aFileWhichIsADirectory(); contentUploader.upload(aFileWhichIsADirectory.getAbsolutePath()); }
@Test public void testUploadByFileName() throws Exception { File testFileToSend = createTestFileToSend(); final File testFileReceived = createTestFileReceived(); doAnswer(new Answer<Void>() { @Override public Void answer(InvocationOnMock invocation) throws Throwable { Object[] invocationArguments = invocation.getArguments(); ByteArrayInputStream inputStream = new ByteArrayInputStream((byte[]) invocationArguments[1], (Integer) invocationArguments[2], (Integer) invocationArguments[3]); FileOutputStream fileOutputStream = null; try { fileOutputStream = new FileOutputStream(testFileReceived, true); StreamUtil.copy(inputStream, new BufferedOutputStream(fileOutputStream, 1024 * 32)); } catch (FileNotFoundException e) { throw new RuntimeException(e); } finally { StreamUtil.safeClose(fileOutputStream); } return null; } }).when(contentManager).uploadContentFragment(eq(TEST_HANDLE), any(byte[].class), anyInt(), anyInt()); String temporaryContentHandle = contentUploader.upload(testFileToSend.getAbsolutePath()); assertEquals(temporaryContentHandle, TEST_HANDLE); assertEquals(testFileReceived.length(), testFileToSend.length()); assertEquals(MessageDigestGenerator.getDigestString(testFileReceived), MessageDigestGenerator.getDigestString(testFileToSend)); }