Add file to Path and Path to File testing

This commit is contained in:
YuCheng Hu 2020-10-13 15:01:44 -04:00
parent c312351b6e
commit 7742a30a4b

View File

@ -1,16 +1,15 @@
package com.ossez.java.nio2; package com.ossez.java.nio2;
import static org.junit.Assert.assertEquals; import org.junit.Test;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import java.io.File;
import java.io.IOException; import java.io.IOException;
import java.net.URI; import java.net.URI;
import java.nio.file.NoSuchFileException; import java.nio.file.NoSuchFileException;
import java.nio.file.Path; import java.nio.file.Path;
import java.nio.file.Paths; import java.nio.file.Paths;
import org.junit.Test; import static org.junit.Assert.*;
public class PathManualTest { public class PathManualTest {
@ -191,4 +190,21 @@ public class PathManualTest {
Path p1 = Paths.get("/baeldung/articles"); Path p1 = Paths.get("/baeldung/articles");
assertTrue(p1.endsWith("articles")); assertTrue(p1.endsWith("articles"));
} }
@Test
public void getFileToPath() {
// Convert File to Path
File file = new File("/home/cwikius/test/file.txt");
Path path = file.toPath();
assertNotNull(path);
}
@Test
public void getPathToFile() {
// Convert Path to File
Path path = Paths.get("/home/cwikius/test/file.txt");
File file = path.toFile();
assertNotNull(file);
}
} }