From 1ea030e92afc09e104dc379a1ae0c0c00b8f0283 Mon Sep 17 00:00:00 2001 From: TheGatesScratch Date: Sat, 12 Nov 2022 16:20:27 +0100 Subject: [PATCH] Add more tests. --- .../com/thegates/maple/data/DataMapTest.java | 27 ++++++++++++------- 1 file changed, 18 insertions(+), 9 deletions(-) diff --git a/src/test/java/com/thegates/maple/data/DataMapTest.java b/src/test/java/com/thegates/maple/data/DataMapTest.java index ef29d5aa..4b82cd32 100644 --- a/src/test/java/com/thegates/maple/data/DataMapTest.java +++ b/src/test/java/com/thegates/maple/data/DataMapTest.java @@ -8,42 +8,51 @@ class DataMapTest { - private DataMap testMap; + private static DataMap testMap; @BeforeEach - void setUp() { + @Test + void put() { testMap = new DataMap(); - testMap.put("map_entry", new DataMap().put("nested_entry_1", new DataMap().put("nested_entry_2", new DataPrimitive(new Object())))); + testMap.put("map_entry", new DataMap().put("nested_entry_1", new DataMap().put("nested_entry_2", new DataPrimitive("test")))); testMap.put("list_entry", new DataList().add(new DataPrimitive(new Object()))); testMap.put("null_entry", new DataNull()); testMap.put("primitive_entry", new DataPrimitive(new Object())); } @Test - void requireKeys() { + void requireKeys_size() { assert testMap.hasKeys("map_entry", "list_entry", "null_entry", "primitive_entry"); + assert testMap.size() == 4; + assert testMap.get("map_entry").requireOf(DataMap.class).size() == 1; } @Test - void get() { + void get_is() { assert testMap.get("null_entry").isDataNull(); assert testMap.get("map_entry").isDataMap(); + assert testMap.get("list_entry").isDataList(); + assert testMap.get("primitive_entry").isDataPrimitive(); } @Test void navigate() { - assert testMap.navigate("map_entry", "nested_entry_1", "nested_entry_2").isDataPrimitive(); + assert testMap.navigate("map_entry", "nested_entry_1", "nested_entry_2").requireOf(DataPrimitive.class).requireValue(String.class).equals("test"); } + @Test + void parent() { + assert testMap.get("map_entry").parent() == testMap; + } @Test - void put() { - assert testMap.navigate("map_entry", "nested_entry_1", "nested_entry_2").parent() == testMap.navigate("map_entry", "nested_entry_1"); + void name() { + assert testMap.get("map_entry").name().equals("map_entry"); } @Test void read_hasKeys_requireOf() { - DataMap read = DataMap.read(Map.of("1", 1, "2", new DataList())); + final DataMap read = DataMap.read(Map.of("1", 1, "2", new DataList())); assert read.hasKeys("1", "2"); read.requireOf("1", DataPrimitive.class); read.requireOf("2", DataList.class);