Add tests for generateTree
This commit is contained in:
parent
f89968d9d0
commit
da02308498
@ -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.assertThrows;
|
||||||
import static org.junit.jupiter.api.Assertions.fail;
|
import static org.junit.jupiter.api.Assertions.fail;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
import java.io.FileNotFoundException;
|
import java.io.FileNotFoundException;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.nio.file.Files;
|
||||||
import java.nio.file.Path;
|
import java.nio.file.Path;
|
||||||
import java.nio.file.Paths;
|
import java.nio.file.Paths;
|
||||||
|
import java.util.List;
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
|
|
||||||
import org.junit.jupiter.api.DisplayName;
|
import org.junit.jupiter.api.DisplayName;
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
import org.junit.jupiter.api.io.TempDir;
|
||||||
import org.mockito.MockedStatic;
|
import org.mockito.MockedStatic;
|
||||||
import org.mockito.Mockito;
|
import org.mockito.Mockito;
|
||||||
|
|
||||||
import app.model.Model;
|
import app.model.Model;
|
||||||
|
import javafx.scene.control.CheckBoxTreeItem;
|
||||||
import javafx.scene.control.TreeItem;
|
import javafx.scene.control.TreeItem;
|
||||||
|
|
||||||
public class FileTreeOperationsTest {
|
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
|
@Test
|
||||||
@DisplayName("Test generateTree")
|
@DisplayName("Test generateTree")
|
||||||
public void testGenerateTree() {
|
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;
|
Path traversalPath = filePath;
|
||||||
TreeItem<String> child = file;
|
TreeItem<String> child = file;
|
||||||
while (!traversalPath.equals(root)) {
|
while (!traversalPath.equals(root)) {
|
||||||
System.out.println(traversalPath);
|
|
||||||
traversalPath = traversalPath.getParent();
|
traversalPath = traversalPath.getParent();
|
||||||
TreeItem<String> parent = new TreeItem<>(traversalPath.getFileName().toString());
|
TreeItem<String> parent = new TreeItem<>(traversalPath.getFileName().toString());
|
||||||
parent.getChildren().add(child);
|
parent.getChildren().add(child);
|
||||||
|
Loading…
Reference in New Issue
Block a user