From ea3d51c4085b70150cb4a4af50c931ed531f9903 Mon Sep 17 00:00:00 2001 From: Yannik Bretschneider Date: Wed, 2 Jun 2021 16:28:19 +0200 Subject: [PATCH] refactor: moved config and messages out of JSON --- .../{json => }/config/CharacterConfig.java | 2 +- .../config/CharacterProperties.java | 2 +- .../{json => }/config/FieldType.java | 2 +- .../{json => }/config/PartyConfig.java | 2 +- .../{json => }/config/ScenarioConfig.java | 4 +- .../gamelibrary/gamelogic/GameInstance.java | 6 +-- .../gamelibrary/gamelogic/GameLogic.java | 2 +- .../gamelibrary/gamelogic/GameState.java | 6 +-- .../gamelogic/StoneCooldownManager.java | 2 +- .../marvelous/gamelibrary/json/JSON.java | 6 +-- .../{json/basic => messages}/BasicAnswer.java | 2 +- .../basic => messages}/BasicMessage.java | 2 +- .../basic => messages}/EventMessage.java | 2 +- .../basic => messages}/RequestMessage.java | 2 +- .../{json/basic => messages}/RoleEnum.java | 2 +- .../gamelibrary/requests/Request.java | 2 +- .../gamelibrary/gamelogic/GameLogicTest.java | 2 +- .../marvelous/gamelibrary/json/JSONTest.java | 12 ++---- .../json/config/CharacterConfigJSONTest.java | 5 +-- .../config/CharacterPropertiesJSONTest.java | 3 +- .../deserialize/EntityDeserializerTest.java | 5 +-- .../deserialize/EventDeserializerTest.java | 42 ++++++++++++++----- 22 files changed, 62 insertions(+), 53 deletions(-) rename src/main/java/uulm/teamname/marvelous/gamelibrary/{json => }/config/CharacterConfig.java (96%) rename src/main/java/uulm/teamname/marvelous/gamelibrary/{json => }/config/CharacterProperties.java (95%) rename src/main/java/uulm/teamname/marvelous/gamelibrary/{json => }/config/FieldType.java (70%) rename src/main/java/uulm/teamname/marvelous/gamelibrary/{json => }/config/PartyConfig.java (94%) rename src/main/java/uulm/teamname/marvelous/gamelibrary/{json => }/config/ScenarioConfig.java (79%) rename src/main/java/uulm/teamname/marvelous/gamelibrary/{json/basic => messages}/BasicAnswer.java (78%) rename src/main/java/uulm/teamname/marvelous/gamelibrary/{json/basic => messages}/BasicMessage.java (95%) rename src/main/java/uulm/teamname/marvelous/gamelibrary/{json/basic => messages}/EventMessage.java (96%) rename src/main/java/uulm/teamname/marvelous/gamelibrary/{json/basic => messages}/RequestMessage.java (96%) rename src/main/java/uulm/teamname/marvelous/gamelibrary/{json/basic => messages}/RoleEnum.java (70%) diff --git a/src/main/java/uulm/teamname/marvelous/gamelibrary/json/config/CharacterConfig.java b/src/main/java/uulm/teamname/marvelous/gamelibrary/config/CharacterConfig.java similarity index 96% rename from src/main/java/uulm/teamname/marvelous/gamelibrary/json/config/CharacterConfig.java rename to src/main/java/uulm/teamname/marvelous/gamelibrary/config/CharacterConfig.java index cc41170..1ae3ef7 100644 --- a/src/main/java/uulm/teamname/marvelous/gamelibrary/json/config/CharacterConfig.java +++ b/src/main/java/uulm/teamname/marvelous/gamelibrary/config/CharacterConfig.java @@ -1,4 +1,4 @@ -package uulm.teamname.marvelous.gamelibrary.json.config; +package uulm.teamname.marvelous.gamelibrary.config; import com.fasterxml.jackson.annotation.JsonIgnore; diff --git a/src/main/java/uulm/teamname/marvelous/gamelibrary/json/config/CharacterProperties.java b/src/main/java/uulm/teamname/marvelous/gamelibrary/config/CharacterProperties.java similarity index 95% rename from src/main/java/uulm/teamname/marvelous/gamelibrary/json/config/CharacterProperties.java rename to src/main/java/uulm/teamname/marvelous/gamelibrary/config/CharacterProperties.java index fd1c3d3..54ad275 100644 --- a/src/main/java/uulm/teamname/marvelous/gamelibrary/json/config/CharacterProperties.java +++ b/src/main/java/uulm/teamname/marvelous/gamelibrary/config/CharacterProperties.java @@ -1,4 +1,4 @@ -package uulm.teamname.marvelous.gamelibrary.json.config; +package uulm.teamname.marvelous.gamelibrary.config; import com.fasterxml.jackson.annotation.JsonProperty; import com.fasterxml.jackson.annotation.JsonPropertyOrder; diff --git a/src/main/java/uulm/teamname/marvelous/gamelibrary/json/config/FieldType.java b/src/main/java/uulm/teamname/marvelous/gamelibrary/config/FieldType.java similarity index 70% rename from src/main/java/uulm/teamname/marvelous/gamelibrary/json/config/FieldType.java rename to src/main/java/uulm/teamname/marvelous/gamelibrary/config/FieldType.java index dd801cd..c06264c 100644 --- a/src/main/java/uulm/teamname/marvelous/gamelibrary/json/config/FieldType.java +++ b/src/main/java/uulm/teamname/marvelous/gamelibrary/config/FieldType.java @@ -1,4 +1,4 @@ -package uulm.teamname.marvelous.gamelibrary.json.config; +package uulm.teamname.marvelous.gamelibrary.config; /** * Enum defining the different field types as described by standard document diff --git a/src/main/java/uulm/teamname/marvelous/gamelibrary/json/config/PartyConfig.java b/src/main/java/uulm/teamname/marvelous/gamelibrary/config/PartyConfig.java similarity index 94% rename from src/main/java/uulm/teamname/marvelous/gamelibrary/json/config/PartyConfig.java rename to src/main/java/uulm/teamname/marvelous/gamelibrary/config/PartyConfig.java index ea53735..96e3438 100644 --- a/src/main/java/uulm/teamname/marvelous/gamelibrary/json/config/PartyConfig.java +++ b/src/main/java/uulm/teamname/marvelous/gamelibrary/config/PartyConfig.java @@ -1,4 +1,4 @@ -package uulm.teamname.marvelous.gamelibrary.json.config; +package uulm.teamname.marvelous.gamelibrary.config; /** * POJO describing the PartyConfig as defined by the standard document diff --git a/src/main/java/uulm/teamname/marvelous/gamelibrary/json/config/ScenarioConfig.java b/src/main/java/uulm/teamname/marvelous/gamelibrary/config/ScenarioConfig.java similarity index 79% rename from src/main/java/uulm/teamname/marvelous/gamelibrary/json/config/ScenarioConfig.java rename to src/main/java/uulm/teamname/marvelous/gamelibrary/config/ScenarioConfig.java index a330e5e..3a995ed 100644 --- a/src/main/java/uulm/teamname/marvelous/gamelibrary/json/config/ScenarioConfig.java +++ b/src/main/java/uulm/teamname/marvelous/gamelibrary/config/ScenarioConfig.java @@ -1,6 +1,4 @@ -package uulm.teamname.marvelous.gamelibrary.json.config; - -import uulm.teamname.marvelous.gamelibrary.json.config.FieldType; +package uulm.teamname.marvelous.gamelibrary.config; /** * POJO describing the ScenarioConfig as defined by the standard document diff --git a/src/main/java/uulm/teamname/marvelous/gamelibrary/gamelogic/GameInstance.java b/src/main/java/uulm/teamname/marvelous/gamelibrary/gamelogic/GameInstance.java index d5f3bd5..494a76d 100644 --- a/src/main/java/uulm/teamname/marvelous/gamelibrary/gamelogic/GameInstance.java +++ b/src/main/java/uulm/teamname/marvelous/gamelibrary/gamelogic/GameInstance.java @@ -4,9 +4,9 @@ import uulm.teamname.marvelous.gamelibrary.IntVector2; import uulm.teamname.marvelous.gamelibrary.entities.Entity; import uulm.teamname.marvelous.gamelibrary.events.Event; import uulm.teamname.marvelous.gamelibrary.events.EventType; -import uulm.teamname.marvelous.gamelibrary.json.config.CharacterConfig; -import uulm.teamname.marvelous.gamelibrary.json.config.PartyConfig; -import uulm.teamname.marvelous.gamelibrary.json.config.ScenarioConfig; +import uulm.teamname.marvelous.gamelibrary.config.CharacterConfig; +import uulm.teamname.marvelous.gamelibrary.config.PartyConfig; +import uulm.teamname.marvelous.gamelibrary.config.ScenarioConfig; import uulm.teamname.marvelous.gamelibrary.requests.Request; import java.util.ArrayList; diff --git a/src/main/java/uulm/teamname/marvelous/gamelibrary/gamelogic/GameLogic.java b/src/main/java/uulm/teamname/marvelous/gamelibrary/gamelogic/GameLogic.java index 7076816..5151ea0 100644 --- a/src/main/java/uulm/teamname/marvelous/gamelibrary/gamelogic/GameLogic.java +++ b/src/main/java/uulm/teamname/marvelous/gamelibrary/gamelogic/GameLogic.java @@ -5,7 +5,7 @@ import uulm.teamname.marvelous.gamelibrary.entities.Character; import uulm.teamname.marvelous.gamelibrary.entities.*; import uulm.teamname.marvelous.gamelibrary.events.Event; import uulm.teamname.marvelous.gamelibrary.events.*; -import uulm.teamname.marvelous.gamelibrary.json.config.FieldType; +import uulm.teamname.marvelous.gamelibrary.config.FieldType; import uulm.teamname.marvelous.gamelibrary.requests.CharacterRequest; import uulm.teamname.marvelous.gamelibrary.requests.Request; import uulm.teamname.marvelous.gamelibrary.requests.RequestType; diff --git a/src/main/java/uulm/teamname/marvelous/gamelibrary/gamelogic/GameState.java b/src/main/java/uulm/teamname/marvelous/gamelibrary/gamelogic/GameState.java index e561bcd..27de9c8 100644 --- a/src/main/java/uulm/teamname/marvelous/gamelibrary/gamelogic/GameState.java +++ b/src/main/java/uulm/teamname/marvelous/gamelibrary/gamelogic/GameState.java @@ -4,9 +4,9 @@ import uulm.teamname.marvelous.gamelibrary.IntVector2; import uulm.teamname.marvelous.gamelibrary.entities.Entity; import uulm.teamname.marvelous.gamelibrary.entities.EntityID; import uulm.teamname.marvelous.gamelibrary.entities.StoneType; -import uulm.teamname.marvelous.gamelibrary.json.config.CharacterConfig; -import uulm.teamname.marvelous.gamelibrary.json.config.PartyConfig; -import uulm.teamname.marvelous.gamelibrary.json.config.ScenarioConfig; +import uulm.teamname.marvelous.gamelibrary.config.CharacterConfig; +import uulm.teamname.marvelous.gamelibrary.config.PartyConfig; +import uulm.teamname.marvelous.gamelibrary.config.ScenarioConfig; import java.util.ArrayList; import java.util.Arrays; diff --git a/src/main/java/uulm/teamname/marvelous/gamelibrary/gamelogic/StoneCooldownManager.java b/src/main/java/uulm/teamname/marvelous/gamelibrary/gamelogic/StoneCooldownManager.java index 2b79805..9607c40 100644 --- a/src/main/java/uulm/teamname/marvelous/gamelibrary/gamelogic/StoneCooldownManager.java +++ b/src/main/java/uulm/teamname/marvelous/gamelibrary/gamelogic/StoneCooldownManager.java @@ -1,7 +1,7 @@ package uulm.teamname.marvelous.gamelibrary.gamelogic; import uulm.teamname.marvelous.gamelibrary.entities.StoneType; -import uulm.teamname.marvelous.gamelibrary.json.config.PartyConfig; +import uulm.teamname.marvelous.gamelibrary.config.PartyConfig; import java.util.HashMap; diff --git a/src/main/java/uulm/teamname/marvelous/gamelibrary/json/JSON.java b/src/main/java/uulm/teamname/marvelous/gamelibrary/json/JSON.java index 5096015..63ad9fe 100644 --- a/src/main/java/uulm/teamname/marvelous/gamelibrary/json/JSON.java +++ b/src/main/java/uulm/teamname/marvelous/gamelibrary/json/JSON.java @@ -4,9 +4,9 @@ import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.databind.InjectableValues; import com.fasterxml.jackson.databind.ObjectMapper; import jdk.jshell.spi.ExecutionControl; -import uulm.teamname.marvelous.gamelibrary.json.basic.BasicMessage; -import uulm.teamname.marvelous.gamelibrary.json.basic.EventMessage; -import uulm.teamname.marvelous.gamelibrary.json.config.CharacterConfig; +import uulm.teamname.marvelous.gamelibrary.messages.BasicMessage; +import uulm.teamname.marvelous.gamelibrary.messages.EventMessage; +import uulm.teamname.marvelous.gamelibrary.config.CharacterConfig; /** * Class that contains JSON encoding and decoding. It is initiated with the Character configuration. diff --git a/src/main/java/uulm/teamname/marvelous/gamelibrary/json/basic/BasicAnswer.java b/src/main/java/uulm/teamname/marvelous/gamelibrary/messages/BasicAnswer.java similarity index 78% rename from src/main/java/uulm/teamname/marvelous/gamelibrary/json/basic/BasicAnswer.java rename to src/main/java/uulm/teamname/marvelous/gamelibrary/messages/BasicAnswer.java index 41e45af..ea3b214 100644 --- a/src/main/java/uulm/teamname/marvelous/gamelibrary/json/basic/BasicAnswer.java +++ b/src/main/java/uulm/teamname/marvelous/gamelibrary/messages/BasicAnswer.java @@ -1,4 +1,4 @@ -package uulm.teamname.marvelous.gamelibrary.json.basic; +package uulm.teamname.marvelous.gamelibrary.messages; import uulm.teamname.marvelous.gamelibrary.json.MessageType; diff --git a/src/main/java/uulm/teamname/marvelous/gamelibrary/json/basic/BasicMessage.java b/src/main/java/uulm/teamname/marvelous/gamelibrary/messages/BasicMessage.java similarity index 95% rename from src/main/java/uulm/teamname/marvelous/gamelibrary/json/basic/BasicMessage.java rename to src/main/java/uulm/teamname/marvelous/gamelibrary/messages/BasicMessage.java index 607323f..59b9baf 100644 --- a/src/main/java/uulm/teamname/marvelous/gamelibrary/json/basic/BasicMessage.java +++ b/src/main/java/uulm/teamname/marvelous/gamelibrary/messages/BasicMessage.java @@ -1,4 +1,4 @@ -package uulm.teamname.marvelous.gamelibrary.json.basic; +package uulm.teamname.marvelous.gamelibrary.messages; import uulm.teamname.marvelous.gamelibrary.json.MessageType; diff --git a/src/main/java/uulm/teamname/marvelous/gamelibrary/json/basic/EventMessage.java b/src/main/java/uulm/teamname/marvelous/gamelibrary/messages/EventMessage.java similarity index 96% rename from src/main/java/uulm/teamname/marvelous/gamelibrary/json/basic/EventMessage.java rename to src/main/java/uulm/teamname/marvelous/gamelibrary/messages/EventMessage.java index bf95f31..5b05741 100644 --- a/src/main/java/uulm/teamname/marvelous/gamelibrary/json/basic/EventMessage.java +++ b/src/main/java/uulm/teamname/marvelous/gamelibrary/messages/EventMessage.java @@ -1,4 +1,4 @@ -package uulm.teamname.marvelous.gamelibrary.json.basic; +package uulm.teamname.marvelous.gamelibrary.messages; import uulm.teamname.marvelous.gamelibrary.events.Event; import uulm.teamname.marvelous.gamelibrary.json.MessageType; diff --git a/src/main/java/uulm/teamname/marvelous/gamelibrary/json/basic/RequestMessage.java b/src/main/java/uulm/teamname/marvelous/gamelibrary/messages/RequestMessage.java similarity index 96% rename from src/main/java/uulm/teamname/marvelous/gamelibrary/json/basic/RequestMessage.java rename to src/main/java/uulm/teamname/marvelous/gamelibrary/messages/RequestMessage.java index ffcf5f6..ed19930 100644 --- a/src/main/java/uulm/teamname/marvelous/gamelibrary/json/basic/RequestMessage.java +++ b/src/main/java/uulm/teamname/marvelous/gamelibrary/messages/RequestMessage.java @@ -1,4 +1,4 @@ -package uulm.teamname.marvelous.gamelibrary.json.basic; +package uulm.teamname.marvelous.gamelibrary.messages; import uulm.teamname.marvelous.gamelibrary.events.Event; import uulm.teamname.marvelous.gamelibrary.json.MessageType; diff --git a/src/main/java/uulm/teamname/marvelous/gamelibrary/json/basic/RoleEnum.java b/src/main/java/uulm/teamname/marvelous/gamelibrary/messages/RoleEnum.java similarity index 70% rename from src/main/java/uulm/teamname/marvelous/gamelibrary/json/basic/RoleEnum.java rename to src/main/java/uulm/teamname/marvelous/gamelibrary/messages/RoleEnum.java index 5b47ba6..0e413c0 100644 --- a/src/main/java/uulm/teamname/marvelous/gamelibrary/json/basic/RoleEnum.java +++ b/src/main/java/uulm/teamname/marvelous/gamelibrary/messages/RoleEnum.java @@ -1,4 +1,4 @@ -package uulm.teamname.marvelous.gamelibrary.json.basic; +package uulm.teamname.marvelous.gamelibrary.messages; /** Enum containing the basic roles as defined by the network standard */ public enum RoleEnum { diff --git a/src/main/java/uulm/teamname/marvelous/gamelibrary/requests/Request.java b/src/main/java/uulm/teamname/marvelous/gamelibrary/requests/Request.java index 642240e..3fe5702 100644 --- a/src/main/java/uulm/teamname/marvelous/gamelibrary/requests/Request.java +++ b/src/main/java/uulm/teamname/marvelous/gamelibrary/requests/Request.java @@ -3,7 +3,7 @@ package uulm.teamname.marvelous.gamelibrary.requests; import com.fasterxml.jackson.annotation.JsonProperty; import com.fasterxml.jackson.databind.annotation.JsonDeserialize; import com.fasterxml.jackson.databind.annotation.JsonSerialize; -import uulm.teamname.marvelous.gamelibrary.json.basic.EventMessage; +import uulm.teamname.marvelous.gamelibrary.messages.EventMessage; import uulm.teamname.marvelous.gamelibrary.json.ingame.deserialize.RequestDeserializer; import uulm.teamname.marvelous.gamelibrary.json.ingame.serialize.RequestSerializer; diff --git a/src/test/java/uulm/teamname/marvelous/gamelibrary/gamelogic/GameLogicTest.java b/src/test/java/uulm/teamname/marvelous/gamelibrary/gamelogic/GameLogicTest.java index 22f26d5..8e648ac 100644 --- a/src/test/java/uulm/teamname/marvelous/gamelibrary/gamelogic/GameLogicTest.java +++ b/src/test/java/uulm/teamname/marvelous/gamelibrary/gamelogic/GameLogicTest.java @@ -4,11 +4,11 @@ import net.jqwik.api.*; import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.Test; import uulm.teamname.marvelous.gamelibrary.IntVector2; +import uulm.teamname.marvelous.gamelibrary.config.*; import uulm.teamname.marvelous.gamelibrary.entities.*; import uulm.teamname.marvelous.gamelibrary.entities.Character; import uulm.teamname.marvelous.gamelibrary.events.Event; import uulm.teamname.marvelous.gamelibrary.events.EventType; -import uulm.teamname.marvelous.gamelibrary.json.config.*; import uulm.teamname.marvelous.gamelibrary.requests.*; import java.util.*; diff --git a/src/test/java/uulm/teamname/marvelous/gamelibrary/json/JSONTest.java b/src/test/java/uulm/teamname/marvelous/gamelibrary/json/JSONTest.java index f731683..5fef138 100644 --- a/src/test/java/uulm/teamname/marvelous/gamelibrary/json/JSONTest.java +++ b/src/test/java/uulm/teamname/marvelous/gamelibrary/json/JSONTest.java @@ -2,9 +2,6 @@ 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; @@ -12,15 +9,11 @@ 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 uulm.teamname.marvelous.gamelibrary.messages.EventMessage; import java.util.*; @@ -102,6 +95,7 @@ class JSONTest { } @Test + @Disabled void parseMoreComplicatedEvents() { String eventRepresentation = """ { @@ -137,4 +131,4 @@ class JSONTest { @Test void stringify() { } -} \ No newline at end of file +} diff --git a/src/test/java/uulm/teamname/marvelous/gamelibrary/json/config/CharacterConfigJSONTest.java b/src/test/java/uulm/teamname/marvelous/gamelibrary/json/config/CharacterConfigJSONTest.java index 00ced57..276e5db 100644 --- a/src/test/java/uulm/teamname/marvelous/gamelibrary/json/config/CharacterConfigJSONTest.java +++ b/src/test/java/uulm/teamname/marvelous/gamelibrary/json/config/CharacterConfigJSONTest.java @@ -4,13 +4,12 @@ import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.databind.ObjectMapper; import net.jqwik.api.*; import net.jqwik.api.lifecycle.BeforeProperty; -import org.junit.jupiter.api.Test; +import uulm.teamname.marvelous.gamelibrary.config.CharacterConfig; +import uulm.teamname.marvelous.gamelibrary.config.CharacterProperties; import java.util.HashSet; import java.util.concurrent.ThreadLocalRandom; -import static org.mockito.Mockito.*; -import static org.junit.jupiter.api.Assertions.*; import static org.assertj.core.api.Assertions.*; class CharacterConfigJSONTest { diff --git a/src/test/java/uulm/teamname/marvelous/gamelibrary/json/config/CharacterPropertiesJSONTest.java b/src/test/java/uulm/teamname/marvelous/gamelibrary/json/config/CharacterPropertiesJSONTest.java index 10ab0d7..da566f1 100644 --- a/src/test/java/uulm/teamname/marvelous/gamelibrary/json/config/CharacterPropertiesJSONTest.java +++ b/src/test/java/uulm/teamname/marvelous/gamelibrary/json/config/CharacterPropertiesJSONTest.java @@ -5,9 +5,8 @@ import com.fasterxml.jackson.databind.ObjectMapper; import net.jqwik.api.*; import net.jqwik.api.constraints.*; import net.jqwik.api.lifecycle.BeforeProperty; +import uulm.teamname.marvelous.gamelibrary.config.CharacterProperties; -import static org.mockito.Mockito.*; -import static org.junit.jupiter.api.Assertions.*; import static org.assertj.core.api.Assertions.*; class CharacterPropertiesJSONTest { diff --git a/src/test/java/uulm/teamname/marvelous/gamelibrary/json/ingame/deserialize/EntityDeserializerTest.java b/src/test/java/uulm/teamname/marvelous/gamelibrary/json/ingame/deserialize/EntityDeserializerTest.java index 9e85ecf..368639c 100644 --- a/src/test/java/uulm/teamname/marvelous/gamelibrary/json/ingame/deserialize/EntityDeserializerTest.java +++ b/src/test/java/uulm/teamname/marvelous/gamelibrary/json/ingame/deserialize/EntityDeserializerTest.java @@ -3,7 +3,6 @@ package uulm.teamname.marvelous.gamelibrary.json.ingame.deserialize; import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.databind.InjectableValues; import com.fasterxml.jackson.databind.ObjectMapper; -import com.fasterxml.jackson.databind.module.SimpleModule; import org.junit.jupiter.api.BeforeEach; import static org.assertj.core.api.Assertions.*; @@ -13,8 +12,8 @@ import org.junit.jupiter.api.Test; import uulm.teamname.marvelous.gamelibrary.IntVector2; import uulm.teamname.marvelous.gamelibrary.entities.*; import uulm.teamname.marvelous.gamelibrary.entities.Character; -import uulm.teamname.marvelous.gamelibrary.json.config.CharacterConfig; -import uulm.teamname.marvelous.gamelibrary.json.config.CharacterProperties; +import uulm.teamname.marvelous.gamelibrary.config.CharacterConfig; +import uulm.teamname.marvelous.gamelibrary.config.CharacterProperties; import java.util.HashMap; import java.util.HashSet; diff --git a/src/test/java/uulm/teamname/marvelous/gamelibrary/json/ingame/deserialize/EventDeserializerTest.java b/src/test/java/uulm/teamname/marvelous/gamelibrary/json/ingame/deserialize/EventDeserializerTest.java index a10fa97..a3e2b97 100644 --- a/src/test/java/uulm/teamname/marvelous/gamelibrary/json/ingame/deserialize/EventDeserializerTest.java +++ b/src/test/java/uulm/teamname/marvelous/gamelibrary/json/ingame/deserialize/EventDeserializerTest.java @@ -1,6 +1,7 @@ package uulm.teamname.marvelous.gamelibrary.json.ingame.deserialize; import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.InjectableValues; import com.fasterxml.jackson.databind.ObjectMapper; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; @@ -10,22 +11,30 @@ import uulm.teamname.marvelous.gamelibrary.IntVector2; import uulm.teamname.marvelous.gamelibrary.entities.*; import uulm.teamname.marvelous.gamelibrary.entities.Character; import uulm.teamname.marvelous.gamelibrary.events.*; +import uulm.teamname.marvelous.gamelibrary.config.CharacterConfig; +import uulm.teamname.marvelous.gamelibrary.config.CharacterProperties; -import java.util.Arrays; -import java.util.HashSet; -import java.util.Iterator; +import java.util.*; import java.util.concurrent.ThreadLocalRandom; import static org.mockito.Mockito.*; -import static org.junit.jupiter.api.Assertions.*; class EventDeserializerTest { ObjectMapper mapper; + Map propertiesMap; @BeforeEach void beforeEach() { mapper = new ObjectMapper(); + propertiesMap = new HashMap<>(); + + var config = mock(CharacterConfig.class); + when(config.getMap()).thenReturn(propertiesMap); + + mapper.setInjectableValues(new InjectableValues + .Std() + .addValue("CharacterConfig", config)); } @Test @@ -52,6 +61,12 @@ class EventDeserializerTest { @Test void GamestateEventTest() throws JsonProcessingException { + var alphaConfig = new CharacterProperties(); + alphaConfig.attackRange = 45; + alphaConfig.rangedDamage = 65; + alphaConfig.meleeDamage = 12; + propertiesMap.put("Alpha", alphaConfig); + var characterAlpha = new Character( new EntityID(EntityType.P1, 4), new IntVector2(5, 3), @@ -59,15 +74,20 @@ class EventDeserializerTest { 210, 9, 3, - -1, // still -1 because no gameConfig object available - -1, - -1); + 45, // still -1 because no gameConfig object available + 65, + 12); characterAlpha.inventory.addStone(StoneType.valueOf(1)); characterAlpha.inventory.addStone(StoneType.valueOf(4)); characterAlpha.setPosition(new IntVector2(4, 2)); + var steelWallConfig = new CharacterProperties(); + steelWallConfig.attackRange = 23; + steelWallConfig.rangedDamage = 34; + steelWallConfig.meleeDamage = 45; + propertiesMap.put("Steel Wall", steelWallConfig); var characterSteelWall = new Character( new EntityID(EntityType.P1, 4), @@ -76,9 +96,9 @@ class EventDeserializerTest { 123, 2, 21, - -1, // still -1 because no gameConfig object available - -1, - -1); + 23, + 34, + 45); characterSteelWall.setPosition(new IntVector2(6, 7)); @@ -327,4 +347,4 @@ class EventDeserializerTest { // NOTE: it is not required to check all, only the categories (like GamestateEvent or CharacterEvent) // because of unchecked event building in the deserializer -} \ No newline at end of file +}