Skip to content

Commit

Permalink
Add more tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
thegatesdev committed Nov 12, 2022
1 parent 974e9c2 commit 1ea030e
Showing 1 changed file with 18 additions and 9 deletions.
27 changes: 18 additions & 9 deletions src/test/java/com/thegates/maple/data/DataMapTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit 1ea030e

Please sign in to comment.