Update EntitySerializerTest.java

This commit is contained in:
C H 2021-06-03 09:17:47 +02:00
parent f53a6502f4
commit d99a2ce3c3

View File

@ -56,36 +56,83 @@ class EntitySerializerTest {
@Test @Test
void serializeNPC() throws JsonProcessingException { void serializeNPC() throws JsonProcessingException {
var mapper = new ObjectMapper(); var mapper = new ObjectMapper();
//(EntityID id, IntVector2 position, int maxMP, ArrayList<StoneType> inventory
ArrayList<StoneType> al = new ArrayList<>(); ArrayList<StoneType> al = new ArrayList<>();
al.add(StoneType.MindStone); al.add(StoneType.MindStone);
al.add(StoneType.PowerStone);
var npc = new NPC( var npc = new NPC(
new EntityID(EntityType.NPC, 3), new EntityID(EntityType.NPC, 3),
new IntVector2(12, 24), new IntVector2(12, 24),
200, 200,
al); al);
/*
var npc2 = new NPC(
new EntityID(EntityType.P2, 3),
new IntVector2(12, 24),
200,
new Inventory());
*/
var jsonRepresentingNPC = """ var jsonRepresentingNPC = """
{ {
"entityType":"NPC", "entityType":"NPC",
"name":"CoolHeroThing",
"PID":2,
"ID":3, "ID":3,
"MP":200, "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], "stones":[1],
"position":[12,24] "position":[12,24]
}""".replace("\n", ""); }""".replace("\n", "");
assertThat(mapper.writeValueAsString(npc)) // System.out.println(mapper.writeValueAsString(npc2));
assertThat(mapper.writeValueAsString(npc2))
.isEqualTo(jsonRepresentingNPC); .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);
} }
} }