improving absolute path test

This commit is contained in:
Kevin Kraus 2019-09-08 22:00:47 -05:00
parent 0eac69ca79
commit 2a7f9f6ede
1 changed files with 8 additions and 4 deletions

View File

@ -9,15 +9,19 @@ import java.io.IOException;
import static org.junit.Assert.assertTrue;
public class CreateFilesUnitTest {
@Test(expected = IOException.class)
public void whenCreatingAFileWithAbsolutePath_thenExceptionIsThrown() throws IOException {
File fileWithAbsolutePath = new File("/myDirectory/testFile.txt");
@Test
public void givenAnExistingDirectory_whenCreatingAFileWithAbsolutePath_thenFileIsCreated() throws IOException {
File tempDirectory = new File(System.getProperty("java.io.tmpdir"));
File fileWithAbsolutePath = new File(tempDirectory.getAbsolutePath() + "/myDirectory/testFile.txt");
fileWithAbsolutePath.mkdirs();
Files.touch(fileWithAbsolutePath);
assertTrue(fileWithAbsolutePath.exists());
}
@Test
public void givenAnExistingDirectory_whenCreatingANewDirectoryAndFile_thenFileIsCreated() throws IOException {
public void givenAnExistingDirectory_whenCreatingANewDirectoryAndFileWithRelativePath_thenFileIsCreated() throws IOException {
File tempDirectory = new File(System.getProperty("java.io.tmpdir"));
File fileWithRelativePath = new File(tempDirectory, "myDirectory/newFile.txt");