/** Returns a {@code File} object for the given path parts. */ private static File file(String first, String... more) { return file(new File(first), more); }
public void testCreateParentDirs_relativePath() throws IOException { File file = file("nonexistent.file"); assertNull(file.getParentFile()); assertNotNull(file.getCanonicalFile().getParentFile()); Files.createParentDirs(file); }
public void testCopyEqualFiles() throws IOException { File temp1 = createTempFile(); File temp2 = file(temp1.getPath()); assertEquals(temp1, temp2); Files.write(ASCII, temp1, Charsets.UTF_8); try { Files.copy(temp1, temp2); fail("Expected an IAE to be thrown but wasn't"); } catch (IllegalArgumentException expected) { } assertEquals(ASCII, Files.toString(temp1, Charsets.UTF_8)); }
public void testCreateParentDirs_multipleParentsNeeded() throws IOException { File file = file(getTempDir(), "grandparent", "parent", "nonexistent.file"); File parent = file.getParentFile(); File grandparent = parent.getParentFile(); assertFalse(grandparent.exists()); Files.createParentDirs(file); assertTrue(parent.exists()); }
public void testCreateParentDirs_noParentsNeeded() throws IOException { File file = file(getTempDir(), "nonexistent.file"); assertTrue(file.getParentFile().exists()); Files.createParentDirs(file); }
public void testCreateParentDirs_oneParentNeeded() throws IOException { File file = file(getTempDir(), "parent", "nonexistent.file"); File parent = file.getParentFile(); assertFalse(parent.exists()); try { Files.createParentDirs(file); assertTrue(parent.exists()); } finally { assertTrue(parent.delete()); } }
public void testCreateParentDirs_nonDirectoryParentExists() throws IOException { File parent = getTestFile("ascii.txt"); assertTrue(parent.isFile()); File file = file(parent, "foo"); try { Files.createParentDirs(file); fail(); } catch (IOException expected) { } }
/** * Returns a {@code File} object for the given path parts. */ private static File file(String first, String... more) { return file(new File(first), more); }
public void testCreateParentDirs_relativePath() throws IOException { File file = file("nonexistent.file"); assertNull(file.getParentFile()); assertNotNull(file.getCanonicalFile().getParentFile()); Files.createParentDirs(file); }
public void testCopyEqualFiles() throws IOException { File temp1 = createTempFile(); File temp2 = file(temp1.getPath()); assertEquals(temp1, temp2); Files.write(ASCII, temp1, Charsets.UTF_8); try { Files.copy(temp1, temp2); fail("Expected an IAE to be thrown but wasn't"); } catch (IllegalArgumentException expected) { } assertEquals(ASCII, Files.toString(temp1, Charsets.UTF_8)); }
public void testCreateParentDirs_noParentsNeeded() throws IOException { File file = file(getTempDir(), "nonexistent.file"); assertTrue(file.getParentFile().exists()); Files.createParentDirs(file); }
public void testCreateParentDirs_multipleParentsNeeded() throws IOException { File file = file(getTempDir(), "grandparent", "parent", "nonexistent.file"); File parent = file.getParentFile(); File grandparent = parent.getParentFile(); assertFalse(grandparent.exists()); Files.createParentDirs(file); assertTrue(parent.exists()); }
public void testCreateParentDirs_oneParentNeeded() throws IOException { File file = file(getTempDir(), "parent", "nonexistent.file"); File parent = file.getParentFile(); assertFalse(parent.exists()); try { Files.createParentDirs(file); assertTrue(parent.exists()); } finally { assertTrue(parent.delete()); } }
public void testCreateParentDirs_nonDirectoryParentExists() throws IOException { File parent = getTestFile("ascii.txt"); assertTrue(parent.isFile()); File file = file(parent, "foo"); try { Files.createParentDirs(file); fail(); } catch (IOException expected) { } }