refactor: clean up code and improve event builder
This commit is contained in:
@ -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
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user