forked from markusgeorge1207/ProgrammingGit
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathIndexTester.java
More file actions
90 lines (70 loc) · 2.17 KB
/
IndexTester.java
File metadata and controls
90 lines (70 loc) · 2.17 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
import static org.junit.Assert.*;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileWriter;
import java.io.PrintWriter;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.LinkedHashMap;
import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;
public class IndexTester {
static String testFileContents = "Milo is adorable.";
public static void deleteDir(File file) {
File[] contents = file.listFiles();
if (contents != null) {
for (File f : contents) {
if (!Files.isSymbolicLink(f.toPath())) {
deleteDir(f);
}
}
}
file.delete();
}
@BeforeAll
static void setUpBeforeClass() throws Exception {
File objects = new File("objects");
File[] contents = objects.listFiles();
if (contents != null) {
for (File f : contents) {
deleteDir(f);
}
}
objects.delete();
File index = new File("index");
index.delete();
Path pathObject = Paths.get("./milo.txt");
Files.createFile(pathObject);
FileWriter fw = new FileWriter("./milo.txt");
fw.write(testFileContents);
fw.close();
}
@AfterAll
static void tearDownAfterClass() throws Exception {
File milo = new File("milo.txt");
milo.delete();
File objects = new File("objects");
File[] contents = objects.listFiles();
if (contents != null) {
for (File f : contents) {
deleteDir(f);
}
}
objects.delete();
File index = new File("index");
index.delete();
}
@Test
@DisplayName("[8] Test if initialize and objects are created correctly")
void testInitialize() throws Exception {
Index index = new Index();
index.initProject();
File file = new File("index");
Path path = Paths.get("objects");
assertTrue(file.exists());
assertTrue(Files.exists(path));
}
}