feat: implemented JSON stuff related to PortalEvents
This commit is contained in:
@ -36,7 +36,6 @@ class JSONTest {
|
||||
CharacterConfig characterConfig;
|
||||
HashMap<String, CharacterProperties> propertiesMap;
|
||||
|
||||
// TODO: add proper CharacterConfig, otherwise Character events won't be deserializable
|
||||
@BeforeEach
|
||||
void setUp() {
|
||||
characterConfig = mock(CharacterConfig.class);
|
||||
|
@ -343,8 +343,30 @@ class EventDeserializerTest {
|
||||
}
|
||||
}
|
||||
|
||||
// TODO: Write tests for the other event types
|
||||
// NOTE: it is not required to check all, only the categories (like GamestateEvent or CharacterEvent)
|
||||
// because of unchecked event building in the deserializer
|
||||
@Test
|
||||
void teleportedEventDeserializationTest() throws JsonProcessingException {
|
||||
|
||||
var jsonRepresentingTeleportedEvent = """
|
||||
{
|
||||
"eventType":"TeleportedEvent",
|
||||
"teleportedEntity":{"entityID":"P1", "ID":3},
|
||||
"originField":[6, 2],
|
||||
"targetField":[11, 14],
|
||||
"originPortal":{"entityID":"Portals", "ID":0},
|
||||
"targetPortal":{"entityID":"Portals", "ID":2}
|
||||
}
|
||||
""";
|
||||
|
||||
var teleportedEvent = new EventBuilder(EventType.TeleportedEvent)
|
||||
.withTeleportedEntity(new EntityID(EntityType.P1, 3))
|
||||
.withOriginField(new IntVector2(6, 2))
|
||||
.withTargetField(new IntVector2(11, 14))
|
||||
.withOriginPortal(new EntityID(EntityType.Portals, 0))
|
||||
.withTargetPortal(new EntityID(EntityType.Portals, 2))
|
||||
.buildTeleportedEvent();
|
||||
|
||||
assertThat((TeleportedEvent) mapper.readValue(jsonRepresentingTeleportedEvent, Event.class))
|
||||
.isEqualTo(teleportedEvent);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -6,6 +6,7 @@ import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
//import net.jqwik.api.lifecycle.BeforeProperty;
|
||||
import net.jqwik.api.*;
|
||||
import net.jqwik.api.lifecycle.BeforeProperty;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import uulm.teamname.marvelous.gamelibrary.IntVector2;
|
||||
import uulm.teamname.marvelous.gamelibrary.entities.*;
|
||||
@ -377,6 +378,31 @@ public class EventSerializerTest {
|
||||
});
|
||||
}
|
||||
|
||||
@Example
|
||||
void teleportedEventSerializationTest() throws JsonProcessingException {
|
||||
|
||||
var jsonRepresentingTeleportedEvent = """
|
||||
{
|
||||
"eventType":"TeleportedEvent",
|
||||
"teleportedEntity":{"entityID":"P1","ID":3},
|
||||
"originField":[6,2],
|
||||
"targetField":[11,14],
|
||||
"originPortal":{"entityID":"Portals","ID":0},
|
||||
"targetPortal":{"entityID":"Portals","ID":2}
|
||||
}
|
||||
""".replace("\n", "");
|
||||
|
||||
var teleportedEvent = new EventBuilder(EventType.TeleportedEvent)
|
||||
.withTeleportedEntity(new EntityID(EntityType.P1, 3))
|
||||
.withOriginField(new IntVector2(6, 2))
|
||||
.withTargetField(new IntVector2(11, 14))
|
||||
.withOriginPortal(new EntityID(EntityType.Portals, 0))
|
||||
.withTargetPortal(new EntityID(EntityType.Portals, 2))
|
||||
.buildTeleportedEvent();
|
||||
|
||||
assertThat(mapper.writeValueAsString(teleportedEvent))
|
||||
.isEqualTo(jsonRepresentingTeleportedEvent);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
Reference in New Issue
Block a user