### Question:
DefaultFileManager implements FileManager { @Override public synchronized File createFile(final String filepath) throws IOException { final File file = new File(directory, filepath); return createFile(file); } DefaultFileManager(final File rootDirectory); @Override synchronized File createDirectory(final String directoryPath); @Override File getDirectory(final String directoryPath); @Override Set<File> listFilesInDirectory(final String directoryPath); @Override Set<File> listFilesInDirectory(final File directory); @Override synchronized File createFile(final String filepath); @Override synchronized File createFile(final File file); @Override synchronized boolean deleteFile(final String filepath); @Override synchronized boolean deleteFile(final File file); @Override synchronized InputStream newInputStream(final String filepath); @Override synchronized InputStream newInputStream(final File file); @Override synchronized OutputStream newOutputStream(final String filepath, final boolean append); @Override synchronized OutputStream newOutputStream(final File file, final boolean append);  }### Answer:
@Test public void test_WhenFileNotExists_createFile_FileReturnedExists() throws IOException { File testFileSetup = new File(rootTestDirectory, TEST_FILE_NAME); testFileSetup.delete(); Assert.assertFalse(testFileSetup.exists()); File testFile = target.createFile(TEST_FILE_NAME); Assert.assertTrue(testFile.isFile()); }
@Test public void test_WhenFileExists_createFile_ReturnsFile() throws IOException { File testFileSetup = new File(rootTestDirectory, TEST_FILE_NAME); testFileSetup.delete(); testFileSetup.createNewFile(); Assert.assertTrue(testFileSetup.isFile()); File testFile = target.createFile(TEST_FILE_NAME); Assert.assertTrue(testFile.isFile()); }
@Test public void test_WhenDirectoryExistsWithSameName_createFile_ReturnsNull() throws IOException{ File testDirectorySetup = new File(rootTestDirectory, TEST_FILE_NAME); testDirectorySetup.delete(); testDirectorySetup.mkdirs(); Assert.assertTrue(testDirectorySetup.isDirectory()); File testFile = target.createFile(TEST_FILE_NAME); Assert.assertNull(testFile); }
@Test(expected = IOException.class) public void test_WhenFileSystemReadOnlyAndFileNotExists_createFile_ThrowsIOException() throws IOException{ File testFileSetup = new File(rootTestDirectory, TEST_FILE_NAME); testFileSetup.delete(); Assert.assertFalse(testFileSetup.exists()); rootTestDirectory.setReadOnly(); try { File testFile = target.createFile(TEST_FILE_NAME); } catch (IOException e) { throw e; } finally { rootTestDirectory.setWritable(true); } }