@Test public void testVerifyFileExistsAndReadable() throws IOException { File testFile = createLocalFile(localTempPath.toString(), "SOME_FILE", FILE_SIZE_1_KB); HerdFileUtils.verifyFileExistsAndReadable(testFile); }
/** * Cleans up a local test directory by deleting a test file. * * @throws IOException if fails to create a local test file */ @Test public void testCleanDirectoryIgnoreException() throws IOException { File testFile = createLocalFile(localTempPath.toString(), "SOME_FILE", FILE_SIZE_1_KB); HerdFileUtils.cleanDirectoryIgnoreException(localTempPath.toFile()); assertFalse(testFile.exists()); assertTrue(localTempPath.toFile().exists()); }
/** * Deletes a local test directory with a test file. * * @throws IOException if fails to create a local test file */ @Test public void testDeleteDirectoryIgnoreException() throws IOException { File testFile = createLocalFile(localTempPath.toString(), "SOME_FILE", FILE_SIZE_1_KB); HerdFileUtils.deleteDirectoryIgnoreException(localTempPath.toFile()); assertFalse(testFile.exists()); assertFalse(localTempPath.toFile().exists()); }
/** * Deletes a local test file. * * @throws IOException if fails to create a local test file */ @Test public void testDeleteFileIgnoreException() throws IOException { File testFile = createLocalFile(localTempPath.toString(), "SOME_FILE", FILE_SIZE_1_KB); HerdFileUtils.deleteFileIgnoreException(testFile); assertFalse(testFile.exists()); assertTrue(localTempPath.toFile().exists()); }
/** * Tries to delete a directory which is actually a file. */ @Test public void testDeleteDirectoryIgnoreExceptionWithException() throws Exception { final File testFile = createLocalFile(localTempPath.toString(), "SOME_FILE", FILE_SIZE_1_KB); executeWithoutLogging(HerdFileUtils.class, new Command() { @Override public void execute() throws Exception { HerdFileUtils.deleteDirectoryIgnoreException(testFile); } }); assertTrue(testFile.exists()); }
@Test public void testVerifyFileExistsAndReadableFileNotReadable() throws IOException { File testFile = createLocalFile(localTempPath.toString(), "SOME_FILE", FILE_SIZE_1_KB); if (testFile.setReadable(false)) { try { HerdFileUtils.verifyFileExistsAndReadable(testFile); fail("Should throw an IllegalArgumentException when file is not readable."); } catch (IllegalArgumentException e) { assertEquals(String.format("Unable to read file \"%s\". Check permissions.", testFile.getName()), e.getMessage()); } } }
/** * Tries to clean a directory which is actually a file. */ @Test public void testCleanDirectoryIgnoreExceptionWithException() throws Exception { final File testFile = createLocalFile(localTempPath.toString(), "SOME_FILE", FILE_SIZE_1_KB); executeWithoutLogging(HerdFileUtils.class, new Command() { @Override public void execute() throws Exception { HerdFileUtils.cleanDirectoryIgnoreException(testFile); } }); assertTrue(testFile.exists()); }