Split up FilePathHelperTest tests in simpler methods

This commit is contained in:
Alireza Tofighi 2021-05-21 22:44:38 +04:30
parent 067528211f
commit e8ad947d37

View file

@ -1,5 +1,6 @@
package org.schabi.newpipe.util; package org.schabi.newpipe.util;
import org.junit.Before;
import org.junit.Test; import org.junit.Test;
import java.io.File; import java.io.File;
@ -10,28 +11,44 @@ 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;
@Before
public void setUp() throws IOException {
dir = Files.createTempDirectory("dir1").toFile();
}
@Test @Test
public void testIsValidDirectoryPath() throws IOException { public void testIsValidDirectoryPathWithEmptyString() {
// empty path is not valid
assertFalse(FilePathUtils.isValidDirectoryPath("")); assertFalse(FilePathUtils.isValidDirectoryPath(""));
}
// null path is not valid @Test
public void testIsValidDirectoryPathWithNullString() {
assertFalse(FilePathUtils.isValidDirectoryPath(null)); assertFalse(FilePathUtils.isValidDirectoryPath(null));
}
// path that exists @Test
final File dir1 = Files.createTempDirectory("dir1").toFile(); public void testIsValidDirectoryPathWithValidPath() {
assertTrue(FilePathUtils.isValidDirectoryPath(dir1.getAbsolutePath())); assertTrue(FilePathUtils.isValidDirectoryPath(dir.getAbsolutePath()));
}
// a directory in above path that exists @Test
final File subDir = Files.createDirectory(dir1.toPath().resolve("subdir")).toFile(); public void testIsValidDirectoryPathWithDeepValidDirectory() throws IOException {
final File subDir = Files.createDirectory(dir.toPath().resolve("subdir")).toFile();
assertTrue(FilePathUtils.isValidDirectoryPath(subDir.getAbsolutePath())); assertTrue(FilePathUtils.isValidDirectoryPath(subDir.getAbsolutePath()));
}
// a directory in above path that doesn't exist @Test
assertFalse(FilePathUtils.isValidDirectoryPath(dir1.toPath().resolve("not-exists-subdir"). public void testIsValidDirectoryPathWithNotExistDirectory() {
assertFalse(FilePathUtils.isValidDirectoryPath(dir.toPath().resolve("not-exists-subdir").
toFile().getAbsolutePath())); toFile().getAbsolutePath()));
}
// file is not a valid direcotry path @Test
final File tempFile = Files.createFile(dir1.toPath().resolve("simple_file")).toFile(); public void testIsValidDirectoryPathWithFile() throws IOException {
final File tempFile = Files.createFile(dir.toPath().resolve("simple_file")).toFile();
assertFalse(FilePathUtils.isValidDirectoryPath(tempFile.getAbsolutePath())); assertFalse(FilePathUtils.isValidDirectoryPath(tempFile.getAbsolutePath()));
} }