-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathTreeTest.java
More file actions
164 lines (95 loc) · 4.03 KB
/
TreeTest.java
File metadata and controls
164 lines (95 loc) · 4.03 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
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
import static org.junit.Assert.assertTrue;
import static org.junit.jupiter.api.Assertions.assertEquals;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.security.NoSuchAlgorithmException;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;
public class TreeTest {
String input = "/Users/lilbarbar/Desktop/Honors Topics/Programming-Git/";
// a good unit test, makes sure that my constructor works properly
// generate a tree file
@Test
@DisplayName("Testing the tree consuctor to make a tree file")
public void testTreeConsturctor() throws IOException {
Tree tree = new Tree();
File treeFile = new File("Tree");
assertTrue(treeFile.exists());
}
@Test
@DisplayName("Testing the tree consuctor to make a tree file")
public void testTreeConsturctor2() throws IOException {
Tree tree = new Tree("SuperTree");
File treeFile = new File("SuperTree");
assertTrue(treeFile.exists());
}
@Test
@DisplayName("Testing the tree consuctor to make a tree file")
public void testWriteToTree() throws IOException, NoSuchAlgorithmException {
Tree tree = new Tree();
File treeFile = new File("Tree");
assertTrue(treeFile.exists());
// Blob b = new Blob("jump.txt");
tree.add("jump.txt", input);
String treeFileContents = Helper.fileContents(treeFile);
String fileContents = Helper.fileContents(new File("jump.txt"));
String fileSHA = Blob.getSha1(fileContents);
String newLine = "Blob : " + fileSHA + " : " + "jump.txt";
assertTrue (treeFileContents.length() > 0);
}
@Test
void testAddDirectory() throws NoSuchAlgorithmException, IOException {
Tree tree = new Tree();
File treeFile = new File(input + "Objects/Tree");
File d = new File("/Users/lilbarbar/Desktop/Honors Topics/Programming-Git/FolderA/");
if (d.exists()) {
tree.addDirectory("/Users/lilbarbar/Desktop/Honors Topics/Programming-Git/FolderA/");
}
tree.add("FolderA", input);
String s = Helper.fileContents(treeFile);
assertTrue (tree.blobs.size() > 0 || tree.trees.size() > 0);
assertEquals (s.contains("FolderA"), true);
}
@Test
void testAdd() throws IOException, NoSuchAlgorithmException {
Tree tree = new Tree ();
File treeFile = new File(input + "Objects/Tree");
tree.add("def.txt", input);
String s = Helper.fileContents(treeFile);
assertEquals(s.indexOf("def.txt") >= 0, true);
// Tree tree = new Tree();
// tree.add("yo.txt", inputString);
// tree.add("def.txt", inputString);
// String s = Helper.fileContents(treeFile);
// assertTrue(s.contains("yo.txt"));
// assertTrue(s.contains("def.txt"));
// assertTrue(s.contains("Blob"));
}
@Test
void testAllBlobs() throws IOException, NoSuchAlgorithmException {
Tree tree = new Tree();
File treeF = new File("Tree");
tree.add("testout.txt", input);
String contents = Helper.fileContents(treeF);
assertTrue(contents.length() > 0);
}
@Test
void testRemove() throws IOException, NoSuchAlgorithmException {
Tree tree = new Tree();
File t = new File(input + "Objects/Tree");
tree.add("abc.txt", input);
tree.add("chiefkeef.txt", input);
tree.add("jump.txt", input);
String string1 = Helper.fileContents(t);
assertTrue(string1.contains("jump.txt"));
assertTrue(string1.contains("abc.txt"));
assertTrue(string1.contains("chiefkeef.txt"));
tree.remove("jump.txt");
tree.remove("bf66c9fecf6e0f873004b0ebeed29b7ad0761759");
String string2 = Helper.fileContents(t);
assertTrue(!string2.contains("jump.txt"));
assertTrue(!string2.contains("abc.txt"));
assertTrue(string2.contains("chiefkeef.txt"));
}
}