From b9b8415c997b57c4410c8b144388419a418d78de Mon Sep 17 00:00:00 2001 From: Oleg Agafonov Date: Mon, 6 May 2019 17:03:56 +0400 Subject: [PATCH] Extra tests to catch card creation errors; --- Mage.Sets/src/mage/cards/e/Expropriate.java | 10 ++++--- .../utils/ExportJsonGameplayDataTest.java | 12 +++++++-- .../java/mage/verify/VerifyCardDataTest.java | 27 +++++++++++++++++++ 3 files changed, 43 insertions(+), 6 deletions(-) diff --git a/Mage.Sets/src/mage/cards/e/Expropriate.java b/Mage.Sets/src/mage/cards/e/Expropriate.java index 81761c64af..318fa8342f 100644 --- a/Mage.Sets/src/mage/cards/e/Expropriate.java +++ b/Mage.Sets/src/mage/cards/e/Expropriate.java @@ -1,8 +1,5 @@ package mage.cards.e; -import java.util.ArrayList; -import java.util.List; -import java.util.UUID; import mage.abilities.Ability; import mage.abilities.effects.ContinuousEffect; import mage.abilities.effects.ContinuousEffectImpl; @@ -22,6 +19,10 @@ import mage.target.Target; import mage.target.TargetPermanent; import mage.target.targetpointer.FixedTarget; +import java.util.ArrayList; +import java.util.List; +import java.util.UUID; + /** * @author JRHerlehy */ @@ -30,7 +31,8 @@ public final class Expropriate extends CardImpl { public Expropriate(UUID ownerId, CardSetInfo setInfo) { super(ownerId, setInfo, new CardType[]{CardType.SORCERY}, "{7}{U}{U}"); - // Council's dilemma — Starting with you, each player votes for time or money. For each time vote, take an extra turn after this one. For each money vote, choose a permanent owned by the voter and gain control of it. Exile Expropriate + // Council's dilemma — Starting with you, each player votes for time or money. For each time vote, + // take an extra turn after this one. For each money vote, choose a permanent owned by the voter and gain control of it. Exile Expropriate this.getSpellAbility().addEffect(new ExpropriateDilemmaEffect()); this.getSpellAbility().addEffect(ExileSpellEffect.getInstance()); } diff --git a/Mage.Tests/src/test/java/org/mage/test/utils/ExportJsonGameplayDataTest.java b/Mage.Tests/src/test/java/org/mage/test/utils/ExportJsonGameplayDataTest.java index 67ef4b6431..624c07c13f 100644 --- a/Mage.Tests/src/test/java/org/mage/test/utils/ExportJsonGameplayDataTest.java +++ b/Mage.Tests/src/test/java/org/mage/test/utils/ExportJsonGameplayDataTest.java @@ -37,8 +37,16 @@ public class ExportJsonGameplayDataTest { Collection sets = Sets.getInstance().values(); for (ExpansionSet set : sets) { for (ExpansionSet.SetCardInfo setInfo : set.getSetCardInfo()) { - cards.add(CardImpl.createCard(setInfo.getCardClass(), new CardSetInfo(setInfo.getName(), set.getCode(), - setInfo.getCardNumber(), setInfo.getRarity(), setInfo.getGraphicInfo()))); + // catch cards creation errors and report (e.g. on wrong card code) + try { + Card card = CardImpl.createCard(setInfo.getCardClass(), new CardSetInfo(setInfo.getName(), set.getCode(), + setInfo.getCardNumber(), setInfo.getRarity(), setInfo.getGraphicInfo())); + if (card != null) { + cards.add(card); + } + } catch (Throwable e) { + logger.error("Can't create card " + setInfo.getName() + ": " + e.getMessage(), e); + } } JsonObject res = new JsonObject(); diff --git a/Mage.Verify/src/test/java/mage/verify/VerifyCardDataTest.java b/Mage.Verify/src/test/java/mage/verify/VerifyCardDataTest.java index 36ce86fb2d..4ea8fb15cb 100644 --- a/Mage.Verify/src/test/java/mage/verify/VerifyCardDataTest.java +++ b/Mage.Verify/src/test/java/mage/verify/VerifyCardDataTest.java @@ -15,6 +15,7 @@ import mage.game.draft.RateCard; import mage.game.permanent.token.Token; import mage.game.permanent.token.TokenImpl; import mage.watchers.Watcher; +import org.apache.log4j.Logger; import org.junit.Assert; import org.junit.Ignore; import org.junit.Test; @@ -41,6 +42,8 @@ import java.util.stream.Collectors; */ public class VerifyCardDataTest { + private static final Logger logger = Logger.getLogger(VerifyCardDataTest.class); + // right now this is very noisy, and not useful enough to make any assertions on private static final boolean CHECK_SOURCE_TOKENS = false; @@ -971,4 +974,28 @@ public class VerifyCardDataTest { } } } + + @Test + public void testCardsCreatingAndConstructorErrors() { + int errorsCount = 0; + Collection sets = Sets.getInstance().values(); + for (ExpansionSet set : sets) { + for (ExpansionSet.SetCardInfo setInfo : set.getSetCardInfo()) { + // catch cards creation errors and report (e.g. on wrong card code or construction checks fail) + try { + Card card = CardImpl.createCard(setInfo.getCardClass(), new CardSetInfo(setInfo.getName(), set.getCode(), + setInfo.getCardNumber(), setInfo.getRarity(), setInfo.getGraphicInfo())); + if (card == null) { + errorsCount++; + } + } catch (Throwable e) { + logger.error("Can't create card " + setInfo.getName() + ": " + e.getMessage(), e); + } + } + } + + if (errorsCount > 0) { + Assert.fail("Founded " + errorsCount + " broken cards, look at logs for stack error"); + } + } }