aboutsummaryrefslogtreecommitdiff
path: root/src/test
diff options
context:
space:
mode:
authorj-james2022-10-29 04:38:39 +0000
committerj-james2022-10-29 04:38:39 +0000
commitfb04947b701d80cd9730e3aa0b7afe7a4bb196f6 (patch)
tree4d6ecccd23eb9d2a4247069912b2cb00c5412d84 /src/test
parent106a0fe85effd27f8da28d17cf1053d5c50cd5fc (diff)
Add persistance tests
Diffstat (limited to 'src/test')
-rw-r--r--src/test/persistance/JsonUtilsTest.java36
1 files changed, 36 insertions, 0 deletions
diff --git a/src/test/persistance/JsonUtilsTest.java b/src/test/persistance/JsonUtilsTest.java
new file mode 100644
index 0000000..9ab9b1c
--- /dev/null
+++ b/src/test/persistance/JsonUtilsTest.java
@@ -0,0 +1,36 @@
+package persistance;
+
+import org.json.JSONArray;
+import org.json.JSONObject;
+import org.junit.jupiter.api.Test;
+
+import java.util.ArrayDeque;
+
+import static org.junit.jupiter.api.Assertions.*;
+
+public class JsonUtilsTest {
+ private static final String testPath = "data/test.cache";
+
+ @Test
+ void testWritingEmptyFile() {
+ ArrayDeque<String> test = new ArrayDeque<>();
+ JsonUtils.writeToFile(new JSONArray(test), testPath);
+
+ JSONArray dugUp = JsonUtils.readFromFile(testPath);
+ assertTrue(dugUp.isEmpty());
+ }
+
+ @Test
+ void testWritingLists() {
+ ArrayDeque<String> test = new ArrayDeque<>();
+ test.add("/home/apropos/foo/bar"); // absolute path
+ test.add("data"); // relative path
+ test.add("/home/apropos/baz/bar"); // another path
+ JsonUtils.writeToFile(new JSONArray(test), testPath);
+
+ JSONArray dugUp = JsonUtils.readFromFile(testPath);
+ for (int i = 0; i < dugUp.length(); i++) {
+ assertTrue(test.removeFirst().equals(dugUp.get(i)));
+ }
+ }
+}