feat: implemented still-missing JSON ser/deser for portalEntities

This commit is contained in:
2021-07-12 21:16:02 +02:00
parent 518e458c5f
commit e9b4bc5f58
5 changed files with 59 additions and 1 deletions

View File

@ -271,12 +271,33 @@ class EntityDeserializerTest {
rock.getPosition().getY()
);
// === RANDOM PORTAL ===
Portal portal = new Portal(
new EntityID(EntityType.Portals, Math.abs(randomIntegers.next())),
new IntVector2(Math.abs(randomIntegers.next()), Math.abs(randomIntegers.next()))
);
String jsonRepresentingPortal = """
{
"entityType": "Portal",
"ID": %d,
"position": [%d, %d]
}
""".formatted(// formatting the string with the required arguments
portal.id.id,
portal.getPosition().getX(),
portal.getPosition().getY()
);
// System.out.println(character);
// System.out.println(jsonRepresentingCharacter);
// System.out.println(stone);
// System.out.println(jsonRepresentingStone);
// System.out.println(rock);
// System.out.println(jsonRepresentingRock);
// System.out.println(portal);
// System.out.println(jsonRepresentingPortal);
// // Assertions
assertThat((Character) (mapper.readValue(jsonRepresentingCharacter, Entity.class)))
@ -288,6 +309,9 @@ class EntityDeserializerTest {
assertThat((Rock) (mapper.readValue(jsonRepresentingRock, Entity.class)))
.isEqualTo(rock);
assertThat((Portal) mapper.readValue(jsonRepresentingPortal, Entity.class))
.isEqualTo(portal);

View File

@ -243,4 +243,26 @@ class EntitySerializerTest {
}
@Test
void serializePortal() throws JsonProcessingException {
var mapper = new ObjectMapper();
Portal portal = new Portal(
new EntityID(EntityType.Portals, 15),
new IntVector2(25, 35)
);
String jsonRepresentingPortal = """
{
"entityType":"Portal",
"ID":15,
"position":[25,35]
}
""".replace("\n", "");
assertThat(mapper.writeValueAsString(portal))
.isEqualTo(jsonRepresentingPortal);
}
}