feat: wrote EntityDeserializer

This commit is contained in:
2021-05-11 21:17:55 +02:00
parent 28ac25fa55
commit f7b1514491
3 changed files with 129 additions and 0 deletions

View File

@ -0,0 +1,56 @@
package uulm.teamname.marvelous.gamelibrary.json.ingame;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import org.junit.jupiter.api.BeforeEach;
import static org.assertj.core.api.Assertions.*;
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.Entity;
import uulm.teamname.marvelous.gamelibrary.entities.EntityID;
import uulm.teamname.marvelous.gamelibrary.entities.EntityType;
import static org.mockito.Mockito.*;
import static org.junit.jupiter.api.Assertions.*;
class EntityDeserializerTest {
ObjectMapper mapper;
@BeforeEach
void setUp() {
mapper = new ObjectMapper();
}
@Test
void simpleCharacterTest() throws JsonProcessingException {
var character = new Character(
new EntityID(EntityType.P1, 3),
new IntVector2(4, 2),
"God",
255,
65535,
4,
-1,
-1,
-1
);
var jsonRepresentingCharacter = """
{
"entityType": "Character",
"name": "God",
"PID": 1,
"ID": 3,
"HP": 255,
"MP": 65535,
"AP": 4,
"position": [4, 2]
}
""";
assertThat(mapper.readValue(jsonRepresentingCharacter, Entity.class))
.isEqualTo(character);
}
}