Tests: added verify check for wrong optional settings on DoIfCostPaid usage;

This commit is contained in:
Oleg Agafonov 2020-08-14 16:22:34 +04:00
parent 9dc3d514bd
commit 61bfdf8108
2 changed files with 13 additions and 1 deletions

View file

@ -1499,7 +1499,8 @@ public class VerifyCardDataTest {
}
@Test
public void test_CardsCreatingAndConstructorErrors() {
public void test_checkCardConstructors() {
Collection<String> errorsList = new ArrayList<>();
int errorsCount = 0;
Collection<ExpansionSet> sets = Sets.getInstance().values();
for (ExpansionSet set : sets) {
@ -1509,15 +1510,18 @@ public class VerifyCardDataTest {
Card card = CardImpl.createCard(setInfo.getCardClass(), new CardSetInfo(setInfo.getName(), set.getCode(),
setInfo.getCardNumber(), setInfo.getRarity(), setInfo.getGraphicInfo()));
if (card == null) {
errorsList.add("Broken constructor: " + setInfo.getCardClass());
errorsCount++;
}
} catch (Throwable e) {
// CardImpl.createCard don't throw exceptions (only error logs), so that logs are useless here
logger.error("Can't create card " + setInfo.getName() + ": " + e.getMessage(), e);
}
}
}
if (errorsCount > 0) {
printMessages(errorsList);
Assert.fail("Founded " + errorsCount + " broken cards, look at logs for stack error");
}
}

View file

@ -2,6 +2,7 @@ package mage.abilities;
import mage.MageObject;
import mage.abilities.effects.Effect;
import mage.abilities.effects.common.DoIfCostPaid;
import mage.constants.AbilityType;
import mage.constants.Zone;
import mage.game.Game;
@ -32,6 +33,13 @@ public abstract class TriggeredAbilityImpl extends AbilityImpl implements Trigge
addEffect(effect);
}
this.optional = optional;
// verify check: DoIfCostPaid effect already asks about action (optional), so no needs to ask it again in triggered ability
if (effect instanceof DoIfCostPaid) {
if (this.optional && ((DoIfCostPaid) effect).isOptional()) {
throw new IllegalArgumentException("DoIfCostPaid effect must have only one optional settings, but it have two (trigger + DoIfCostPaid): " + this.getClass().getSimpleName());
}
}
}
public TriggeredAbilityImpl(final TriggeredAbilityImpl ability) {