forked from m4rkyma/Git
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGitTest.java
More file actions
64 lines (49 loc) · 1.86 KB
/
GitTest.java
File metadata and controls
64 lines (49 loc) · 1.86 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
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import org.junit.jupiter.api.Test;
public class GitTest {
@Test
void testAdd() throws IOException {
File testFile = new File("test.txt");
testFile.createNewFile();
// Call add method
Git.add("test.txt");
// Checks to see if index file has the text from test.txt inside it
String indexContents = Git.readFile("index");
assertTrue(indexContents.contains("test.txt"));
}
@Test
void testInitialize() throws IOException {
// Call init method
Git.initialize();
// Checks if index and objects were created
assertTrue(new File("index").isFile());
assertTrue(new File("objects").isDirectory());
}
@Test
void testReadFile() throws IOException {
File testFile = new File("test.txt");
String fileContent = "abcdefg"; // Makes a String for what we want to be inside of test.txt
try (FileWriter fw = new FileWriter(testFile)) {
fw.write(fileContent); // Writes the string to test.txt
}
String readContent = Git.readFile("test.txt"); // Reads through test.txt
assertEquals(fileContent, readContent); // Compares the 2 Strings
}
@Test
void testRemove() throws IOException {
File testFile = new File("test.txt");
testFile.createNewFile();
// Call add method on test.txt
Git.add("test.txt");
// Call remove method on test.txt
Git.remove("test.txt");
// Check if index has been correctly updated after calling remove on test.txt
String indexContents = Git.readFile("index");
assertTrue(!indexContents.contains("test.txt"));
}
}