forked from markusgeorge1207/ProgrammingGit
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathBlobTester.java
More file actions
93 lines (72 loc) · 2.46 KB
/
BlobTester.java
File metadata and controls
93 lines (72 loc) · 2.46 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
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 BlobTester {
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("[15] Test if adding a blob works. 5 for sha, 5 for file contents, 5 for correct location")
void testCreateBlob() throws Exception {
Blob b = new Blob("./milo.txt");
String sha = Utils.calculateSHA1(Utils.readFile("./milo.txt"));
// Check blob exists in the objects folder
File file_junit1 = new File("objects/" + sha);
assertTrue("Blob file to add not found", file_junit1.exists());
// Read file contents
assertEquals("File contents of Blob don't match file contents pre-blob creation", testFileContents,
Utils.readFile("./objects/" + sha));
}
}