From 49606337a5a30edeafbc25b80f01cfa5aa9b6b4a Mon Sep 17 00:00:00 2001 From: Kevin Kraus Date: Fri, 6 Sep 2019 22:20:33 -0500 Subject: [PATCH] BAEL-3227 --- .../com/baeldung/files/CreatingFilesTest.java | 29 +++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 core-java-modules/core-java/src/test/java/com/baeldung/files/CreatingFilesTest.java diff --git a/core-java-modules/core-java/src/test/java/com/baeldung/files/CreatingFilesTest.java b/core-java-modules/core-java/src/test/java/com/baeldung/files/CreatingFilesTest.java new file mode 100644 index 0000000000..1380846e24 --- /dev/null +++ b/core-java-modules/core-java/src/test/java/com/baeldung/files/CreatingFilesTest.java @@ -0,0 +1,29 @@ +import com.google.common.io.Files; +import org.junit.Test; + +import java.io.File; +import java.io.IOException; + +public class CreateFilesTest { + @Test(expected = IOException.class) + public void whenCreatingAFileWithAbsolutePath_thenExceptionIsThrown() throws IOException { + File fileWithAbsolutePath = new File("/myDirectory/testFile.txt"); + + Files.touch(fileWithAbsolutePath); + } + + @Test(expected = IOException.class) + public void givenAnExistingDirectory_whenCreatingANewDirectoryAndFile_thenExceptionIsThrown() throws IOException { + File tempDirectory = new File(System.getProperty("java.io.tmpdir")); + File fileWithRelativePath = new File(tempDirectory, "myDirectory/newFile.txt"); + + Files.touch(fileWithRelativePath); + } + + @Test(expected = IOException.class) + public void whenCreatingAFileWithFileSeparator_thenPathIsCreated() throws IOException { + File newFile = new File("src" + File.separator + "test" + File.separator + "resources" + File.separator + "newFile.txt"); + + Files.touch(newFile); + } +}