-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathTestUtils.java
More file actions
37 lines (33 loc) · 1 KB
/
TestUtils.java
File metadata and controls
37 lines (33 loc) · 1 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
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Paths;
public class TestUtils {
public void initialize() throws IOException {
File indexFile = new File("index");
indexFile.createNewFile();
Files.createDirectories(Paths.get("objects/"));
}
public void writeStringToFile(String path, String contents) throws IOException {
FileWriter fw = new FileWriter(path, false);
fw.write(contents);
fw.close();
}
public void deleteFile(String path) {
File file = new File(path);
file.delete();
}
public void deleteDirectory(String path) {
File file = new File(path);
File[] contents = file.listFiles();
if (contents != null) {
for (File f : contents) {
if (!Files.isSymbolicLink(f.toPath())) {
deleteDirectory(f.getPath());
}
}
}
file.delete();
}
}