From 61bfdf8108bbc2de2853cfcb0189bf2af3206ad5 Mon Sep 17 00:00:00 2001 From: Oleg Agafonov Date: Fri, 14 Aug 2020 16:22:34 +0400 Subject: [PATCH] Tests: added verify check for wrong optional settings on DoIfCostPaid usage; --- .../src/test/java/mage/verify/VerifyCardDataTest.java | 6 +++++- .../main/java/mage/abilities/TriggeredAbilityImpl.java | 8 ++++++++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/Mage.Verify/src/test/java/mage/verify/VerifyCardDataTest.java b/Mage.Verify/src/test/java/mage/verify/VerifyCardDataTest.java index 5b0dda367b..c2680f531b 100644 --- a/Mage.Verify/src/test/java/mage/verify/VerifyCardDataTest.java +++ b/Mage.Verify/src/test/java/mage/verify/VerifyCardDataTest.java @@ -1499,7 +1499,8 @@ public class VerifyCardDataTest { } @Test - public void test_CardsCreatingAndConstructorErrors() { + public void test_checkCardConstructors() { + Collection errorsList = new ArrayList<>(); int errorsCount = 0; Collection 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"); } } diff --git a/Mage/src/main/java/mage/abilities/TriggeredAbilityImpl.java b/Mage/src/main/java/mage/abilities/TriggeredAbilityImpl.java index 80a26c2f80..fb9f834c5a 100644 --- a/Mage/src/main/java/mage/abilities/TriggeredAbilityImpl.java +++ b/Mage/src/main/java/mage/abilities/TriggeredAbilityImpl.java @@ -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) {