Gamelib/src/test/java/uulm/teamname/marvelous/gamelibrary/json/ingame/serialize/EntitySerializerTest.java

57 lines
1.8 KiB
Java

package uulm.teamname.marvelous.gamelibrary.json.ingame.serialize;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import org.junit.jupiter.api.Test;
import uulm.teamname.marvelous.gamelibrary.IntVector2;
import uulm.teamname.marvelous.gamelibrary.entities.Character;
import uulm.teamname.marvelous.gamelibrary.entities.EntityID;
import uulm.teamname.marvelous.gamelibrary.entities.EntityType;
import uulm.teamname.marvelous.gamelibrary.entities.StoneType;
import uulm.teamname.marvelous.gamelibrary.json.ingame.deserialize.EntityDeserializer;
import static org.mockito.Mockito.*;
import static org.junit.jupiter.api.Assertions.*;
import static org.assertj.core.api.Assertions.*;
class EntitySerializerTest {
@Test
void serializeCharacter() throws JsonProcessingException {
var mapper = new ObjectMapper();
var chara = new Character(
new EntityID(EntityType.P2, 3),
new IntVector2(12, 24),
"CoolHeroThing",
200,
300,
400,
500,
600,
700);
chara.inventory.addStone(StoneType.SoulStone);
chara.inventory.addStone(StoneType.SpaceStone);
chara.inventory.addStone(StoneType.MindStone);
var jsonRepresentingCharacter = """
{
"entityType":"Character",
"name":"CoolHeroThing",
"PID":1,
"ID":1,
"HP":200,
"MP":300,
"AP":8,
"stones":[1,2,5],
"position":[12,24]
}""".replace("\n", "");
assertThat(mapper.writeValueAsString(chara))
.isEqualTo(jsonRepresentingCharacter);
}
}