From d06ac91ef806ee3d65634b96670816acf1b8ba5d Mon Sep 17 00:00:00 2001 From: punchready Date: Sun, 2 May 2021 14:28:51 +0200 Subject: [PATCH] refactor: clean up code and improve event builder --- .../gamelibrary/events/EventBuilder.java | 274 ++++++------------ .../gamelibrary/events/GameEvent.java | 4 +- .../gamelibrary/gamelogic/EntityManager.java | 1 - .../gamelibrary/gamelogic/GameStateView.java | 1 - .../gamelibrary/events/EventBuilderTest.java | 34 ++- 5 files changed, 113 insertions(+), 201 deletions(-) diff --git a/src/main/java/uulm/teamname/marvelous/gamelibrary/events/EventBuilder.java b/src/main/java/uulm/teamname/marvelous/gamelibrary/events/EventBuilder.java index a893b94..65ae474 100644 --- a/src/main/java/uulm/teamname/marvelous/gamelibrary/events/EventBuilder.java +++ b/src/main/java/uulm/teamname/marvelous/gamelibrary/events/EventBuilder.java @@ -5,8 +5,10 @@ import uulm.teamname.marvelous.gamelibrary.entities.Entity; import uulm.teamname.marvelous.gamelibrary.entities.EntityID; import uulm.teamname.marvelous.gamelibrary.entities.StoneType; +import java.lang.reflect.Field; import java.util.Arrays; import java.util.HashMap; +import java.util.StringJoiner; /** * A class made for building all sorts of {@link Event}s as nicely as possible. @@ -47,28 +49,18 @@ public class EventBuilder { private String teamIdentifier; private HashMap customContent; -// /** -// * Creates a new {@link EventBuilder} used for building {@link Event}s -// */ -// public EventBuilder() { -// -// } - - /** * Creates a new {@link EventBuilder} used for building {@link Event}s. - * - * @param eventType is the type of Event that the final event will have. + * @param eventType is the type of Event that the final event will have */ public EventBuilder(EventType eventType) { this.type = eventType; } - // with for builder pattern style things - /** - * Deprecated. Use constructor with EventType instead. + * @deprecated Use {@link #EventBuilder(EventType)} instead. */ + @Deprecated public EventBuilder withType(EventType type) { this.type = type; return this; @@ -89,7 +81,6 @@ public class EventBuilder { return this; } - public EventBuilder withEntity(Entity entity) { this.entity = entity; return this; @@ -110,12 +101,12 @@ public class EventBuilder { return this; } - public EventBuilder withRoundCount(int roundCount) { + public EventBuilder withRoundCount(Integer roundCount) { this.roundCount = roundCount; return this; } - public EventBuilder withTurnCount(int turnCount) { + public EventBuilder withTurnCount(Integer turnCount) { this.turnCount = turnCount; return this; } @@ -130,7 +121,7 @@ public class EventBuilder { return this; } - public EventBuilder withPlayerWon(int playerWon) { + public EventBuilder withPlayerWon(Integer playerWon) { this.playerWon = playerWon; return this; } @@ -140,7 +131,7 @@ public class EventBuilder { return this; } - public EventBuilder withTimeLeft(int timeLeft) { + public EventBuilder withTimeLeft(Integer timeLeft) { this.timeLeft = timeLeft; return this; } @@ -160,7 +151,7 @@ public class EventBuilder { return this; } - public EventBuilder withWinCondition(boolean winCondition) { + public EventBuilder withWinCondition(Boolean winCondition) { this.winCondition = winCondition; return this; } @@ -177,9 +168,10 @@ public class EventBuilder { /** * A method to check whether the current event is actually built correctly. If that is not the case, it - * throws an {@link IllegalStateException}. This occurs if for example a property is null even though it shouldn't - * be. The check is based on the EventType. !!! Using this method is strongly recommended when working with - * entities, as it prevents unnoticed bugs before they might happen !!! + * throws an {@link IllegalStateException}. + * This occurs if for example a property is null even though it shouldn't be. + * The check is based on the EventType. Using this method is strongly recommended when working with + * entities, as it prevents unnoticed bugs before they might happen! * * @throws IllegalStateException if the current event is non-valid */ @@ -314,19 +306,15 @@ public class EventBuilder { } /** - * Utility function for throwing a specific exception - * - * @throws IllegalStateException meaning that the event is non-valid for the current builder state + * Utility function for throwing a specific exception. + * @throws IllegalStateException if the builder hasn't received enough properties to construct the event */ private void throwException() throws IllegalStateException { - throw new IllegalStateException("Properties malformed for " + this.type + ".\n" + - "Builder properties: " + this.notNullToString()); + throw new IllegalStateException("Properties malformed for " + this.type + ".\n" + "Builder properties: " + this.notNullToString()); } /** - * Builds a generic {@link GameEvent} from the values given to the builder. - * This method checks for the correctness of the event before building it. If this is not desired, - * use the {@link #buildGameEventUnchecked()} method instead + * Builds a {@link GameEvent} from the values given to the builder. *
    *
  • type is the {@link EventType} of the {@link GameEvent}.
  • *
  • roundCount describes the count of rounds in the RoundSetupEvent
  • @@ -338,31 +326,21 @@ public class EventBuilder { *
  • timeLeft describes the time left for a client to act before getting kicked in the TimeoutWarning event
  • *
* - * @return a {@link GameEvent} based on the builder. Caution: non-given fields are null! + * @param checked Determines if properties should be checked + * @return a {@link GameEvent} based on the builder */ - public GameEvent buildGameEvent() throws IllegalStateException { - this.check(); - return buildGameEventUnchecked(); + public GameEvent buildGameEvent(boolean checked) throws IllegalStateException { + if(checked) { + this.check(); + } + return buildGameEvent(); } - /** - * Builds a generic {@link GameEvent} from the values given to the builder without checking whether this - * * event is valid. Please use checked method {@link #buildGameEvent()} instead - *
    - *
  • type is the {@link EventType} of the {@link GameEvent}.
  • - *
  • roundCount describes the count of rounds in the RoundSetupEvent
  • - *
  • turnCount describes the amount of turns taken in Events
  • - *
  • characterOrder describes the order in which characters have their turn
  • - *
  • nextCharacter describes the next character in the turn order in the TurnEvent
  • - *
  • playerWon describes the player that has won the game in the WinEvent
  • - *
  • message describes a generic message delivered as a String in several GameEvents. It is optional.
  • - *
  • timeLeft describes the time left for a client to act before getting kicked in the TimeoutWarning event
  • - *
- * - * @return a {@link GameEvent} based on the builder. Caution: non-given fields are null! + * Builds a {@link GameEvent} from the values given to the builder without checking. + * @return a {@link GameEvent} based on the builder */ - public GameEvent buildGameEventUnchecked() throws IllegalStateException { + private GameEvent buildGameEvent() { var gameEvent = new GameEvent(); gameEvent.type = this.type; gameEvent.roundCount = this.roundCount; @@ -379,38 +357,28 @@ public class EventBuilder { /** * Builds an {@link EntityEvent} from the values given to the builder. - * This method checks for the correctness of the event before building it. If this is not desired, - * use the {@link #buildEntityEventUnchecked()} method instead - * *
    *
  • type is the {@link EventType} of the EntityEvent
  • *
  • targetEntity is the target {@link Entity}
  • *
  • targetField is the target field in the form of an {@link IntVector2}
  • - *
  • amount is the amount of something, like damage. It's an int.
  • + *
  • amount is a generic amount, for example damage taken
  • *
* - * @return a {@link EntityEvent} based on the builder. Caution: non-given fields are null! + * @param checked Determines if properties should be checked + * @return an {@link EntityEvent} based on the builder */ - public EntityEvent buildEntityEvent() throws IllegalStateException { - this.check(); - return this.buildEntityEventUnchecked(); + public EntityEvent buildEntityEvent(boolean checked) throws IllegalStateException { + if(checked) { + this.check(); + } + return this.buildEntityEvent(); } - /** - * Builds an {@link EntityEvent} from the values given to the builder without checking whether this - * event is valid. Please use checked method {@link #buildEntityEvent()} instead - * - *
    - *
  • type is the {@link EventType} of the EntityEvent
  • - *
  • targetEntity is the target {@link Entity}
  • - *
  • targetField is the target field in the form of an {@link IntVector2}
  • - *
  • amount is the amount of something, like damage. It's an int.
  • - *
- * - * @return a {@link EntityEvent} based on the builder. Caution: non-given fields are null! + * Builds an {@link EntityEvent} from the values given to the builder without checking. + * @return an {@link EntityEvent} based on the builder */ - public EntityEvent buildEntityEventUnchecked() { + private EntityEvent buildEntityEvent() { var entityEvent = new EntityEvent(); entityEvent.type = this.type; entityEvent.targetEntity = this.targetEntity; @@ -421,10 +389,7 @@ public class EventBuilder { } /** - * Builds a generic {@link CharacterEvent} from the values given to the builder. - * This method checks for the correctness of the event before building it. If this is not desired, - * use the {@link #buildCharacterEventUnchecked()} method instead - * + * Builds a {@link CharacterEvent} from the values given to the builder. *
    *
  • type is the {@link EventType} of the EntityEvent
  • *
  • originEntity is the origin {@link Entity}
  • @@ -433,31 +398,21 @@ public class EventBuilder { *
  • targetField is the target field in the form of an {@link IntVector2}
  • *
* - * @return a {@link CharacterEvent} based on the builder. Caution: non-given fields are null! - * @throws IllegalStateException if the event being built is non-valid. + * @param checked Determines if properties should be checked + * @return a {@link CharacterEvent} based on the builder */ - public CharacterEvent buildCharacterEvent() throws IllegalStateException { - this.check(); - return buildCharacterEventUnchecked(); + public CharacterEvent buildCharacterEvent(boolean checked) throws IllegalStateException { + if(checked) { + this.check(); + } + return buildCharacterEvent(); } - /** - * Builds a generic {@link CharacterEvent} from the values given to the builder without checking whether this - * event is valid. Please use checked method {@link #buildCharacterEvent()} instead - * - *
    - *
  • type is the {@link EventType} of the EntityEvent
  • - *
  • originEntity is the origin {@link Entity}
  • - *
  • targetEntity is the target {@link Entity}
  • - *
  • originField is the field that an action originates in, delivered as an {@link IntVector2}
  • - *
  • targetField is the target field in the form of an {@link IntVector2}
  • - *
- * - * @return a {@link CharacterEvent} based on the builder. Caution: non-given fields are null! - * @throws IllegalStateException if the event being built is non-valid. + * Builds a {@link CharacterEvent} from the values given to the builder without checking. + * @return a {@link CharacterEvent} based on the builder */ - public CharacterEvent buildCharacterEventUnchecked() { + private CharacterEvent buildCharacterEvent() { var characterEvent = new CharacterEvent(); characterEvent.type = this.type; characterEvent.originEntity = this.originEntity; @@ -469,11 +424,8 @@ public class EventBuilder { return characterEvent; } - /** * Builds a generic {@link GameStateEvent} from the values given to the builder. - * This method checks for the correctness of the event before building it. If this is not desired, - * use the {@link #buildGameStateEventUnchecked()} method instead *
    *
  • type is the {@link EventType} of the {@link GameStateEvent}
  • *
  • entities is an array of {@link Entity Entities}
  • @@ -482,29 +434,21 @@ public class EventBuilder { *
  • describes whether the win condition is in effect
  • *
* - * @return a {@link GameStateEvent} based on the builder. Caution: non-given fields are null! - * @throws IllegalStateException if the event being built is non-valid. + * @param checked Determines if properties should be checked + * @return a {@link GameStateEvent} based on the builder */ - public GameStateEvent buildGameStateEvent() throws IllegalStateException { - this.check(); - return this.buildGameStateEventUnchecked(); + public GameStateEvent buildGameStateEvent(boolean checked) throws IllegalStateException { + if(checked) { + this.check(); + } + return this.buildGameStateEvent(); } - /** - * Builds a generic {@link GameStateEvent} from the values given to the builder without checking whether this - * event is valid. Please use checked method {@link #buildGameStateEvent()} instead - *
    - *
  • type is the {@link EventType} of the {@link GameStateEvent}
  • - *
  • entities is an array of {@link Entity Entities}
  • - *
  • turnOrder describes the order in which characters take turns
  • - *
  • activeCharacter describes the currently active character
  • - *
  • describes whether the win condition is in effect
  • - *
- * - * @return a {@link GameStateEvent} based on the builder. Caution: non-given fields are null! + * Builds a {@link GameStateEvent} from the values given to the builder without checking. + * @return a {@link GameStateEvent} based on the builder */ - public GameStateEvent buildGameStateEventUnchecked() { + private GameStateEvent buildGameStateEvent() { var gameStateEvent = new GameStateEvent(); gameStateEvent.type = this.type; gameStateEvent.entities = this.entities; @@ -515,33 +459,27 @@ public class EventBuilder { } /** - * Builds a {@link CustomEvent} from the values given to the builder. This method checks for the correctness of the - * event before building it. If this is not desired, use the {@link #buildCustomEventUnchecked()} method instead + * Builds a {@link CustomEvent} from the values given to the builder. *
    *
  • teamIdentifier is a String for identifying a specific custom content
  • *
  • customContent is a {@link HashMap}<{@link String}, {@link Object}> resembling the JSON keys in the event
  • *
* - * @return a {@link CustomEvent} based on the builder. Caution: non-given fields are null! - * @throws IllegalStateException if the event being built is non-valid. + * @param checked Determines if properties should be checked + * @return a {@link CustomEvent} based on the builder */ - public CustomEvent buildCustomEvent() throws IllegalStateException { - this.check(); - var customEvent = new CustomEvent(); - return this.buildCustomEventUnchecked(); + public CustomEvent buildCustomEvent(boolean checked) throws IllegalStateException { + if(checked) { + this.check(); + } + return this.buildCustomEvent(); } /** - * Builds a {@link CustomEvent} from the values given to the builder without checking whether this event - * is valid. Please use checked method {@link #buildCustomEvent()} instead - *
    - *
  • teamIdentifier is a String for identifying a specific custom content
  • - *
  • customContent is a {@link HashMap}<{@link String}, {@link Object}> resembling the JSON keys in the event
  • - *
- * - * @return a {@link CustomEvent} based on the builder. Caution: non-given fields are null! + * Builds a {@link CustomEvent} from the values given to the builder without checking. + * @return a {@link CustomEvent} based on the builder */ - public CustomEvent buildCustomEventUnchecked() { + private CustomEvent buildCustomEvent() { var customEvent = new CustomEvent(); customEvent.type = this.type; customEvent.teamIdentifier = this.teamIdentifier; @@ -551,55 +489,29 @@ public class EventBuilder { @Override public String toString() { - return "EventBuilder{" + - "\ntype=" + type + - ",\n targetEntity=" + targetEntity + - ",\n targetField=" + targetField + - ",\n amount=" + amount + - ",\n entity=" + entity + - ",\n originEntity=" + originEntity + - ",\n originField=" + originField + - ",\n stoneType=" + stoneType + - ",\n roundCount=" + roundCount + - ",\n turnCount=" + turnCount + - ",\n characterOrder=" + Arrays.toString(characterOrder) + - ",\n nextCharacter=" + nextCharacter + - ",\n playerWon=" + playerWon + - ",\n message='" + message + '\'' + - ",\n timeLeft=" + timeLeft + - ",\n entities=" + Arrays.toString(entities) + - ",\n turnOrder=" + Arrays.toString(turnOrder) + - ",\n activeCharacter=" + activeCharacter + - ",\n winCondition=" + winCondition + - ",\n teamIdentifier='" + teamIdentifier + '\'' + - ",\n customContent=" + customContent + - "\n}"; + StringJoiner joiner = new StringJoiner("\n"); + joiner.add("EventBuilder(all) {"); + for(Field field: this.getClass().getDeclaredFields()) { + try { + joiner.add(field.getName() + " = " + field.get(this)); + }catch(IllegalAccessException ignore) { } + } + joiner.add("}"); + return joiner.toString(); } - public String notNullToString() { - return "EventBuilder (only not null) {" + - (type != null ? "\n type=" + type : "" )+ - (targetEntity != null ? "\n targetEntity=" + targetEntity : "" )+ - (targetField != null ? "\n targetField=" + targetField : "" )+ - (amount != null ? "\n amount=" + amount : "" )+ - (entity != null ? "\n entity=" + entity : "" )+ - (originEntity != null ? "\n originEntity=" + originEntity : "" )+ - (originField != null ? "\n originField=" + originField : "" )+ - (stoneType != null ? "\n stoneType=" + stoneType : "" )+ - (roundCount != null ? "\n roundCount=" + roundCount : "" )+ - (turnCount != null ? "\n turnCount=" + turnCount : "" )+ - (characterOrder != null ? "\n characterOrder=" + Arrays.toString(characterOrder) : "" )+ - (nextCharacter != null ? "\n nextCharacter=" + nextCharacter : "" )+ - (playerWon != null ? "\n playerWon=" + playerWon : "" )+ - (message != null ? "\n message='" + message : "" )+ '\'' + - (timeLeft != null ? "\n timeLeft=" + timeLeft : "" )+ - (entities != null ? "\n entities=" + Arrays.toString(entities) : "" )+ - (turnOrder != null ? "\n turnOrder=" + Arrays.toString(turnOrder) : "" )+ - (activeCharacter != null ? "\n activeCharacter=" + activeCharacter : "" )+ - (winCondition != null ? "\n winCondition=" + winCondition : "" )+ - (teamIdentifier != null ? "\n teamIdentifier='" + teamIdentifier : "" )+ '\'' + - (customContent != null ? "\n customContent=" + customContent : "" )+ - "\n}"; + StringJoiner joiner = new StringJoiner("\n"); + joiner.add("EventBuilder(non-null) {"); + for(Field field: this.getClass().getDeclaredFields()) { + try { + Object value = field.get(this); + if(value != null) { + joiner.add(field.getName() + " = " + value); + } + }catch(IllegalAccessException ignore) { } + } + joiner.add("}"); + return joiner.toString(); } -} \ No newline at end of file +} diff --git a/src/main/java/uulm/teamname/marvelous/gamelibrary/events/GameEvent.java b/src/main/java/uulm/teamname/marvelous/gamelibrary/events/GameEvent.java index 0530e6c..43d9079 100644 --- a/src/main/java/uulm/teamname/marvelous/gamelibrary/events/GameEvent.java +++ b/src/main/java/uulm/teamname/marvelous/gamelibrary/events/GameEvent.java @@ -1,8 +1,6 @@ package uulm.teamname.marvelous.gamelibrary.events; -import uulm.teamname.marvelous.gamelibrary.IntVector2; import uulm.teamname.marvelous.gamelibrary.entities.EntityID; -import uulm.teamname.marvelous.gamelibrary.entities.StoneType; import java.util.Arrays; import java.util.Objects; @@ -25,7 +23,7 @@ public class GameEvent extends Event { if (o == null || getClass() != o.getClass()) return false; if (!super.equals(o)) return false; GameEvent gameEvent = (GameEvent) o; - return Objects.equals(roundCount, gameEvent.roundCount) && Objects.equals(turnCount, gameEvent.turnCount) && Objects.equals(playerWon, gameEvent.playerWon) && Objects.equals(timeLeft, gameEvent.timeLeft) && Arrays.equals(characterOrder, gameEvent.characterOrder) && Objects.equals(nextCharacter, gameEvent.nextCharacter) && Objects.equals(message, gameEvent.message); + return Objects.equals(roundCount, gameEvent.roundCount) && Objects.equals(turnCount, gameEvent.turnCount) && Objects.equals(playerWon, gameEvent.playerWon) && Objects.equals(timeLeft, gameEvent.timeLeft) && Arrays.equals(characterOrder, gameEvent.characterOrder) && Objects.equals(nextCharacter, gameEvent.nextCharacter) && Objects.equals(message, gameEvent.message); } @Override diff --git a/src/main/java/uulm/teamname/marvelous/gamelibrary/gamelogic/EntityManager.java b/src/main/java/uulm/teamname/marvelous/gamelibrary/gamelogic/EntityManager.java index da1a774..47e903d 100644 --- a/src/main/java/uulm/teamname/marvelous/gamelibrary/gamelogic/EntityManager.java +++ b/src/main/java/uulm/teamname/marvelous/gamelibrary/gamelogic/EntityManager.java @@ -3,7 +3,6 @@ package uulm.teamname.marvelous.gamelibrary.gamelogic; 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.EntityType; import java.util.ArrayList; import java.util.Arrays; diff --git a/src/main/java/uulm/teamname/marvelous/gamelibrary/gamelogic/GameStateView.java b/src/main/java/uulm/teamname/marvelous/gamelibrary/gamelogic/GameStateView.java index 124ca5a..f152e1e 100644 --- a/src/main/java/uulm/teamname/marvelous/gamelibrary/gamelogic/GameStateView.java +++ b/src/main/java/uulm/teamname/marvelous/gamelibrary/gamelogic/GameStateView.java @@ -5,7 +5,6 @@ import uulm.teamname.marvelous.gamelibrary.entities.Entity; import uulm.teamname.marvelous.gamelibrary.entities.EntityID; import uulm.teamname.marvelous.gamelibrary.entities.StoneType; -import java.util.ArrayList; import java.util.Iterator; /** Represents a game state view containing getters for all the properties of a {@link GameState}. */ 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 31d0783..0315d78 100644 --- a/src/test/java/uulm/teamname/marvelous/gamelibrary/events/EventBuilderTest.java +++ b/src/test/java/uulm/teamname/marvelous/gamelibrary/events/EventBuilderTest.java @@ -1,10 +1,10 @@ package uulm.teamname.marvelous.gamelibrary.events; import org.junit.jupiter.api.BeforeEach; -import org.junit.jupiter.api.DisplayName; 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.*; @@ -13,9 +13,6 @@ import uulm.teamname.marvelous.gamelibrary.entities.Character; import java.util.ArrayList; import java.util.HashMap; -import static org.mockito.Mockito.*; -import static org.junit.jupiter.api.Assertions.*; - class EventBuilderTest { EntityID[] turns; EntityID turn; @@ -116,13 +113,20 @@ class EventBuilderTest { .withCustomContent(new HashMap<>()); } + @Test + void builderToStringTest() { + assertEquals("EventBuilder(non-null) {\ntype = TurnEvent\nroundCount = 5\n}", new EventBuilder(EventType.TurnEvent) + .withRoundCount(5) + .notNullToString()); + } + @Test void buildGameEventUncheckedActualEvents() { // System.out.println("Checks for mistakes in GameEvent creation"); var roundSetupEvent = new EventBuilder(EventType.RoundSetupEvent) .withRoundCount(4) .withCharacterOrder(turns) - .buildGameEvent(); + .buildGameEvent(true); var roundSetupEventBaseline = new GameEvent(); roundSetupEventBaseline.type = EventType.RoundSetupEvent; @@ -136,7 +140,7 @@ class EventBuilderTest { var turnEvent = new EventBuilder(EventType.TurnEvent) .withNextCharacter(turn) .withRoundCount(5) - .buildGameEventUnchecked(); + .buildGameEvent(false); var turnEventBaseline = new GameEvent(); turnEventBaseline.type = EventType.TurnEvent; @@ -159,7 +163,7 @@ class EventBuilderTest { .withPlayerWon(5912) .withMessage("This message is very much not useful at all") .withTimeLeft(-144) - .buildGameEventUnchecked(); + .buildGameEvent(false); var baseline = new GameEvent(); baseline.type = EventType.DisconnectEvent; @@ -184,7 +188,7 @@ class EventBuilderTest { .withTurnOrder(turns) .withActiveCharacter(turn) .withWinCondition(true) - .buildGameStateEventUnchecked(); + .buildGameStateEvent(false); var baseline = new GameStateEvent(); baseline.type = EventType.ConsumedAPEvent; @@ -217,28 +221,28 @@ class EventBuilderTest { .withAmount(15) // also properties of different EventTypes, they just get ignored .withEntities(entities) // properties belonging to the same eventType get incorporated into .withWinCondition(false) // the final event, so they have to be ignored - .buildGameStateEvent()); // by the programmer later on + .buildGameStateEvent(true)); // by the programmer later on } @Test void buildGameStateEvent() { assertThatNoException() .isThrownBy(() -> new EventBuilder(EventType.Ack) // needs no properties - .buildGameStateEvent()); + .buildGameStateEvent(true)); assertThatNoException() - .isThrownBy(() -> new EventBuilder(EventType.Nack).buildGameStateEvent()); + .isThrownBy(() -> new EventBuilder(EventType.Nack).buildGameStateEvent(true)); assertThatNoException() - .isThrownBy(() -> new EventBuilder(EventType.Req).buildGameStateEvent()); + .isThrownBy(() -> new EventBuilder(EventType.Req).buildGameStateEvent(true)); assertThatExceptionOfType(IllegalStateException.class) .isThrownBy(() -> new EventBuilder(EventType.GameStateEvent) // if properties missing throw exception .withTurnOrder(turns) .withActiveCharacter(turn) - .buildGameStateEvent()); + .buildGameStateEvent(true)); assertThatNoException() .isThrownBy(() -> new EventBuilder(EventType.GameStateEvent) // no exception if all properties present @@ -246,7 +250,7 @@ class EventBuilderTest { .withTurnOrder(turns) .withActiveCharacter(turn) .withWinCondition(false) - .buildGameStateEvent()); + .buildGameStateEvent(true)); } @Test @@ -254,4 +258,4 @@ class EventBuilderTest { // TODO: check CustomEvent validation for correctness } -} \ No newline at end of file +}