move to core-java-io

This commit is contained in:
Kevin Kraus
2019-09-10 20:47:13 -05:00
parent 9f2a9a9c36
commit 714e909e97

View File

@@ -0,0 +1,43 @@
package com.baeldung.createfiles;
import com.google.common.io.Files;
import org.junit.Test;
import java.io.File;
import java.io.IOException;
import static org.junit.Assert.assertTrue;
public class CreateFilesUnitTest {
@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_whenCreatingANewDirectoryAndFileWithRelativePath_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
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());
}
}