forked from markusgeorge1207/ProgrammingGit
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathTester.java
More file actions
118 lines (96 loc) · 3.43 KB
/
Tester.java
File metadata and controls
118 lines (96 loc) · 3.43 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
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
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 Tester {
@BeforeAll
static void setUpBeforeClass() throws Exception {
/*
* Utils.writeStringToFile("junit_example_file_data.txt", "test file contents");
*
*/
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();
PrintWriter pw = new PrintWriter(new BufferedWriter(new FileWriter("milo")));
pw.print("Milo is adorable.");
pw.close();
}
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();
}
@AfterAll
static void tearDownAfterClass() throws Exception {
/*
* Utils.deleteFile("junit_example_file_data.txt");
* Utils.deleteFile("index");
* Utils.deleteDirectory("objects");
*/
File milo = new File("milo");
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 {
// Run the person's code
// TestHelper.runTestSuiteMethods("testInitialize");
// check if the file exists
File file = new File("index");
Path path = Paths.get("objects");
assertTrue(file.exists());
assertTrue(Files.exists(path));
}
@Test
@DisplayName("[15] Test if adding a blob works. 5 for sha, 5 for file contents, 5 for correct location")
void testCreateBlob() throws Exception {
try {
// Manually create the files and folders before the 'testAddFile'
// MyGitProject myGitClassInstance = new MyGitProject();
// myGitClassInstance.init();
// TestHelper.runTestSuiteMethods("testCreateBlob", file1.getName());
} catch (Exception e) {
System.out.println("An error occurred: " + e.getMessage());
}
// Check blob exists in the objects folder
File file_junit1 = new File("objects/" + file1.methodToGetSha1());
assertTrue("Blob file to add not found", file_junit1.exists());
// Read file contents
String indexFileContents = MyUtilityClass.readAFileToAString("objects/" + file1.methodToGetSha1());
assertEquals("File contents of Blob don't match file contents pre-blob creation", indexFileContents,
file1.getContents());
}
}