Move ContentSettingsFragment.isValidPath to helpers and add unit test for it.

This commit is contained in:
Alireza Tofighi 2021-05-21 20:21:58 +04:30
parent 82f43ac6a6
commit fa2b11b768
3 changed files with 57 additions and 10 deletions

View file

@ -0,0 +1,32 @@
package org.schabi.newpipe.util;
import org.junit.Test;
import java.io.File;
import java.io.IOException;
import java.nio.file.Files;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
public class FilePathHelperTest {
@Test
public void testIsValidDirectoryPath() throws IOException {
// path that exists
final File dir1 = Files.createTempDirectory("dir1").toFile();
assertTrue(FilePathUtils.isValidDirectoryPath(dir1.getAbsolutePath()));
// a directory in above path that exists
final File subDir = Files.createDirectory(dir1.toPath().resolve("subdir")).toFile();
assertTrue(FilePathUtils.isValidDirectoryPath(subDir.getAbsolutePath()));
// a directory in above path that doesn't exist
assertFalse(FilePathUtils.isValidDirectoryPath(dir1.toPath().resolve("not-exists-subdir").
toFile().getAbsolutePath()));
// file is not a valid direcotry path
final File tempFile = Files.createFile(dir1.toPath().resolve("simple_file")).toFile();
assertFalse(FilePathUtils.isValidDirectoryPath(tempFile.getAbsolutePath()));
}
}