From ed7b67f19c3d4a464b5b7e3a1ab97bf57220f0e2 Mon Sep 17 00:00:00 2001 From: Kevin Kraus Date: Fri, 6 Sep 2019 22:44:56 -0500 Subject: [PATCH] BAEL-3227 fixed tests --- .../baeldung/files/CreatingFilesUnitTest.java | 16 ++++++++++++---- 1 file changed, 12 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 1f2c1ec505..175a0001f1 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 @@ -4,6 +4,8 @@ import org.junit.Test; import java.io.File; import java.io.IOException; +import static org.junit.Assert.assertTrue; + public class CreateFilesUnitTest { @Test(expected = IOException.class) public void whenCreatingAFileWithAbsolutePath_thenExceptionIsThrown() throws IOException { @@ -12,18 +14,24 @@ public class CreateFilesUnitTest { Files.touch(fileWithAbsolutePath); } - @Test(expected = IOException.class) - public void givenAnExistingDirectory_whenCreatingANewDirectoryAndFile_thenExceptionIsThrown() throws IOException { + @Test + public void givenAnExistingDirectory_whenCreatingANewDirectoryAndFile_thenFileIsCreated() throws IOException { File tempDirectory = new File(System.getProperty("java.io.tmpdir")); File fileWithRelativePath = new File(tempDirectory, "myDirectory/newFile.txt"); + fileWithRelativePath.mkdirs(); Files.touch(fileWithRelativePath); + + assertTrue(fileWithRelativePath.exists()); } - @Test(expected = IOException.class) - public void whenCreatingAFileWithFileSeparator_thenPathIsCreated() throws IOException { + @Test + public void whenCreatingAFileWithFileSeparator_thenFileIsCreated() throws IOException { File newFile = new File("src" + File.separator + "test" + File.separator + "resources" + File.separator + "newFile.txt"); + newFile.mkdirs(); Files.touch(newFile); + + assertTrue(newFile.exists()); } }