refactor: fixing codestyle and improving codequality
This commit is contained in:
parent
29f5eed2fb
commit
de6e9abfd7
@ -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 <E> ArrayList<E> toArrayList(E[] a) {
|
||||
ArrayList<E> l = new ArrayList<>(a.length);
|
||||
for(E e: a) {
|
||||
l.add(e);
|
||||
}
|
||||
l.addAll(Arrays.asList(a));
|
||||
return l;
|
||||
}
|
||||
}
|
||||
|
@ -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;
|
||||
|
@ -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;
|
||||
}
|
||||
|
||||
|
@ -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 {
|
||||
|
||||
|
@ -55,21 +55,17 @@ public class EntityDeserializer extends JsonDeserializer<Entity> {
|
||||
((Character) result).inventory.addStone(StoneType.valueOf(i));
|
||||
}
|
||||
}
|
||||
case InfinityStone -> {
|
||||
result = new InfinityStone(
|
||||
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(
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
@ -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;
|
||||
|
@ -28,7 +28,7 @@ public class EventDeserializer extends JsonDeserializer<Event> {
|
||||
JsonNode currentNode = null;
|
||||
|
||||
EventBuilder builder;
|
||||
EventType eventType = null;
|
||||
EventType eventType;
|
||||
|
||||
if (!node.has("eventType")) {
|
||||
throw new IOException("Event had wrong format: no EventType found");
|
||||
|
@ -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<IntVector2> {
|
||||
@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]);
|
||||
}
|
||||
}
|
||||
|
@ -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<Request> {
|
||||
.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,
|
||||
|
@ -39,6 +39,7 @@ public class RequestSerializer extends StdSerializer<Request> {
|
||||
}
|
||||
|
||||
/** 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
|
||||
|
@ -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"),
|
||||
|
@ -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;
|
||||
|
@ -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;
|
||||
|
@ -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;
|
||||
|
@ -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<String, Object>())
|
||||
.withCustomContent(new HashMap<>())
|
||||
.buildCustomEvent().check()).isTrue();
|
||||
|
||||
CustomEvent des = new CustomEvent();
|
||||
des.type = EventType.CustomEvent;
|
||||
des.customContent= new HashMap<String, Object>();
|
||||
des.customContent= new HashMap<>();
|
||||
|
||||
|
||||
EventBuilder eb = new EventBuilder(EventType.CustomEvent);
|
||||
CustomEvent des2 = eb
|
||||
.withCustomContent(new HashMap<String, Object>())
|
||||
.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<String, Object>(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());
|
||||
|
||||
|
||||
|
@ -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.*;
|
||||
|
@ -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<String, Object>();
|
||||
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);
|
||||
|
@ -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 {
|
||||
|
@ -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);
|
||||
}
|
||||
}
|
@ -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 {
|
||||
|
@ -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<String, Object>(1,1);
|
||||
ce.customContent = new HashMap<>(1, 1);
|
||||
|
||||
|
||||
var jsonRepresentingEE = """
|
||||
|
@ -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 {
|
||||
|
@ -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<RequestType> characterRequestTypes;
|
||||
static Set<RequestType> gameRequestTypes;
|
||||
static final Set<RequestType> characterRequestTypes;
|
||||
static final Set<RequestType> 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<Tuple.Tuple2<IntVector2, IntVector2>> attackPositions() {
|
||||
return Combinators.combine(randomPositions(), directions().tuple5())
|
||||
.as((origin, dir) -> {
|
||||
|
@ -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));
|
||||
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user