Skip to content

Commit

Permalink
Fix bombard casualties firing back. (2.6 bug) (#11791)
Browse files Browse the repository at this point in the history
A parameter was missing!
Adds a test.
Fixes: #8948
  • Loading branch information
asvitkine authored Jul 19, 2023
1 parent 406114a commit 8f6a4d2
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public BattleStep.Order getOrder() {
@Override
public void execute(final ExecutionStack stack, final IDelegateBridge bridge) {
if (canBombardmentOccur() && clearCasualties()) {
battleActions.clearWaitingToDieAndDamagedChangesInto(bridge);
battleActions.clearWaitingToDieAndDamagedChangesInto(bridge, BattleState.Side.DEFENSE);
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
package games.strategy.triplea.delegate.battle.steps.change;

import static games.strategy.triplea.delegate.battle.BattleState.Side.DEFENSE;
import static games.strategy.triplea.delegate.battle.FakeBattleState.givenBattleStateBuilder;
import static games.strategy.triplea.delegate.battle.steps.BattleStepsTest.givenAnyUnit;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.verifyNoMoreInteractions;

import games.strategy.engine.data.Unit;
import games.strategy.engine.delegate.IDelegateBridge;
import games.strategy.triplea.delegate.ExecutionStack;
import games.strategy.triplea.delegate.battle.BattleActions;
import games.strategy.triplea.delegate.battle.BattleState;
import games.strategy.triplea.delegate.battle.steps.MockGameData;
import java.util.List;
import org.junit.jupiter.api.extension.ExtendWith;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.ValueSource;
import org.mockito.Mock;
import org.mockito.junit.jupiter.MockitoExtension;

@ExtendWith(MockitoExtension.class)
public class ClearBombardmentCasualtiesTest {
@Mock BattleActions battleActions;
@Mock ExecutionStack executionStack;
@Mock IDelegateBridge delegateBridge;

@ParameterizedTest
@ValueSource(booleans = {true, false})
void bombardCasualtiesRemoved(boolean navalBombardCasualtiesReturnFire) {
final List<Unit> bombardingUnits = List.of(givenAnyUnit());
final List<Unit> attackers = List.of(givenAnyUnit());
final List<Unit> defenders = List.of(givenAnyUnit());
final MockGameData gameData =
MockGameData.givenGameData()
.withNavalBombardCasualtiesReturnFire(navalBombardCasualtiesReturnFire);
final BattleState battleState =
givenBattleStateBuilder()
.battleRound(1)
.bombardingUnits(bombardingUnits)
.attackingUnits(attackers)
.defendingUnits(defenders)
.gameData(gameData.build())
.build();

final var clearBombardmentCasualties =
new ClearBombardmentCasualties(battleState, battleActions);
clearBombardmentCasualties.execute(executionStack, delegateBridge);
if (!navalBombardCasualtiesReturnFire) {
verify(battleActions).clearWaitingToDieAndDamagedChangesInto(delegateBridge, DEFENSE);
}
verifyNoMoreInteractions(battleActions);
}
}

0 comments on commit 8f6a4d2

Please sign in to comment.