Update EntitySerializerTest.java
This commit is contained in:
parent
d99a2ce3c3
commit
d70cd36a39
@ -6,6 +6,7 @@ import org.junit.jupiter.api.Test;
|
||||
import uulm.teamname.marvelous.gamelibrary.IntVector2;
|
||||
import uulm.teamname.marvelous.gamelibrary.entities.*;
|
||||
import uulm.teamname.marvelous.gamelibrary.entities.Character;
|
||||
import uulm.teamname.marvelous.gamelibrary.entities.Rock;
|
||||
import uulm.teamname.marvelous.gamelibrary.json.ingame.deserialize.EntityDeserializer;
|
||||
|
||||
import java.util.ArrayList;
|
||||
@ -19,6 +20,10 @@ class EntitySerializerTest {
|
||||
|
||||
@Test
|
||||
void serializeCharacter() throws JsonProcessingException {
|
||||
|
||||
//test if all required values are set in json
|
||||
// and that this is done in the right order as defined in the methods serialize() and serializeCharacter().
|
||||
|
||||
var mapper = new ObjectMapper();
|
||||
|
||||
var chara = new Character(
|
||||
@ -55,12 +60,19 @@ class EntitySerializerTest {
|
||||
|
||||
@Test
|
||||
void serializeNPC() throws JsonProcessingException {
|
||||
|
||||
//test if all required values are set in json
|
||||
// and that this is done in the right order as defined in the methods serialize() and serializeNPC().
|
||||
|
||||
var mapper = new ObjectMapper();
|
||||
|
||||
//________________________________________________
|
||||
|
||||
ArrayList<StoneType> al = new ArrayList<>();
|
||||
al.add(StoneType.MindStone);
|
||||
al.add(StoneType.PowerStone);
|
||||
|
||||
|
||||
var npc = new NPC(
|
||||
new EntityID(EntityType.NPC, 3),
|
||||
new IntVector2(12, 24),
|
||||
@ -80,13 +92,51 @@ class EntitySerializerTest {
|
||||
assertThat(mapper.writeValueAsString(npc))
|
||||
.isEqualTo(jsonRepresentingNPC);
|
||||
|
||||
// System.out.println(mapper.writeValueAsString(npc));
|
||||
//________________________________________________
|
||||
|
||||
// al.removeStone(StoneType.MindStone);
|
||||
//Inventory inv = new Inventory(al);
|
||||
var npc0= new NPC(
|
||||
new EntityID(EntityType.NPC, 3),
|
||||
new IntVector2(12, 24));
|
||||
npc0.inventory.addStone(StoneType.SoulStone);
|
||||
npc0.inventory.addStone(StoneType.TimeStone);
|
||||
|
||||
jsonRepresentingNPC = """
|
||||
{
|
||||
"entityType":"NPC",
|
||||
"ID":3,
|
||||
"MP":0,
|
||||
"stones":[4,5],
|
||||
"position":[12,24]
|
||||
}""".replace("\n", "");
|
||||
|
||||
// System.out.println(mapper.writeValueAsString(npc0));
|
||||
assertThat(mapper.writeValueAsString(npc0))
|
||||
.isEqualTo(jsonRepresentingNPC);
|
||||
|
||||
npc0.inventory.removeStone(StoneType.TimeStone);
|
||||
|
||||
jsonRepresentingNPC = """
|
||||
{
|
||||
"entityType":"NPC",
|
||||
"ID":3,
|
||||
"MP":0,
|
||||
"stones":[5],
|
||||
"position":[12,24]
|
||||
}""".replace("\n", "");
|
||||
|
||||
//System.out.println(mapper.writeValueAsString(npc0));
|
||||
assertThat(mapper.writeValueAsString(npc0))
|
||||
.isEqualTo(jsonRepresentingNPC);
|
||||
|
||||
//________________________________________________
|
||||
|
||||
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().
|
||||
//test if all required values are set in json and that this is done in the right order as defined in the methods serialize() and serializeNPC().
|
||||
jsonRepresentingNPC = """
|
||||
{
|
||||
"entityType":"NPC",
|
||||
@ -96,7 +146,7 @@ class EntitySerializerTest {
|
||||
"position":[12,24]
|
||||
}""".replace("\n", "");
|
||||
|
||||
// System.out.println(mapper.writeValueAsString(npc2));
|
||||
|
||||
assertThat(mapper.writeValueAsString(npc2))
|
||||
.isEqualTo(jsonRepresentingNPC);
|
||||
|
||||
@ -111,10 +161,12 @@ class EntitySerializerTest {
|
||||
"position":[12,24]
|
||||
}""".replace("\n", "");
|
||||
|
||||
// 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),
|
||||
@ -129,10 +181,71 @@ class EntitySerializerTest {
|
||||
"position":[12,24]
|
||||
}""".replace("\n", "");
|
||||
|
||||
// System.out.println(mapper.writeValueAsString(npc3));
|
||||
assertThat(mapper.writeValueAsString(npc3))
|
||||
.isEqualTo(jsonRepresentingNPC);
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
void serializeRock() throws JsonProcessingException {
|
||||
|
||||
var mapper = new ObjectMapper();
|
||||
|
||||
Rock rock1 = new Rock(
|
||||
new EntityID(EntityType.Rocks, 3),
|
||||
new IntVector2(12, 24),
|
||||
200);
|
||||
|
||||
var jsonRepresentingNPC = """
|
||||
{
|
||||
"entityType":"Rock",
|
||||
"ID":3,
|
||||
"HP":200,
|
||||
"position":[12,24]
|
||||
}""".replace("\n", "");
|
||||
|
||||
// System.out.println(mapper.writeValueAsString(rock1));
|
||||
assertThat(mapper.writeValueAsString(rock1))
|
||||
.isEqualTo(jsonRepresentingNPC);
|
||||
|
||||
rock1.decreaseHp(50);
|
||||
|
||||
jsonRepresentingNPC = """
|
||||
{
|
||||
"entityType":"Rock",
|
||||
"ID":3,
|
||||
"HP":150,
|
||||
"position":[12,24]
|
||||
}""".replace("\n", "");
|
||||
|
||||
//System.out.println(mapper.writeValueAsString(rock1));
|
||||
assertThat(mapper.writeValueAsString(rock1))
|
||||
.isEqualTo(jsonRepresentingNPC);
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
void serializeInfinityStone() throws JsonProcessingException {
|
||||
|
||||
var mapper = new ObjectMapper();
|
||||
|
||||
InfinityStone inf1 = new InfinityStone(
|
||||
new EntityID(EntityType.InfinityStones, 3),
|
||||
new IntVector2(12, 24),
|
||||
StoneType.PowerStone);
|
||||
|
||||
var jsonRepresentingNPC = """
|
||||
{
|
||||
"entityType":"InfinityStone",
|
||||
"ID":3,
|
||||
"position":[12,24]
|
||||
}""".replace("\n", "");
|
||||
|
||||
System.out.println(mapper.writeValueAsString(inf1));
|
||||
assertThat(mapper.writeValueAsString(inf1))
|
||||
.isEqualTo(jsonRepresentingNPC);
|
||||
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user