add asserts and use temp directory
This commit is contained in:
parent
714e909e97
commit
42b6bf5c02
|
@ -6,6 +6,7 @@ import org.junit.Test;
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
|
||||||
|
import static org.junit.Assert.assertFalse;
|
||||||
import static org.junit.Assert.assertTrue;
|
import static org.junit.Assert.assertTrue;
|
||||||
|
|
||||||
public class CreateFilesUnitTest {
|
public class CreateFilesUnitTest {
|
||||||
|
@ -14,7 +15,8 @@ public class CreateFilesUnitTest {
|
||||||
File tempDirectory = new File(System.getProperty("java.io.tmpdir"));
|
File tempDirectory = new File(System.getProperty("java.io.tmpdir"));
|
||||||
File fileWithAbsolutePath = new File(tempDirectory.getAbsolutePath() + "/myDirectory/testFile.txt");
|
File fileWithAbsolutePath = new File(tempDirectory.getAbsolutePath() + "/myDirectory/testFile.txt");
|
||||||
|
|
||||||
fileWithAbsolutePath.mkdirs();
|
assertFalse(fileWithAbsolutePath.exists());
|
||||||
|
|
||||||
Files.touch(fileWithAbsolutePath);
|
Files.touch(fileWithAbsolutePath);
|
||||||
|
|
||||||
assertTrue(fileWithAbsolutePath.exists());
|
assertTrue(fileWithAbsolutePath.exists());
|
||||||
|
@ -25,7 +27,8 @@ public class CreateFilesUnitTest {
|
||||||
File tempDirectory = new File(System.getProperty("java.io.tmpdir"));
|
File tempDirectory = new File(System.getProperty("java.io.tmpdir"));
|
||||||
File fileWithRelativePath = new File(tempDirectory, "myDirectory/newFile.txt");
|
File fileWithRelativePath = new File(tempDirectory, "myDirectory/newFile.txt");
|
||||||
|
|
||||||
fileWithRelativePath.mkdirs();
|
assertFalse(fileWithRelativePath.exists());
|
||||||
|
|
||||||
Files.touch(fileWithRelativePath);
|
Files.touch(fileWithRelativePath);
|
||||||
|
|
||||||
assertTrue(fileWithRelativePath.exists());
|
assertTrue(fileWithRelativePath.exists());
|
||||||
|
@ -33,9 +36,11 @@ public class CreateFilesUnitTest {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void whenCreatingAFileWithFileSeparator_thenFileIsCreated() throws IOException {
|
public void whenCreatingAFileWithFileSeparator_thenFileIsCreated() throws IOException {
|
||||||
File newFile = new File("src" + File.separator + "test" + File.separator + "resources" + File.separator + "newFile.txt");
|
File tempDirectory = new File(System.getProperty("java.io.tmpdir"));
|
||||||
|
File newFile = new File(tempDirectory.getAbsolutePath() + File.separator + "newFile.txt");
|
||||||
|
|
||||||
|
assertFalse(newFile.exists());
|
||||||
|
|
||||||
newFile.mkdirs();
|
|
||||||
Files.touch(newFile);
|
Files.touch(newFile);
|
||||||
|
|
||||||
assertTrue(newFile.exists());
|
assertTrue(newFile.exists());
|
||||||
|
|
Loading…
Reference in New Issue