-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathIndexTest.java
More file actions
86 lines (77 loc) · 2.61 KB
/
IndexTest.java
File metadata and controls
86 lines (77 loc) · 2.61 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
import static org.junit.Assert.*;
import org.junit.jupiter.api.io.TempDir;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
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 IndexTest {
@Test
@DisplayName("Test if adding a blob works.")
void testAdd() throws Exception {
File file = new File("test.txt");
//Blob b = new Blob(file);
String contentsOfFile = "testing";
Files.write(file.toPath(), contentsOfFile.getBytes());
Index ind = new Index();
//File object = new File("index");
ind.addBlob("test.txt");
String ret = ind.fileToString("index");
assertTrue(ret.contains(Blob.encryptThisString(contentsOfFile)));
file.delete();
}
@Test
void testAddDirectory() throws Exception
{
File file = new File("Folder");
file.mkdir();
Index ind = new Index();
ind.addBlob("Folder");
String ret = ind.fileToString("index");
System.out.println(ret);
assertTrue(ret.equals("tree : da39a3ee5e6b4b0d3255bfef95601890afd80709 : Folder" + "\n"));
}
@Test
void testInit() throws Exception {
Index index = new Index();
index.init();
assertTrue(new File("index").exists());
}
@Test
void testRemoveBlob() throws Exception {
File file = new File("test.txt");
//Blob b = new Blob(file);
String contentsOfFile = "testing";
Files.write(file.toPath(), contentsOfFile.getBytes());
Index ind = new Index();
//File object = new File("index");
ind.addBlob("test.txt");
String ret = ind.fileToString("index");
assertTrue(ret.contains(Blob.encryptThisString(contentsOfFile)));
//file.delete();
ind.removeBlob("test.txt");
ret = ind.fileToString("index");
System.out.println(ret);
assertTrue(!ret.contains(Blob.encryptThisString(contentsOfFile)));
}
@Test
void testWriter() throws Exception {
Index ind = new Index();
File f = new File("test.txt");
f.createNewFile();
String contents = "testing";
FileWriter fw = new FileWriter(f);
fw.write(contents);
fw.close();
ind.addBlob("test.txt");
Index.writeInd();
String ret = ind.fileToString("index");
assertTrue(ret.contains(Blob.encryptThisString(contents)));
}
}