This repository has been archived by the owner on Mar 5, 2023. It is now read-only.
/
JsonUtilTest.java
45 lines (31 loc) · 1.69 KB
/
JsonUtilTest.java
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
package seedu.address.commons.util;
import static org.junit.jupiter.api.Assertions.assertEquals;
import java.io.IOException;
import java.nio.file.Path;
import org.junit.jupiter.api.Test;
import seedu.address.testutil.SerializableTestClass;
import seedu.address.testutil.TestUtil;
/**
* Tests JSON Read and Write
*/
public class JsonUtilTest {
private static final Path SERIALIZATION_FILE = TestUtil.getFilePathInSandboxFolder("serialize.json");
@Test
public void serializeObjectToJsonFile_noExceptionThrown() throws IOException {
SerializableTestClass serializableTestClass = new SerializableTestClass();
serializableTestClass.setTestValues();
JsonUtil.serializeObjectToJsonFile(SERIALIZATION_FILE, serializableTestClass);
assertEquals(FileUtil.readFromFile(SERIALIZATION_FILE), SerializableTestClass.JSON_STRING_REPRESENTATION);
}
@Test
public void deserializeObjectFromJsonFile_noExceptionThrown() throws IOException {
FileUtil.writeToFile(SERIALIZATION_FILE, SerializableTestClass.JSON_STRING_REPRESENTATION);
SerializableTestClass serializableTestClass = JsonUtil
.deserializeObjectFromJsonFile(SERIALIZATION_FILE, SerializableTestClass.class);
assertEquals(serializableTestClass.getName(), SerializableTestClass.getNameTestValue());
assertEquals(serializableTestClass.getListOfLocalDateTimes(), SerializableTestClass.getListTestValues());
assertEquals(serializableTestClass.getMapOfIntegerToString(), SerializableTestClass.getHashMapTestValues());
}
//TODO: @Test jsonUtil_readJsonStringToObjectInstance_correctObject()
//TODO: @Test jsonUtil_writeThenReadObjectToJson_correctObject()
}