From 2a7f9f6edef83a6f979085e4917299e61d757de4 Mon Sep 17 00:00:00 2001 From: Kevin Kraus Date: Sun, 8 Sep 2019 22:00:47 -0500 Subject: [PATCH] improving absolute path test --- .../com/baeldung/files/CreatingFilesUnitTest.java | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/core-java-modules/core-java/src/test/java/com/baeldung/files/CreatingFilesUnitTest.java b/core-java-modules/core-java/src/test/java/com/baeldung/files/CreatingFilesUnitTest.java index 031d641ffc..f2216f58c7 100644 --- a/core-java-modules/core-java/src/test/java/com/baeldung/files/CreatingFilesUnitTest.java +++ b/core-java-modules/core-java/src/test/java/com/baeldung/files/CreatingFilesUnitTest.java @@ -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");