diff --git a/src/test/java/uulm/teamname/marvelous/gamelibrary/json/ingame/serialize/EntitySerializerTest.java b/src/test/java/uulm/teamname/marvelous/gamelibrary/json/ingame/serialize/EntitySerializerTest.java index ab6e46f..ae72b5a 100644 --- a/src/test/java/uulm/teamname/marvelous/gamelibrary/json/ingame/serialize/EntitySerializerTest.java +++ b/src/test/java/uulm/teamname/marvelous/gamelibrary/json/ingame/serialize/EntitySerializerTest.java @@ -56,36 +56,83 @@ class EntitySerializerTest { @Test void serializeNPC() throws JsonProcessingException { var mapper = new ObjectMapper(); - //(EntityID id, IntVector2 position, int maxMP, ArrayList inventory + ArrayList al = new ArrayList<>(); al.add(StoneType.MindStone); + al.add(StoneType.PowerStone); var npc = new NPC( new EntityID(EntityType.NPC, 3), new IntVector2(12, 24), 200, al); -/* - var npc2 = new NPC( - new EntityID(EntityType.P2, 3), - new IntVector2(12, 24), - 200, - new Inventory()); -*/ var jsonRepresentingNPC = """ { "entityType":"NPC", - "name":"CoolHeroThing", - "PID":2, "ID":3, "MP":200, + "stones":[1,3], + "position":[12,24] + }""".replace("\n", ""); + + + assertThat(mapper.writeValueAsString(npc)) + .isEqualTo(jsonRepresentingNPC); + + // System.out.println(mapper.writeValueAsString(npc)); + + var npc2 = new NPC( + new EntityID(EntityType.NPC, 3), + new IntVector2(12, 24)); + + //test if all values are set in json and that this is done in the right order as defined in the method serializeNPC(). + jsonRepresentingNPC = """ + { + "entityType":"NPC", + "ID":3, + "MP":0, + "stones":[], + "position":[12,24] + }""".replace("\n", ""); + + // System.out.println(mapper.writeValueAsString(npc2)); + assertThat(mapper.writeValueAsString(npc2)) + .isEqualTo(jsonRepresentingNPC); + + npc2.inventory.addStone(StoneType.MindStone); + + jsonRepresentingNPC = """ + { + "entityType":"NPC", + "ID":3, + "MP":0, "stones":[1], "position":[12,24] }""".replace("\n", ""); - assertThat(mapper.writeValueAsString(npc)) + // System.out.println(mapper.writeValueAsString(npc2)); + assertThat(mapper.writeValueAsString(npc2)) .isEqualTo(jsonRepresentingNPC); + + var npc3 = new NPC( + new EntityID(EntityType.NPC, 3), + new IntVector2(12, 24), + 200); + + jsonRepresentingNPC = """ + { + "entityType":"NPC", + "ID":3, + "MP":200, + "stones":[], + "position":[12,24] + }""".replace("\n", ""); + + // System.out.println(mapper.writeValueAsString(npc3)); + assertThat(mapper.writeValueAsString(npc3)) + .isEqualTo(jsonRepresentingNPC); + } }