Add tests for generateTree

This commit is contained in:
Oystein Kristoffer Tveit 2021-04-25 22:21:06 +02:00
parent f89968d9d0
commit da02308498

View File

@ -4,24 +4,64 @@ import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.junit.jupiter.api.Assertions.fail;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.List;
import java.util.Optional;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.io.TempDir;
import org.mockito.MockedStatic;
import org.mockito.Mockito;
import app.model.Model;
import javafx.scene.control.CheckBoxTreeItem;
import javafx.scene.control.TreeItem;
public class FileTreeOperationsTest {
@TempDir
File tmp;
private void populateTmpDir() throws IOException {
List<String> files = List.of(
"test.java",
"test.md",
"test.txt",
"test.unknown"
);
for (String f : files) {
new File(tmp, f).createNewFile();
}
}
private void createRecursiveSymlink() throws IOException {
File folders = new File(tmp, "test/innerFolder/");
folders.mkdirs();
Path target = Paths.get(tmp.toPath().toString(), "test");
Path link = Paths.get(tmp.toPath().toString(), "test/innerFolder/test");
Files.createSymbolicLink(link, target);
}
@Test
@DisplayName("Test generateTree")
public void testGenerateTree() {
try {
populateTmpDir();
createRecursiveSymlink();
CheckBoxTreeItem<String> parent = new CheckBoxTreeItem<>("Parent");
FiletreeOperations.generateTree(tmp, parent);
} catch (IOException e) {
fail(e);
}
}
@ -29,7 +69,6 @@ public class FileTreeOperationsTest {
Path traversalPath = filePath;
TreeItem<String> child = file;
while (!traversalPath.equals(root)) {
System.out.println(traversalPath);
traversalPath = traversalPath.getParent();
TreeItem<String> parent = new TreeItem<>(traversalPath.getFileName().toString());
parent.getChildren().add(child);