1
0
mirror of https://github.com/TeamNewPipe/NewPipe synced 2024-06-29 00:23:22 +00:00

Remove unnecessary conversion between file and path

This commit is contained in:
XiangRongLin 2021-05-21 20:24:11 +02:00
parent e8ad947d37
commit 376e5c1546

View File

@ -6,17 +6,18 @@ import org.junit.Test;
import java.io.File; import java.io.File;
import java.io.IOException; import java.io.IOException;
import java.nio.file.Files; import java.nio.file.Files;
import java.nio.file.Path;
import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue; import static org.junit.Assert.assertTrue;
public class FilePathHelperTest { public class FilePathHelperTest {
private File dir; private Path dir;
@Before @Before
public void setUp() throws IOException { public void setUp() throws IOException {
dir = Files.createTempDirectory("dir1").toFile(); dir = Files.createTempDirectory("dir1");
} }
@Test @Test
@ -31,24 +32,24 @@ public class FilePathHelperTest {
@Test @Test
public void testIsValidDirectoryPathWithValidPath() { public void testIsValidDirectoryPathWithValidPath() {
assertTrue(FilePathUtils.isValidDirectoryPath(dir.getAbsolutePath())); assertTrue(FilePathUtils.isValidDirectoryPath(dir.toAbsolutePath().toString()));
} }
@Test @Test
public void testIsValidDirectoryPathWithDeepValidDirectory() throws IOException { public void testIsValidDirectoryPathWithDeepValidDirectory() throws IOException {
final File subDir = Files.createDirectory(dir.toPath().resolve("subdir")).toFile(); final File subDir = Files.createDirectory(dir.resolve("subdir")).toFile();
assertTrue(FilePathUtils.isValidDirectoryPath(subDir.getAbsolutePath())); assertTrue(FilePathUtils.isValidDirectoryPath(subDir.getAbsolutePath()));
} }
@Test @Test
public void testIsValidDirectoryPathWithNotExistDirectory() { public void testIsValidDirectoryPathWithNotExistDirectory() {
assertFalse(FilePathUtils.isValidDirectoryPath(dir.toPath().resolve("not-exists-subdir"). assertFalse(FilePathUtils.isValidDirectoryPath(dir.resolve("not-exists-subdir").
toFile().getAbsolutePath())); toFile().getAbsolutePath()));
} }
@Test @Test
public void testIsValidDirectoryPathWithFile() throws IOException { public void testIsValidDirectoryPathWithFile() throws IOException {
final File tempFile = Files.createFile(dir.toPath().resolve("simple_file")).toFile(); final File tempFile = Files.createFile(dir.resolve("simple_file")).toFile();
assertFalse(FilePathUtils.isValidDirectoryPath(tempFile.getAbsolutePath())); assertFalse(FilePathUtils.isValidDirectoryPath(tempFile.getAbsolutePath()));
} }