diff --git a/src/main/java/uulm/teamname/marvelous/gamelibrary/ArrayTools.java b/src/main/java/uulm/teamname/marvelous/gamelibrary/ArrayTools.java index 024a8df..46d770b 100644 --- a/src/main/java/uulm/teamname/marvelous/gamelibrary/ArrayTools.java +++ b/src/main/java/uulm/teamname/marvelous/gamelibrary/ArrayTools.java @@ -1,6 +1,7 @@ package uulm.teamname.marvelous.gamelibrary; import java.util.ArrayList; +import java.util.Arrays; /** Provides various tools for Arrays. */ public class ArrayTools { @@ -13,9 +14,7 @@ public class ArrayTools { */ public static ArrayList toArrayList(E[] a) { ArrayList l = new ArrayList<>(a.length); - for(E e: a) { - l.add(e); - } + l.addAll(Arrays.asList(a)); return l; } } diff --git a/src/main/java/uulm/teamname/marvelous/gamelibrary/config/CharacterProperties.java b/src/main/java/uulm/teamname/marvelous/gamelibrary/config/CharacterProperties.java index b0abad8..bd83c15 100644 --- a/src/main/java/uulm/teamname/marvelous/gamelibrary/config/CharacterProperties.java +++ b/src/main/java/uulm/teamname/marvelous/gamelibrary/config/CharacterProperties.java @@ -5,10 +5,8 @@ import com.fasterxml.jackson.annotation.JsonPropertyOrder; import java.util.Objects; +/** Represents properties of a character in the {@link CharacterConfig} */ @JsonPropertyOrder({"characterID", "name", "HP", "MP", "AP", "meleeDamage", "rangeCombatDamage", "rangeCombatReach"}) -/** - * Represents properties of a character in the {@link CharacterConfig}. - */ public class CharacterProperties { public int characterID; public String name; diff --git a/src/main/java/uulm/teamname/marvelous/gamelibrary/config/ScenarioConfig.java b/src/main/java/uulm/teamname/marvelous/gamelibrary/config/ScenarioConfig.java index e961eec..562370b 100644 --- a/src/main/java/uulm/teamname/marvelous/gamelibrary/config/ScenarioConfig.java +++ b/src/main/java/uulm/teamname/marvelous/gamelibrary/config/ScenarioConfig.java @@ -27,7 +27,7 @@ public class ScenarioConfig { @Override public int hashCode() { int result = Objects.hash(author, name); - result = 31 * result + Arrays.hashCode(scenario); + result = 31 * result + Arrays.deepHashCode(scenario); return result; } diff --git a/src/main/java/uulm/teamname/marvelous/gamelibrary/json/JsonNodeUnwrapper.java b/src/main/java/uulm/teamname/marvelous/gamelibrary/json/JsonNodeUnwrapper.java index a0dea7f..a2b91af 100644 --- a/src/main/java/uulm/teamname/marvelous/gamelibrary/json/JsonNodeUnwrapper.java +++ b/src/main/java/uulm/teamname/marvelous/gamelibrary/json/JsonNodeUnwrapper.java @@ -2,9 +2,7 @@ package uulm.teamname.marvelous.gamelibrary.json; import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.core.ObjectCodec; -import com.fasterxml.jackson.databind.DeserializationContext; import com.fasterxml.jackson.databind.JsonNode; -import com.fasterxml.jackson.databind.ObjectMapper; public class JsonNodeUnwrapper { diff --git a/src/main/java/uulm/teamname/marvelous/gamelibrary/json/ingame/deserialize/EntityDeserializer.java b/src/main/java/uulm/teamname/marvelous/gamelibrary/json/ingame/deserialize/EntityDeserializer.java index 9996394..8432413 100644 --- a/src/main/java/uulm/teamname/marvelous/gamelibrary/json/ingame/deserialize/EntityDeserializer.java +++ b/src/main/java/uulm/teamname/marvelous/gamelibrary/json/ingame/deserialize/EntityDeserializer.java @@ -55,20 +55,16 @@ public class EntityDeserializer extends JsonDeserializer { ((Character) result).inventory.addStone(StoneType.valueOf(i)); } } - case InfinityStone -> { - result = new InfinityStone( - new EntityID(EntityType.InfinityStones, node.get("ID").asInt()), - codec.treeToValue(node.get("position"), IntVector2.class), - StoneType.valueOf(node.get("ID").asInt()) - ); - } - case Rock -> { - result = new Rock( - new EntityID(EntityType.Rocks, node.get("ID").asInt()), - codec.treeToValue(node.get("position"), IntVector2.class), - node.get("HP").asInt() - ); - } + case InfinityStone -> result = new InfinityStone( + new EntityID(EntityType.InfinityStones, node.get("ID").asInt()), + codec.treeToValue(node.get("position"), IntVector2.class), + StoneType.valueOf(node.get("ID").asInt()) + ); + case Rock -> result = new Rock( + new EntityID(EntityType.Rocks, node.get("ID").asInt()), + codec.treeToValue(node.get("position"), IntVector2.class), + node.get("HP").asInt() + ); } return result; } diff --git a/src/main/java/uulm/teamname/marvelous/gamelibrary/json/ingame/deserialize/EntityIDDeserializer.java b/src/main/java/uulm/teamname/marvelous/gamelibrary/json/ingame/deserialize/EntityIDDeserializer.java index c694d0a..52b9d4d 100644 --- a/src/main/java/uulm/teamname/marvelous/gamelibrary/json/ingame/deserialize/EntityIDDeserializer.java +++ b/src/main/java/uulm/teamname/marvelous/gamelibrary/json/ingame/deserialize/EntityIDDeserializer.java @@ -1,7 +1,6 @@ package uulm.teamname.marvelous.gamelibrary.json.ingame.deserialize; import com.fasterxml.jackson.core.JsonParser; -import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.core.ObjectCodec; import com.fasterxml.jackson.databind.DeserializationContext; import com.fasterxml.jackson.databind.JsonDeserializer; diff --git a/src/main/java/uulm/teamname/marvelous/gamelibrary/json/ingame/deserialize/EventDeserializer.java b/src/main/java/uulm/teamname/marvelous/gamelibrary/json/ingame/deserialize/EventDeserializer.java index ae8f6f5..9e464ca 100644 --- a/src/main/java/uulm/teamname/marvelous/gamelibrary/json/ingame/deserialize/EventDeserializer.java +++ b/src/main/java/uulm/teamname/marvelous/gamelibrary/json/ingame/deserialize/EventDeserializer.java @@ -28,7 +28,7 @@ public class EventDeserializer extends JsonDeserializer { JsonNode currentNode = null; EventBuilder builder; - EventType eventType = null; + EventType eventType; if (!node.has("eventType")) { throw new IOException("Event had wrong format: no EventType found"); diff --git a/src/main/java/uulm/teamname/marvelous/gamelibrary/json/ingame/deserialize/IntVector2Deserializer.java b/src/main/java/uulm/teamname/marvelous/gamelibrary/json/ingame/deserialize/IntVector2Deserializer.java index 03d1756..7b218ad 100644 --- a/src/main/java/uulm/teamname/marvelous/gamelibrary/json/ingame/deserialize/IntVector2Deserializer.java +++ b/src/main/java/uulm/teamname/marvelous/gamelibrary/json/ingame/deserialize/IntVector2Deserializer.java @@ -1,12 +1,8 @@ package uulm.teamname.marvelous.gamelibrary.json.ingame.deserialize; import com.fasterxml.jackson.core.JsonParser; -import com.fasterxml.jackson.core.JsonProcessingException; -import com.fasterxml.jackson.core.ObjectCodec; import com.fasterxml.jackson.databind.DeserializationContext; import com.fasterxml.jackson.databind.JsonDeserializer; -import com.fasterxml.jackson.databind.JsonNode; -import com.fasterxml.jackson.databind.ObjectMapper; import uulm.teamname.marvelous.gamelibrary.IntVector2; import java.io.IOException; @@ -15,7 +11,6 @@ public class IntVector2Deserializer extends JsonDeserializer { @Override public IntVector2 deserialize(JsonParser p, DeserializationContext ctxt) throws IOException { var values = p.readValueAs(Integer[].class); - IntVector2 result = new IntVector2(values[0], values[1]); - return result; + return new IntVector2(values[0], values[1]); } } diff --git a/src/main/java/uulm/teamname/marvelous/gamelibrary/json/ingame/deserialize/RequestDeserializer.java b/src/main/java/uulm/teamname/marvelous/gamelibrary/json/ingame/deserialize/RequestDeserializer.java index bd803da..b3a48cd 100644 --- a/src/main/java/uulm/teamname/marvelous/gamelibrary/json/ingame/deserialize/RequestDeserializer.java +++ b/src/main/java/uulm/teamname/marvelous/gamelibrary/json/ingame/deserialize/RequestDeserializer.java @@ -1,7 +1,6 @@ package uulm.teamname.marvelous.gamelibrary.json.ingame.deserialize; import com.fasterxml.jackson.core.JsonParser; -import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.core.ObjectCodec; import com.fasterxml.jackson.databind.DeserializationContext; import com.fasterxml.jackson.databind.JsonDeserializer; @@ -39,7 +38,7 @@ public class RequestDeserializer extends JsonDeserializer { .withTargetField(unwrap(node.get("targetField"), IntVector2.class, codec)) .withStoneType(Optional.ofNullable(unwrap(node.get("stoneType"), EntityID.class, codec)) .map(x -> StoneType.valueOf(x.id)) - .orElseGet(() -> null)); + .orElse(null)); switch (requestType) { case DisconnectRequest, diff --git a/src/main/java/uulm/teamname/marvelous/gamelibrary/json/ingame/serialize/RequestSerializer.java b/src/main/java/uulm/teamname/marvelous/gamelibrary/json/ingame/serialize/RequestSerializer.java index 7e20c53..2e217b4 100644 --- a/src/main/java/uulm/teamname/marvelous/gamelibrary/json/ingame/serialize/RequestSerializer.java +++ b/src/main/java/uulm/teamname/marvelous/gamelibrary/json/ingame/serialize/RequestSerializer.java @@ -39,6 +39,7 @@ public class RequestSerializer extends StdSerializer { } /** Method invoked after writing the RequestType, and used to write any additional values required */ + @SuppressWarnings({"EmptyMethod", "UnnecessaryReturnStatement"}) private void serializeGameRequest(GameRequest value, JsonGenerator gen, SerializerProvider provider) throws IOException { return; // does nothing, but still there for consistency diff --git a/src/main/java/uulm/teamname/marvelous/gamelibrary/messages/BasicMessage.java b/src/main/java/uulm/teamname/marvelous/gamelibrary/messages/BasicMessage.java index 760ca11..7dc456d 100644 --- a/src/main/java/uulm/teamname/marvelous/gamelibrary/messages/BasicMessage.java +++ b/src/main/java/uulm/teamname/marvelous/gamelibrary/messages/BasicMessage.java @@ -3,8 +3,6 @@ package uulm.teamname.marvelous.gamelibrary.messages; import com.fasterxml.jackson.annotation.JsonSubTypes; import com.fasterxml.jackson.annotation.JsonSubTypes.Type; import com.fasterxml.jackson.annotation.JsonTypeInfo; -import com.fasterxml.jackson.databind.annotation.JsonDeserialize; -import com.fasterxml.jackson.databind.annotation.JsonTypeResolver; import java.util.Objects; @@ -13,7 +11,7 @@ import java.util.Objects; * messageType, as fields that aren't sent are null. Note that most messages are not deserialized into the {@link * BasicMessage}, but instead into messages such as the {@link EventMessage} or {@link GameAssignmentMessage}. */ -@JsonTypeInfo(use = JsonTypeInfo.Id.NAME, include = JsonTypeInfo.As.PROPERTY, property = "messageType") +@JsonTypeInfo(use = JsonTypeInfo.Id.NAME, property = "messageType") @JsonSubTypes({ @Type(value = HelloClientMessage.class, name = "HELLO_CLIENT"), @Type(value = HelloServerMessage.class, name = "HELLO_SERVER"), diff --git a/src/main/java/uulm/teamname/marvelous/gamelibrary/messages/EventMessage.java b/src/main/java/uulm/teamname/marvelous/gamelibrary/messages/EventMessage.java index 3d7dd17..dad71f3 100644 --- a/src/main/java/uulm/teamname/marvelous/gamelibrary/messages/EventMessage.java +++ b/src/main/java/uulm/teamname/marvelous/gamelibrary/messages/EventMessage.java @@ -1,7 +1,6 @@ package uulm.teamname.marvelous.gamelibrary.messages; import com.fasterxml.jackson.annotation.JsonIgnore; -import com.fasterxml.jackson.databind.annotation.JsonDeserialize; import uulm.teamname.marvelous.gamelibrary.events.Event; import java.util.Arrays; diff --git a/src/main/java/uulm/teamname/marvelous/gamelibrary/messages/GameAssignmentMessage.java b/src/main/java/uulm/teamname/marvelous/gamelibrary/messages/GameAssignmentMessage.java index 454b869..5221237 100644 --- a/src/main/java/uulm/teamname/marvelous/gamelibrary/messages/GameAssignmentMessage.java +++ b/src/main/java/uulm/teamname/marvelous/gamelibrary/messages/GameAssignmentMessage.java @@ -1,7 +1,5 @@ package uulm.teamname.marvelous.gamelibrary.messages; -import com.fasterxml.jackson.databind.annotation.JsonDeserialize; -import uulm.teamname.marvelous.gamelibrary.config.CharacterConfig; import uulm.teamname.marvelous.gamelibrary.config.CharacterProperties; import java.util.Arrays; diff --git a/src/main/java/uulm/teamname/marvelous/gamelibrary/messages/GameStructureMessage.java b/src/main/java/uulm/teamname/marvelous/gamelibrary/messages/GameStructureMessage.java index aeacf40..e2537d7 100644 --- a/src/main/java/uulm/teamname/marvelous/gamelibrary/messages/GameStructureMessage.java +++ b/src/main/java/uulm/teamname/marvelous/gamelibrary/messages/GameStructureMessage.java @@ -6,7 +6,6 @@ import uulm.teamname.marvelous.gamelibrary.config.CharacterProperties; import uulm.teamname.marvelous.gamelibrary.config.PartyConfig; import uulm.teamname.marvelous.gamelibrary.config.ScenarioConfig; -import java.lang.reflect.Array; import java.util.Arrays; import java.util.Objects; import java.util.stream.Stream; diff --git a/src/test/java/uulm/teamname/marvelous/gamelibrary/events/EventBuilderTest.java b/src/test/java/uulm/teamname/marvelous/gamelibrary/events/EventBuilderTest.java index 111bdaa..6611117 100644 --- a/src/test/java/uulm/teamname/marvelous/gamelibrary/events/EventBuilderTest.java +++ b/src/test/java/uulm/teamname/marvelous/gamelibrary/events/EventBuilderTest.java @@ -10,7 +10,6 @@ import uulm.teamname.marvelous.gamelibrary.IntVector2; import uulm.teamname.marvelous.gamelibrary.entities.*; import uulm.teamname.marvelous.gamelibrary.entities.Character; -import java.util.ArrayList; import java.util.HashMap; class EventBuilderTest { @@ -127,8 +126,8 @@ class EventBuilderTest { .buildGameEvent(); assertThat(roundSetupEvent.check()) - .isTrue() - .withFailMessage("RoundSetupEvent failed check"); + .withFailMessage("RoundSetupEvent failed check") + .isTrue(); var roundSetupEventBaseline = new GameEvent(); roundSetupEventBaseline.type = EventType.RoundSetupEvent; @@ -145,8 +144,8 @@ class EventBuilderTest { .buildGameEvent(); assertThat(turnEvent.check()) - .isTrue() - .withFailMessage("TurnEvent failed check"); + .withFailMessage("TurnEvent failed check") + .isTrue(); var turnEventBaseline = new GameEvent(); turnEventBaseline.type = EventType.TurnEvent; @@ -172,8 +171,8 @@ class EventBuilderTest { .buildGameEvent(); assertThat(gameEvent.check()) - .isTrue() - .withFailMessage("GameEvent failed check"); + .withFailMessage("GameEvent failed check") + .isTrue(); var baseline = new GameEvent(); baseline.type = EventType.DisconnectEvent; @@ -201,8 +200,8 @@ class EventBuilderTest { .buildGameStateEvent(); assertThat(gameStateEvent.check()) - .isTrue() - .withFailMessage("GameStateEvent failed check"); + .withFailMessage("GameStateEvent failed check") + .isTrue(); var baseline = new GamestateEvent(); baseline.type = EventType.ConsumedAPEvent; @@ -226,7 +225,7 @@ class EventBuilderTest { //the target entity is not set --> check() return false boolean b = des2.check(); - assertEquals(b, false); + assertFalse(b); } @@ -240,7 +239,7 @@ class EventBuilderTest { //the target entity, the origin and the target entity are not set --> check() return false boolean b = des2.check(); - assertEquals(b, false); + assertFalse(b); } @@ -269,12 +268,12 @@ class EventBuilderTest { assertEquals(des.targetField, des2.targetField); // EntityEvent des2 = new EntityEvent(eb.); - assertEquals(des.equals(des2), true); + assertTrue(des.equals(des2)); assertEquals(des.hashCode(), des2.hashCode()); des.targetField = new IntVector2(3,3); - assertEquals(des.equals(des2), false); + assertFalse(des.equals(des2)); assertNotEquals(des.hashCode(), des2.hashCode()); @@ -312,12 +311,12 @@ class EventBuilderTest { assertEquals(des.originEntity, des2.originEntity); assertEquals(des.originField, des2.originField); - assertEquals(des.equals(des2), true); + assertTrue(des.equals(des2)); assertEquals(des.hashCode(), des2.hashCode()); des.targetField = new IntVector2(3,3); - assertEquals(des.equals(des2), false); + assertFalse(des.equals(des2)); assertNotEquals(des.hashCode(), des2.hashCode()); @@ -365,31 +364,31 @@ class EventBuilderTest { void buildCustomEvent() { //testing CustomEvent class assertThat(new EventBuilder(EventType.CustomEvent) - .withCustomContent(new HashMap()) + .withCustomContent(new HashMap<>()) .buildCustomEvent().check()).isTrue(); CustomEvent des = new CustomEvent(); des.type = EventType.CustomEvent; - des.customContent= new HashMap(); + des.customContent= new HashMap<>(); EventBuilder eb = new EventBuilder(EventType.CustomEvent); CustomEvent des2 = eb - .withCustomContent(new HashMap()) + .withCustomContent(new HashMap<>()) .buildCustomEvent(); //testing EventBuilder and CustomEvent class assertEquals(des.type, des2.type); assertEquals(des.customContent, des2.customContent); - assertEquals(des.equals(des2), true); + assertTrue(des.equals(des2)); assertEquals(des.hashCode(), des2.hashCode()); Object o = new Object(); - des.customContent = new HashMap(1,1); + des.customContent = new HashMap<>(1, 1); des.customContent.put("a",o); - assertEquals(des.equals(des2), false); + assertFalse(des.equals(des2)); assertNotEquals(des.hashCode(), des2.hashCode()); 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 964ca86..4646f65 100644 --- a/src/test/java/uulm/teamname/marvelous/gamelibrary/gamelogic/GameLogicTest.java +++ b/src/test/java/uulm/teamname/marvelous/gamelibrary/gamelogic/GameLogicTest.java @@ -7,7 +7,6 @@ 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.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 5e48d19..c399e00 100644 --- a/src/test/java/uulm/teamname/marvelous/gamelibrary/json/JSONTest.java +++ b/src/test/java/uulm/teamname/marvelous/gamelibrary/json/JSONTest.java @@ -14,7 +14,6 @@ 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.messages.EventMessage; -import uulm.teamname.marvelous.gamelibrary.messages.MessageType; import java.util.*; @@ -62,7 +61,7 @@ class JSONTest { }; target = new EventMessage(); target.customContentType = "TestCustomContent"; - target.customContent = new HashMap(); + target.customContent = new HashMap<>(); target.customContent.put("customKey", "customResult"); target.customContent.put("customNumber", 15); target.customContent.put("customProperty", true); @@ -88,7 +87,7 @@ class JSONTest { """; String completeMessageStructure = messageStructureStart + eventRepresentation + messageStructureEnd[1]; - target.messageType = MessageType.EVENTS; + // target.messageType = MessageType.EVENTS; target.messages = targetEvents; assertThat(json.parse(completeMessageStructure)).isEqualTo(target); diff --git a/src/test/java/uulm/teamname/marvelous/gamelibrary/json/ingame/deserialize/IntVector2DeserializerTest.java b/src/test/java/uulm/teamname/marvelous/gamelibrary/json/ingame/deserialize/IntVector2DeserializerTest.java index 745a3d6..1b44534 100644 --- a/src/test/java/uulm/teamname/marvelous/gamelibrary/json/ingame/deserialize/IntVector2DeserializerTest.java +++ b/src/test/java/uulm/teamname/marvelous/gamelibrary/json/ingame/deserialize/IntVector2DeserializerTest.java @@ -5,17 +5,13 @@ import com.fasterxml.jackson.databind.ObjectMapper; import net.jqwik.api.ForAll; import net.jqwik.api.Property; import net.jqwik.api.lifecycle.BeforeProperty; -import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import uulm.teamname.marvelous.gamelibrary.IntVector2; import java.util.Iterator; import java.util.concurrent.ThreadLocalRandom; -import java.util.stream.IntStream; -import static org.mockito.Mockito.*; -import static org.junit.jupiter.api.Assertions.*; import static org.assertj.core.api.Assertions.*; class IntVector2DeserializerTest { @@ -67,4 +63,4 @@ class IntVector2DeserializerTest { assertThat(mapper.readValue(String.format("[%d, %d]", someX, someY), IntVector2.class)) .isEqualTo(new IntVector2(someX, someY)); } -} \ No newline at end of file +} diff --git a/src/test/java/uulm/teamname/marvelous/gamelibrary/json/ingame/deserialize/MessageDeserializerTest.java b/src/test/java/uulm/teamname/marvelous/gamelibrary/json/ingame/deserialize/MessageDeserializerTest.java new file mode 100644 index 0000000..e1a4bd6 --- /dev/null +++ b/src/test/java/uulm/teamname/marvelous/gamelibrary/json/ingame/deserialize/MessageDeserializerTest.java @@ -0,0 +1,353 @@ +package uulm.teamname.marvelous.gamelibrary.json.ingame.deserialize; + +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.ObjectMapper; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import uulm.teamname.marvelous.gamelibrary.config.*; +import uulm.teamname.marvelous.gamelibrary.messages.*; + +import static org.assertj.core.api.Assertions.*; + +public class MessageDeserializerTest { + + ObjectMapper mapper; + + @BeforeEach + void beforeEach() { + mapper = new ObjectMapper(); + } + + @Test + void CharacterSelectionDeserializationTest() throws JsonProcessingException { + var jsonRepresentingMessage = """ + { + "messageType":"CHARACTER_SELECTION", + "characters":[false,true,false,true,false,true,false,true,false,true,false,true] + } + """.replace("\n", ""); + + var message = new CharacterSelectionMessage(); +// message.messageType = MessageType.CHARACTER_SELECTION; + message.characters = new Boolean[] {false,true,false,true,false,true,false,true,false,true,false,true}; + + assertThat( + ((CharacterSelectionMessage) mapper.readValue(jsonRepresentingMessage, BasicMessage.class))) + .isEqualTo(message); + } + + @Test + void confirmSelectionTest() throws JsonProcessingException { + var jsonRepresentingMessage = """ + { + "messageType":"CONFIRM_SELECTION", + "selectionComplete":true + } + """; + + var message = new ConfirmSelectionMessage(); +// message.messageType = MessageType.CONFIRM_SELECTION; + message.selectionComplete = true; + + assertThat(mapper.readValue(jsonRepresentingMessage, ConfirmSelectionMessage.class)) + .isEqualTo(message); + } + + @Test + void errorTest() throws JsonProcessingException { + var jsonRepresentingMessage = """ + { + "messageType":"ERROR", + "message": "error error", + "type":0 + } + """; + var message = new ErrorMessage(); +// message.messageType = MessageType.ERROR; + message.message = "error error"; + message.type = 0; + + assertThat(mapper.readValue(jsonRepresentingMessage, ErrorMessage.class)) + .isEqualTo(message); + } + + @Test + void gameAssignmentTest() throws JsonProcessingException { + var jsonRepresentingMessage = """ + { + "messageType":"GAME_ASSIGNMENT", + "gameID":"6a39c3cf-26d8-409e-a309-45590f38ec4f", + "characterSelection":[ + { + "characterID": 1, + "name": "Rocket Raccoon", + "HP": 100, + "MP": 2, + "AP": 2, + "meleeDamage": 10, + "rangeCombatDamage": 30, + "rangeCombatReach": 5 + }, + { + "characterID": 2, + "name": "Quicksilver", + "HP": 100, + "MP": 6, + "AP": 1, + "meleeDamage": 10, + "rangeCombatDamage": 10, + "rangeCombatReach": 3 + }, + { + "characterID": 3, + "name": "Hulk", + "HP": 100, + "MP": 2, + "AP": 2, + "meleeDamage": 10, + "rangeCombatDamage": 30, + "rangeCombatReach": 5 + } + ] + } + """; + + var racoon = new CharacterProperties(); + + racoon.characterID = 1; + racoon.name = "Rocket Raccoon"; + racoon.HP = 100; + racoon.MP = 2; + racoon.AP = 2; + racoon.meleeDamage = 10; + racoon.rangedDamage = 30; + racoon.attackRange = 5; + + + var quicksilver = new CharacterProperties(); + + quicksilver.characterID = 2; + quicksilver.name = "Quicksilver"; + quicksilver.HP = 100; + quicksilver.MP = 6; + quicksilver.AP = 1; + quicksilver.meleeDamage = 10; + quicksilver.rangedDamage = 10; + quicksilver.attackRange = 3; + + + var hulk = new CharacterProperties(); + + hulk.characterID = 3; + hulk.name = "Hulk"; + hulk.HP = 100; + hulk.MP = 2; + hulk.AP = 2; + hulk.meleeDamage = 10; + hulk.rangedDamage = 30; + hulk.attackRange = 5; + + var message = new GameAssignmentMessage(); +// message.messageType = MessageType.GAME_ASSIGNMENT; + message.gameID = "6a39c3cf-26d8-409e-a309-45590f38ec4f"; + message.characterSelection = new CharacterProperties[] {racoon, quicksilver, hulk}; + + assertThat(mapper.readValue(jsonRepresentingMessage, GameAssignmentMessage.class)) + .isEqualTo(message); + } + + @Test + void testGameStructure() throws JsonProcessingException { + var jsonRepresentingGameStructure = """ + { + "messageType":"GAME_STRUCTURE", + "assignment": "PlayerOne", + "playerOneName": "Gandalf", + "playerTwoName": "Bilbo", + "playerOneCharacters":[ + { + "characterID": 1, + "name": "Rocket Raccoon", + "HP": 100, + "MP": 2, + "AP": 2, + "meleeDamage": 10, + "rangeCombatDamage": 30, + "rangeCombatReach": 5 + }, + { + "characterID": 2, + "name": "Quicksilver", + "HP": 100, + "MP": 6, + "AP": 1, + "meleeDamage": 10, + "rangeCombatDamage": 10, + "rangeCombatReach": 3 + }, + { + "characterID": 3, + "name": "Hulk", + "HP": 100, + "MP": 2, + "AP": 2, + "meleeDamage": 10, + "rangeCombatDamage": 30, + "rangeCombatReach": 5 + } + ], + "playerTwoCharacters":[ + { + "characterID": 19, + "name": "Loki", + "HP": 100, + "MP": 6, + "AP": 1, + "meleeDamage": 10, + "rangeCombatDamage": 10, + "rangeCombatReach": 3 + }, + { + "characterID": 20, + "name": "Silver Surfer", + "HP": 100, + "MP": 6, + "AP": 1, + "meleeDamage": 10, + "rangeCombatDamage": 10, + "rangeCombatReach": 3 + } + ], + "scenarioconfig": { + "scenario":[ + ["GRASS","GRASS", "GRASS", "GRASS", "GRASS", "GRASS", "GRASS"], + ["GRASS","GRASS", "GRASS", "ROCK", "GRASS", "GRASS", "GRASS"], + ["GRASS","GRASS", "GRASS", "ROCK", "GRASS", "GRASS", "GRASS"], + ["GRASS","GRASS", "GRASS", "ROCK", "GRASS", "GRASS", "GRASS"], + ["GRASS","GRASS", "ROCK", "ROCK", "ROCK", "GRASS", "GRASS"], + ["GRASS","ROCK", "ROCK", "ROCK", "ROCK", "ROCK", "GRASS"] + ], + "author": "jakobmh", + "name": "asgard" + }, + "matchconfig": { + "maxRounds": 30, + "maxRoundTime": 300, + "maxGameTime": 1800, + "maxAnimationTime": 50 + } + } + """; + + var racoon = new CharacterProperties(); + + racoon.characterID = 1; + racoon.name = "Rocket Raccoon"; + racoon.HP = 100; + racoon.MP = 2; + racoon.AP = 2; + racoon.meleeDamage = 10; + racoon.rangedDamage = 30; + racoon.attackRange = 5; + + + var quicksilver = new CharacterProperties(); + + quicksilver.characterID = 2; + quicksilver.name = "Quicksilver"; + quicksilver.HP = 100; + quicksilver.MP = 6; + quicksilver.AP = 1; + quicksilver.meleeDamage = 10; + quicksilver.rangedDamage = 10; + quicksilver.attackRange = 3; + + + var hulk = new CharacterProperties(); + + hulk.characterID = 3; + hulk.name = "Hulk"; + hulk.HP = 100; + hulk.MP = 2; + hulk.AP = 2; + hulk.meleeDamage = 10; + hulk.rangedDamage = 30; + hulk.attackRange = 5; + + var loki = new CharacterProperties(); + + loki.characterID = 19; + loki.name = "Loki"; + loki.HP = 100; + loki.MP = 6; + loki.AP = 1; + loki.meleeDamage = 10; + loki.rangedDamage = 10; + loki.attackRange = 3; + + var silversurfer = new CharacterProperties(); + + silversurfer.characterID = 20; + silversurfer.name = "Silver Surfer"; + silversurfer.HP = 100; + silversurfer.MP = 6; + silversurfer.AP = 1; + silversurfer.meleeDamage = 10; + silversurfer.rangedDamage = 10; + silversurfer.attackRange = 3; + + var scenarioConfig = new ScenarioConfig(); + + scenarioConfig.scenario = new FieldType[][] { + {FieldType.GRASS, FieldType.GRASS, FieldType.GRASS, FieldType.GRASS, FieldType.GRASS, FieldType.GRASS, FieldType.GRASS} , + {FieldType.GRASS, FieldType.GRASS, FieldType.GRASS, FieldType.ROCK, FieldType.GRASS, FieldType.GRASS, FieldType.GRASS} , + {FieldType.GRASS, FieldType.GRASS, FieldType.GRASS, FieldType.ROCK, FieldType.GRASS, FieldType.GRASS, FieldType.GRASS} , + {FieldType.GRASS, FieldType.GRASS, FieldType.GRASS, FieldType.ROCK, FieldType.GRASS, FieldType.GRASS, FieldType.GRASS} , + {FieldType.GRASS, FieldType.GRASS, FieldType.ROCK, FieldType.ROCK, FieldType.ROCK, FieldType.GRASS, FieldType.GRASS} , + {FieldType.GRASS, FieldType.ROCK, FieldType.ROCK, FieldType.ROCK, FieldType.ROCK, FieldType.ROCK, FieldType.GRASS} + }; + + scenarioConfig.author = "jakobmh"; + scenarioConfig.name = "asgard"; + + var matchconfig = new PartyConfig(); + + matchconfig.maxRounds = 30; + matchconfig.maxRoundTime = 300; + matchconfig.maxGameTime = 1800; + matchconfig.maxAnimationTime = 50; + + var message = new GameStructureMessage(); + +// message.messageType = MessageType.GAME_STRUCTURE; + message.assignment = Assignment.PlayerOne; + message.playerOneName = "Gandalf"; + message.playerTwoName = "Bilbo"; + message.playerOneCharacters = new CharacterProperties[] {racoon, quicksilver, hulk}; + message.playerTwoCharacters = new CharacterProperties[] {loki, silversurfer}; + message.scenarioconfig = scenarioConfig; + message.matchconfig = matchconfig; + + assertThat((GameStructureMessage) mapper.readValue(jsonRepresentingGameStructure, BasicMessage.class)) + .isEqualTo(message); + + } + + + @Test + void generalAssignmentTest() throws JsonProcessingException { + var jsonRepresentingMessage = """ + { + "messageType":"GENERAL_ASSIGNMENT", + "gameID":"6a39c3cf-26d8-409e-a309-45590f38ec4f" + } + """; + + var message = new GeneralAssignmentMessage(); +// message.messageType = MessageType.GENERAL_ASSIGNMENT; + message.gameID = "6a39c3cf-26d8-409e-a309-45590f38ec4f"; + + assertThat((GeneralAssignmentMessage) mapper.readValue(jsonRepresentingMessage, BasicMessage.class)) + .isEqualTo(message); + } +} diff --git a/src/test/java/uulm/teamname/marvelous/gamelibrary/json/ingame/serialize/EntitySerializerTest.java b/src/test/java/uulm/teamname/marvelous/gamelibrary/json/ingame/serialize/EntitySerializerTest.java index 2c6cd53..f737374 100644 --- a/src/test/java/uulm/teamname/marvelous/gamelibrary/json/ingame/serialize/EntitySerializerTest.java +++ b/src/test/java/uulm/teamname/marvelous/gamelibrary/json/ingame/serialize/EntitySerializerTest.java @@ -6,13 +6,9 @@ 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.entities.Rock; -import uulm.teamname.marvelous.gamelibrary.json.ingame.deserialize.EntityDeserializer; import java.util.ArrayList; -import static org.mockito.Mockito.*; -import static org.junit.jupiter.api.Assertions.*; import static org.assertj.core.api.Assertions.*; class EntitySerializerTest { diff --git a/src/test/java/uulm/teamname/marvelous/gamelibrary/json/ingame/serialize/EventSerializerTest.java b/src/test/java/uulm/teamname/marvelous/gamelibrary/json/ingame/serialize/EventSerializerTest.java index bf94564..8a4a69a 100644 --- a/src/test/java/uulm/teamname/marvelous/gamelibrary/json/ingame/serialize/EventSerializerTest.java +++ b/src/test/java/uulm/teamname/marvelous/gamelibrary/json/ingame/serialize/EventSerializerTest.java @@ -7,14 +7,11 @@ import com.fasterxml.jackson.databind.ObjectMapper; 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.events.*; import java.util.HashMap; import static org.assertj.core.api.Assertions.*; -import static org.assertj.core.api.Assertions.assertThat; -import static org.junit.jupiter.api.Assertions.assertEquals; public class EventSerializerTest { //System.out.println(mapper.writeValueAsString(gse)); @@ -289,7 +286,7 @@ public class EventSerializerTest { CustomEvent ce = new CustomEvent(); ce.type = EventType.CustomEvent; ce.teamIdentifier ="identity"; - ce.customContent = new HashMap(1,1); + ce.customContent = new HashMap<>(1, 1); var jsonRepresentingEE = """ diff --git a/src/test/java/uulm/teamname/marvelous/gamelibrary/json/ingame/serialize/IntVector2SerializerTest.java b/src/test/java/uulm/teamname/marvelous/gamelibrary/json/ingame/serialize/IntVector2SerializerTest.java index f9f956d..3223c19 100644 --- a/src/test/java/uulm/teamname/marvelous/gamelibrary/json/ingame/serialize/IntVector2SerializerTest.java +++ b/src/test/java/uulm/teamname/marvelous/gamelibrary/json/ingame/serialize/IntVector2SerializerTest.java @@ -6,8 +6,6 @@ import net.jqwik.api.*; import net.jqwik.api.lifecycle.BeforeProperty; import uulm.teamname.marvelous.gamelibrary.IntVector2; -import static org.mockito.Mockito.*; -import static org.junit.jupiter.api.Assertions.*; import static org.assertj.core.api.Assertions.*; class IntVector2SerializerTest { @@ -34,4 +32,4 @@ class IntVector2SerializerTest { .map(pos -> new IntVector2(pos.get1(), pos.get2())); } -} \ No newline at end of file +} diff --git a/src/test/java/uulm/teamname/marvelous/gamelibrary/json/ingame/serialize/RequestSerializerTest.java b/src/test/java/uulm/teamname/marvelous/gamelibrary/json/ingame/serialize/RequestSerializerTest.java index c12654d..fa3f7c9 100644 --- a/src/test/java/uulm/teamname/marvelous/gamelibrary/json/ingame/serialize/RequestSerializerTest.java +++ b/src/test/java/uulm/teamname/marvelous/gamelibrary/json/ingame/serialize/RequestSerializerTest.java @@ -97,8 +97,8 @@ public class RequestSerializerTest { // Note that everything that follows could be extracted into another class, // but that's complicated, so I won't do it - static Set characterRequestTypes; - static Set gameRequestTypes; + static final Set characterRequestTypes; + static final Set gameRequestTypes; static { characterRequestTypes = new HashSet<>(); @@ -183,7 +183,7 @@ public class RequestSerializerTest { } else { actualID = id; } - return new EntityID(type, id); + return new EntityID(type, actualID); }); } @@ -204,8 +204,9 @@ public class RequestSerializerTest { .map(pos -> new IntVector2(pos.get1(), pos.get2())); } - @Provide("attackPositions") + /** Returns tuples of origin vectors (of an attack), and the vector pointing to the attack dir */ + @Provide("attackPositions") private Arbitrary> attackPositions() { return Combinators.combine(randomPositions(), directions().tuple5()) .as((origin, dir) -> { diff --git a/src/test/java/uulm/teamname/marvelous/gamelibrary/requests/RequestBuilderTest.java b/src/test/java/uulm/teamname/marvelous/gamelibrary/requests/RequestBuilderTest.java index b3e0118..404ca96 100644 --- a/src/test/java/uulm/teamname/marvelous/gamelibrary/requests/RequestBuilderTest.java +++ b/src/test/java/uulm/teamname/marvelous/gamelibrary/requests/RequestBuilderTest.java @@ -1,17 +1,12 @@ package uulm.teamname.marvelous.gamelibrary.requests; -import static org.junit.jupiter.api.Assertions.*; -import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; -import static org.assertj.core.api.Assertions.*; import static org.junit.jupiter.api.Assertions.*; import uulm.teamname.marvelous.gamelibrary.IntVector2; import uulm.teamname.marvelous.gamelibrary.entities.*; -import uulm.teamname.marvelous.gamelibrary.entities.Character; -import java.util.ArrayList; import java.util.HashMap; class RequestBuilderTest { @@ -52,8 +47,8 @@ class RequestBuilderTest { map.put(1,StoneType.SoulStone); cr3.stoneType = StoneType.valueOf(1); - assertEquals(cr.equals(cr2), true); - assertEquals(cr.equals(cr3), false); + assertTrue(cr.equals(cr2)); + assertFalse(cr.equals(cr3)); assertEquals(cr.hashCode(), cr2.hashCode()); assertNotEquals(cr.hashCode(), cr3.hashCode()); @@ -87,7 +82,7 @@ class RequestBuilderTest { //since we tested in the test before that the equals() method from the CharacterRequest class works fine // we can use this method here. and do not have to test all properties for itself, e.g.: "assertEquals(cr.targetEntity, cr2.targetEntity)"; - assertEquals(cr.equals(cr2), true); + assertTrue(cr.equals(cr2)); } @@ -109,4 +104,4 @@ class RequestBuilderTest { } -} \ No newline at end of file +}