From 90cb1a20957947118cf26977fd04e370656903c8 Mon Sep 17 00:00:00 2001 From: asvitkine Date: Wed, 5 Jul 2023 19:30:54 -0400 Subject: [PATCH] Fix existing tests. --- .../delegate/battle/FakeBattleState.java | 19 ++++++++++++------- .../change/CheckGeneralBattleEndTest.java | 17 +++++++++++++++-- 2 files changed, 27 insertions(+), 9 deletions(-) diff --git a/game-app/game-core/src/test/java/games/strategy/triplea/delegate/battle/FakeBattleState.java b/game-app/game-core/src/test/java/games/strategy/triplea/delegate/battle/FakeBattleState.java index ccfb7d61274..9d982e1d229 100644 --- a/game-app/game-core/src/test/java/games/strategy/triplea/delegate/battle/FakeBattleState.java +++ b/game-app/game-core/src/test/java/games/strategy/triplea/delegate/battle/FakeBattleState.java @@ -178,12 +178,8 @@ public List getStepStrings() { return List.of(); } - public static FakeBattleState.FakeBattleStateBuilder givenBattleStateBuilder() { - final GameData gameData = givenGameData().build(); - final GamePlayer attacker = mock(GamePlayer.class); - lenient().when(attacker.getData()).thenReturn(gameData); - final GamePlayer defender = mock(GamePlayer.class); - lenient().when(defender.getData()).thenReturn(gameData); + public static FakeBattleState.FakeBattleStateBuilder givenBattleStateBuilder( + final GamePlayer attacker, final GamePlayer defender) { return FakeBattleState.builder() .battleRound(2) .maxBattleRounds(-1) @@ -199,9 +195,18 @@ public static FakeBattleState.FakeBattleStateBuilder givenBattleStateBuilder() { .dependentUnits(List.of()) .killed(List.of()) .retreatUnits(new ArrayList<>()) - .gameData(gameData) + .gameData(attacker.getData()) .amphibious(false) .over(false) .attackerRetreatTerritories(List.of()); } + + public static FakeBattleState.FakeBattleStateBuilder givenBattleStateBuilder() { + final GameData gameData = givenGameData().build(); + final GamePlayer attacker = mock(GamePlayer.class); + lenient().when(attacker.getData()).thenReturn(gameData); + final GamePlayer defender = mock(GamePlayer.class); + lenient().when(defender.getData()).thenReturn(gameData); + return givenBattleStateBuilder(attacker, defender); + } } diff --git a/game-app/game-core/src/test/java/games/strategy/triplea/delegate/battle/steps/change/CheckGeneralBattleEndTest.java b/game-app/game-core/src/test/java/games/strategy/triplea/delegate/battle/steps/change/CheckGeneralBattleEndTest.java index 42ae0c8a7f1..5babe4812ac 100644 --- a/game-app/game-core/src/test/java/games/strategy/triplea/delegate/battle/steps/change/CheckGeneralBattleEndTest.java +++ b/game-app/game-core/src/test/java/games/strategy/triplea/delegate/battle/steps/change/CheckGeneralBattleEndTest.java @@ -7,6 +7,7 @@ import static games.strategy.triplea.delegate.battle.steps.BattleStepsTest.givenUnitSeaTransport; import static games.strategy.triplea.delegate.battle.steps.MockGameData.givenGameData; import static org.mockito.ArgumentMatchers.any; +import static org.mockito.Mockito.lenient; import static org.mockito.Mockito.never; import static org.mockito.Mockito.times; import static org.mockito.Mockito.verify; @@ -24,6 +25,7 @@ import games.strategy.triplea.delegate.battle.IBattle; import java.util.List; import java.util.Set; +import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; import org.mockito.Mock; @@ -38,6 +40,14 @@ class CheckGeneralBattleEndTest { @Mock GamePlayer attacker; @Mock GamePlayer defender; + @BeforeEach + void setUp() { + final GameData gameData = new GameData(); + + lenient().when(attacker.getData()).thenReturn(gameData); + lenient().when(defender.getData()).thenReturn(gameData); + } + private CheckGeneralBattleEnd givenCheckGeneralBattleEnd(final BattleState battleState) { return new CheckGeneralBattleEnd(battleState, battleActions); } @@ -133,9 +143,10 @@ void nobodyWinsIfBothHaveUnitsButMaxRound() { void battleIsNotDoneIfOffenseHasUnitWithPower() { final Unit attackerUnit = givenUnitWithAttackPower(attacker); final Unit defenderUnit = givenAnyUnit(); + lenient().when(defenderUnit.getOwner()).thenReturn(defender); final BattleState battleState = - givenBattleStateBuilder() + givenBattleStateBuilder(attacker, defender) .gameData(givenGameData().withDiceSides(6).build()) .attackingUnits(List.of(attackerUnit)) .defendingUnits(List.of(defenderUnit)) @@ -252,8 +263,10 @@ void stalemateRetreatPossibleIfOnlyNonCombatTransports() { givenBattleStateBuilder() .gameData( givenGameData() - .withLhtrHeavyBombers(false) + .withAlliedAirIndependent(false) + .withDefendingSuicideAndMunitionUnitsDoNotFire(false) .withTransportCasualtiesRestricted(true) + .withLhtrHeavyBombers(false) .build()) .attackingUnits(List.of(attackerUnit)) .defendingUnits(List.of(defenderUnit))