From 7d85a2215e5ebe2db02338d1d48e9b9a03337aba Mon Sep 17 00:00:00 2001 From: Guillaume R Date: Sat, 23 Mar 2019 18:24:40 +0100 Subject: [PATCH] Test enums with json --- .../nightconfig/json/JsonConfigTest.java | 18 ++++++++---------- json/test.json | 3 ++- 2 files changed, 10 insertions(+), 11 deletions(-) diff --git a/json/src/test/java/com/electronwill/nightconfig/json/JsonConfigTest.java b/json/src/test/java/com/electronwill/nightconfig/json/JsonConfigTest.java index ef6f293d..e9768e9b 100644 --- a/json/src/test/java/com/electronwill/nightconfig/json/JsonConfigTest.java +++ b/json/src/test/java/com/electronwill/nightconfig/json/JsonConfigTest.java @@ -1,27 +1,21 @@ package com.electronwill.nightconfig.json; import com.electronwill.nightconfig.core.Config; +import com.electronwill.nightconfig.core.TestEnum; import com.electronwill.nightconfig.core.file.FileConfig; import com.electronwill.nightconfig.core.file.FileNotFoundAction; import com.electronwill.nightconfig.core.io.IndentStyle; import com.electronwill.nightconfig.core.io.ParsingException; import com.electronwill.nightconfig.core.io.WritingMode; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; -import java.io.BufferedWriter; -import java.io.File; -import java.io.FileOutputStream; -import java.io.IOException; -import java.io.OutputStreamWriter; -import java.io.StringWriter; -import java.io.Writer; +import java.io.*; import java.nio.charset.StandardCharsets; import java.nio.file.Files; import java.util.Arrays; import java.util.List; -import org.junit.jupiter.api.Assertions; -import org.junit.jupiter.api.Test; - import static org.junit.jupiter.api.Assertions.*; /** @@ -43,6 +37,7 @@ public class JsonConfigTest { config.set("config", config2); config.set("list", Arrays.asList("a", "b", 3, null, true, false, 17.5)); config.set("null", null); + config.set("enum", TestEnum.A); } private final File file = new File("test.json"); @@ -72,9 +67,12 @@ public void testWriteThenRead() throws IOException { writer.write(config, file, WritingMode.REPLACE); Config read = new JsonParser().parse(file, FileNotFoundAction.THROW_ERROR); + assertEquals(TestEnum.A, read.getEnum("enum", TestEnum.class)); System.out.println("config: " + config); System.out.println("read: " + read); + + assertEquals(read.toString(), config.toString()); } @Test diff --git a/json/test.json b/json/test.json index 9a0a1957..1805a4db 100644 --- a/json/test.json +++ b/json/test.json @@ -17,5 +17,6 @@ "false": false }, "int": 123456, - "long": 1234567890 + "long": 1234567890, + "enum": "A" } \ No newline at end of file