Skip to content

Commit

Permalink
Add a test for the fix.
Browse files Browse the repository at this point in the history
  • Loading branch information
asvitkine committed Jul 14, 2023
1 parent ad5e6ce commit da5435a
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2000,4 +2000,42 @@ void attackingPlanesCanNotWithdrawWW2v2AndNotAmphibious() {

assertThat(steps, is(basicFightStepStrings()));
}

@Test
@DisplayName("Verify that extra steps won't be created due to canNotTarget and non-participants")
void nonParticipantsDontCreateExtraStepsWithCannotTarget() {
// Two attacking units of different types.
final Unit unit1 = givenAnyUnit();
lenient().when(unit1.getOwner()).thenReturn(attacker);
final Unit unit2 = givenAnyUnit();
lenient().when(unit2.getOwner()).thenReturn(attacker);
final UnitType unit2Type = unit2.getType();

// One defending unit that can only target one of the attackers.
final Unit unit3 = givenAnyUnit();
lenient().when(unit3.getOwner()).thenReturn(defender);
final UnitAttachment unit3Attachment = unit3.getUnitAttachment();
when(unit3Attachment.getCanNotTarget()).thenReturn(Set.of(unit2Type));
// And an infra unit on the defense that should not participate in combat.
final Unit unit4 = givenUnitIsInfrastructure();
lenient().when(unit4.getOwner()).thenReturn(defender);

final var unitTypeList =
List.of(unit1.getType(), unit2.getType(), unit3.getType(), unit4.getType());

final List<String> steps =
givenBattleSteps(
givenBattleStateBuilder()
.gameData(
givenGameDataWithLenientProperties().withUnitTypeList(unitTypeList).build())
.attacker(attacker)
.defender(defender)
.attackingUnits(List.of(unit1, unit2))
.defendingUnits(List.of(unit3, unit4))
.battleSite(battleSite)
.amphibious(false)
.build());

assertThat(steps, is(basicFightStepStrings()));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,11 @@
import games.strategy.engine.data.ResourceList;
import games.strategy.engine.data.TechnologyFrontier;
import games.strategy.engine.data.Territory;
import games.strategy.engine.data.UnitType;
import games.strategy.engine.data.UnitTypeList;
import games.strategy.engine.data.properties.GameProperties;
import games.strategy.triplea.delegate.TechTracker;
import java.util.List;
import java.util.Set;

public class MockGameData {
Expand Down Expand Up @@ -196,4 +198,14 @@ public MockGameData withLowLuck(final boolean value) {
when(gameProperties.get(LOW_LUCK, false)).thenReturn(value);
return this;
}

public MockGameData withUnitTypeList(final List<UnitType> types) {
UnitTypeList unitTypeList = new UnitTypeList(gameData);
for (var unitType : types) {
lenient().when(unitType.getData()).thenReturn(gameData);
unitTypeList.addUnitType(unitType);
}
when(gameData.getUnitTypeList()).thenReturn(unitTypeList);
return this;
}
}

0 comments on commit da5435a

Please sign in to comment.