refactor: re-formatted JSONTest

This commit is contained in:
Yannik Bretschneider 2021-05-30 18:07:05 +02:00
parent 2ff309500e
commit 6a6669ae5d

View File

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