Extra tests to catch card creation errors;

This commit is contained in:
Oleg Agafonov 2019-05-06 17:03:56 +04:00
parent e77b21f4e9
commit b9b8415c99
3 changed files with 43 additions and 6 deletions

View file

@ -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}");
// <i>Council's dilemma</i> &mdash; 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
// <i>Council's dilemma</i> &mdash; 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());
}

View file

@ -37,8 +37,16 @@ public class ExportJsonGameplayDataTest {
Collection<ExpansionSet> 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();

View file

@ -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<ExpansionSet> 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");
}
}
}