refactor: re-formatted JSONTest

This commit is contained in:
Yannik Bretschneider 2021-05-30 18:07:05 +02:00
parent 2ff309500e
commit 6a6669ae5d
1 changed files with 36 additions and 28 deletions

View File

@ -2,19 +2,27 @@ package uulm.teamname.marvelous.gamelibrary.json;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import net.jqwik.api.*;
import net.jqwik.api.lifecycle.BeforeContainer;
import net.jqwik.api.lifecycle.BeforeProperty;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.Test;
import static org.assertj.core.api.Assertions.*;
import uulm.teamname.marvelous.gamelibrary.IntVector2;
import uulm.teamname.marvelous.gamelibrary.entities.EntityID;
import uulm.teamname.marvelous.gamelibrary.entities.EntityType;
import uulm.teamname.marvelous.gamelibrary.entities.Rock;
import uulm.teamname.marvelous.gamelibrary.events.Event;
import uulm.teamname.marvelous.gamelibrary.events.EventBuilder;
import uulm.teamname.marvelous.gamelibrary.events.EventType;
import uulm.teamname.marvelous.gamelibrary.json.basic.EventMessage;
import uulm.teamname.marvelous.gamelibrary.requests.*;
import java.util.HashMap;
import java.util.*;
class JSONTest {
@ -29,11 +37,11 @@ class JSONTest {
@BeforeEach
void setUp() {
messageStructureStart = """
{
"messages":[
""";
messageStructureEnd = new String[] {
"""
{
"messages":[
""";
messageStructureEnd = new String[]{
"""
],
"messageType": "REQUESTS",
"customContentType": "TestCustomContent",
@ -43,7 +51,7 @@ class JSONTest {
"customProperty" = true
}
""",
"""
"""
],
"messageType": "EVENTS",
"customContentType": "TestCustomContent",
@ -75,9 +83,9 @@ class JSONTest {
};
String eventRepresentation = """
{"eventType": "Ack"},
{"eventType": "Nack"}
""";
{"eventType": "Ack"},
{"eventType": "Nack"}
""";
String completeMessageStructure = messageStructureStart + eventRepresentation + messageStructureEnd[1];
target.messageType = MessageType.EVENTS;
@ -90,19 +98,19 @@ class JSONTest {
@Test
void parseMoreComplicatedEvents() {
String eventRepresentation = """
{
"eventType": "GamestateEvent",
"activeCharacter": {"entityID": "P2", "ID": 4},
"turnOrder": [
{"entityID": "P2", "ID": 4},
{"entityID": "P2", "ID": 2},
{"entityID": "P1", "ID": 3},
{"entityID": "NPC", "ID": 1},
{"entityID": "InfinityStones", "ID": 5},
{"entityID": "Rocks", "ID": 0}
]
}
""";
{
"eventType": "GamestateEvent",
"activeCharacter": {"entityID": "P2", "ID": 4},
"turnOrder": [
{"entityID": "P2", "ID": 4},
{"entityID": "P2", "ID": 2},
{"entityID": "P1", "ID": 3},
{"entityID": "NPC", "ID": 1},
{"entityID": "InfinityStones", "ID": 5},
{"entityID": "Rocks", "ID": 0}
]
}
""";
String completeMessageStructure = messageStructureStart + eventRepresentation + messageStructureEnd[1];
System.out.println(JSON.parse(completeMessageStructure));
@ -112,11 +120,11 @@ class JSONTest {
@Disabled
void simpleInDevTest() throws JsonProcessingException {
String simpleEntity = """
{
"entityID": "P2",
"ID": 4
}
""";
{
"entityID": "P2",
"ID": 4
}
""";
System.out.println(new ObjectMapper().readValue(simpleEntity, EntityID.class));
}