refactor: move event checks from builder to their respective classes
This commit is contained in:
@ -37,7 +37,7 @@ class EventBuilderTest {
|
||||
new EntityID(EntityType.P2, 0),
|
||||
};
|
||||
|
||||
turn = new EntityID(EntityType.P1, 0);
|
||||
turn = turns[0];
|
||||
|
||||
entities = new Entity[]{
|
||||
new Character(
|
||||
@ -79,7 +79,6 @@ class EventBuilderTest {
|
||||
25);
|
||||
|
||||
filled = new EventBuilder(EventType.CustomEvent)
|
||||
// .withType(EventType.CustomEvent)
|
||||
.withTargetEntity(new EntityID(EntityType.P1, 1))
|
||||
.withTargetField(new IntVector2(11, 13))
|
||||
.withAmount(15)
|
||||
@ -126,7 +125,11 @@ class EventBuilderTest {
|
||||
var roundSetupEvent = new EventBuilder(EventType.RoundSetupEvent)
|
||||
.withRoundCount(4)
|
||||
.withCharacterOrder(turns)
|
||||
.buildGameEvent(true);
|
||||
.buildGameEvent();
|
||||
|
||||
assertThat(roundSetupEvent.check())
|
||||
.isTrue()
|
||||
.withFailMessage("RoundSetupEvent failed check");
|
||||
|
||||
var roundSetupEventBaseline = new GameEvent();
|
||||
roundSetupEventBaseline.type = EventType.RoundSetupEvent;
|
||||
@ -139,13 +142,17 @@ class EventBuilderTest {
|
||||
|
||||
var turnEvent = new EventBuilder(EventType.TurnEvent)
|
||||
.withNextCharacter(turn)
|
||||
.withRoundCount(5)
|
||||
.buildGameEvent(false);
|
||||
.withTurnCount(5)
|
||||
.buildGameEvent();
|
||||
|
||||
assertThat(turnEvent.check())
|
||||
.isTrue()
|
||||
.withFailMessage("TurnEvent failed check");
|
||||
|
||||
var turnEventBaseline = new GameEvent();
|
||||
turnEventBaseline.type = EventType.TurnEvent;
|
||||
turnEventBaseline.nextCharacter = turn;
|
||||
turnEventBaseline.roundCount = 5;
|
||||
turnEventBaseline.turnCount = 5;
|
||||
|
||||
assertThat(turnEvent)
|
||||
.isEqualTo(turnEventBaseline)
|
||||
@ -163,7 +170,11 @@ class EventBuilderTest {
|
||||
.withPlayerWon(5912)
|
||||
.withMessage("This message is very much not useful at all")
|
||||
.withTimeLeft(-144)
|
||||
.buildGameEvent(false);
|
||||
.buildGameEvent();
|
||||
|
||||
assertThat(gameEvent.check())
|
||||
.isTrue()
|
||||
.withFailMessage("GameEvent failed check");
|
||||
|
||||
var baseline = new GameEvent();
|
||||
baseline.type = EventType.DisconnectEvent;
|
||||
@ -188,7 +199,11 @@ class EventBuilderTest {
|
||||
.withTurnOrder(turns)
|
||||
.withActiveCharacter(turn)
|
||||
.withWinCondition(true)
|
||||
.buildGameStateEvent(false);
|
||||
.buildGameStateEvent();
|
||||
|
||||
assertThat(gameStateEvent.check())
|
||||
.isTrue()
|
||||
.withFailMessage("GameStateEvent failed check");
|
||||
|
||||
var baseline = new GameStateEvent();
|
||||
baseline.type = EventType.ConsumedAPEvent;
|
||||
@ -216,46 +231,42 @@ class EventBuilderTest {
|
||||
|
||||
@Test
|
||||
void buildGameStateEventWithTooManyProperties() {
|
||||
assertThatNoException()
|
||||
.isThrownBy(() -> new EventBuilder(EventType.Ack) // too many properties is fine
|
||||
.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(true)); // by the programmer later on
|
||||
assertThat(new EventBuilder(EventType.Ack) // too many properties is fine
|
||||
.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
|
||||
.check()).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
void buildGameStateEvent() {
|
||||
assertThatNoException()
|
||||
.isThrownBy(() -> new EventBuilder(EventType.Ack) // needs no properties
|
||||
.buildGameStateEvent(true));
|
||||
assertThat(new EventBuilder(EventType.Ack) // needs no properties
|
||||
.buildGameStateEvent()
|
||||
.check()).isTrue();
|
||||
|
||||
|
||||
assertThat(new EventBuilder(EventType.Nack).buildGameStateEvent().check()).isTrue();
|
||||
|
||||
assertThatNoException()
|
||||
.isThrownBy(() -> new EventBuilder(EventType.Nack).buildGameStateEvent(true));
|
||||
assertThat(new EventBuilder(EventType.Req).buildGameStateEvent().check()).isTrue();
|
||||
|
||||
assertThatNoException()
|
||||
.isThrownBy(() -> new EventBuilder(EventType.Req).buildGameStateEvent(true));
|
||||
assertThat(new EventBuilder(EventType.GameStateEvent) // if properties missing throw exception
|
||||
.withTurnOrder(turns)
|
||||
.withActiveCharacter(turn)
|
||||
.buildGameStateEvent()
|
||||
.check()).isFalse();
|
||||
|
||||
assertThatExceptionOfType(IllegalStateException.class)
|
||||
.isThrownBy(() -> new EventBuilder(EventType.GameStateEvent) // if properties missing throw exception
|
||||
.withTurnOrder(turns)
|
||||
.withActiveCharacter(turn)
|
||||
.buildGameStateEvent(true));
|
||||
|
||||
assertThatNoException()
|
||||
.isThrownBy(() -> new EventBuilder(EventType.GameStateEvent) // no exception if all properties present
|
||||
.withEntities(entities)
|
||||
.withTurnOrder(turns)
|
||||
.withActiveCharacter(turn)
|
||||
.withWinCondition(false)
|
||||
.buildGameStateEvent(true));
|
||||
assertThat(new EventBuilder(EventType.GameStateEvent) // no exception if all properties present
|
||||
.withEntities(entities)
|
||||
.withTurnOrder(turns)
|
||||
.withActiveCharacter(turn)
|
||||
.withWinCondition(false)
|
||||
.buildGameStateEvent()
|
||||
.check()).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
void buildCustomEvent() {
|
||||
// TODO: check CustomEvent validation for correctness
|
||||
}
|
||||
|
||||
}
|
||||
|
Reference in New Issue
Block a user