From c8154bf018b86de163b38c5fc9e02c9be3023e59 Mon Sep 17 00:00:00 2001 From: Evan Kranzler Date: Thu, 10 Jun 2021 18:40:56 -0400 Subject: [PATCH] [MH2] added test for Garth One-Eye --- Mage.Sets/src/mage/cards/g/GarthOneEye.java | 21 ++- .../cards/single/mh2/GarthOneEyeTest.java | 151 ++++++++++++++++++ 2 files changed, 165 insertions(+), 7 deletions(-) create mode 100644 Mage.Tests/src/test/java/org/mage/test/cards/single/mh2/GarthOneEyeTest.java diff --git a/Mage.Sets/src/mage/cards/g/GarthOneEye.java b/Mage.Sets/src/mage/cards/g/GarthOneEye.java index e1b0a90a7a..9fe9dd77c8 100644 --- a/Mage.Sets/src/mage/cards/g/GarthOneEye.java +++ b/Mage.Sets/src/mage/cards/g/GarthOneEye.java @@ -57,13 +57,19 @@ class GarthOneEyeEffect extends OneShotEffect { private static final List names = Arrays.asList( "Disenchant", "Braingeyser", "Terror", "Shivan Dragon", "Regrowth", "Black Lotus" ); - private static final Map cardMap - = CardRepository - .instance - .findCards(new CardCriteria().setCodes("LEA")) - .stream() - .filter(cardInfo -> names.contains(cardInfo.getName())) - .collect(Collectors.toMap(CardInfo::getName, CardInfo::getCard)); + private static final Map cardMap = new HashMap<>(); + + private static final void initMap() { + if (!cardMap.isEmpty()) { + return; + } + cardMap.putAll(CardRepository + .instance + .findCards(new CardCriteria().setCodes("LEA")) + .stream() + .filter(cardInfo -> names.contains(cardInfo.getName())) + .collect(Collectors.toMap(CardInfo::getName, CardInfo::getCard))); + } GarthOneEyeEffect() { super(Outcome.Benefit); @@ -83,6 +89,7 @@ class GarthOneEyeEffect extends OneShotEffect { @Override public boolean apply(Game game, Ability source) { + initMap(); Player player = game.getPlayer(source.getControllerId()); if (player == null) { return false; diff --git a/Mage.Tests/src/test/java/org/mage/test/cards/single/mh2/GarthOneEyeTest.java b/Mage.Tests/src/test/java/org/mage/test/cards/single/mh2/GarthOneEyeTest.java new file mode 100644 index 0000000000..e78adbea82 --- /dev/null +++ b/Mage.Tests/src/test/java/org/mage/test/cards/single/mh2/GarthOneEyeTest.java @@ -0,0 +1,151 @@ +package org.mage.test.cards.single.mh2; + +import mage.constants.PhaseStep; +import mage.constants.Zone; +import mage.game.permanent.Permanent; +import mage.game.permanent.PermanentToken; +import org.junit.Assert; +import org.junit.Test; +import org.mage.test.serverside.base.CardTestPlayerBase; + +/** + * @author TheElk801 + */ +public class GarthOneEyeTest extends CardTestPlayerBase { + + private static final String garth = "Garth One-Eye"; + private static final String disenchant = "Disenchant"; + private static final String braingeyser = "Braingeyser"; + private static final String terror = "Terror"; + private static final String dragon = "Shivan Dragon"; + private static final String regrowth = "Regrowth"; + private static final String lotus = "Black Lotus"; + private static final String courser = "Nyxborn Courser"; + + @Test + public void testDisenchant() { + addCard(Zone.BATTLEFIELD, playerA, "Plains", 2); + addCard(Zone.BATTLEFIELD, playerA, garth); + addCard(Zone.BATTLEFIELD, playerA, courser); + + setChoice(playerA, disenchant); + setChoice(playerA, "Yes"); + addTarget(playerA, courser); + activateAbility(1, PhaseStep.PRECOMBAT_MAIN, playerA, "{T}: Choose"); + + setStrictChooseMode(true); + setStopAt(1, PhaseStep.END_TURN); + execute(); + assertAllCommandsUsed(); + + assertTapped(garth, true); + assertTapped("Plains", true); + assertPermanentCount(playerA, courser, 0); + assertGraveyardCount(playerA, disenchant, 0); + assertGraveyardCount(playerA, courser, 1); + } + + @Test + public void testBraingeyser() { + addCard(Zone.BATTLEFIELD, playerA, "Island", 5); + addCard(Zone.BATTLEFIELD, playerA, garth); + + setChoice(playerA, braingeyser); + setChoice(playerA, "Yes"); + setChoice(playerA, "X=3"); + addTarget(playerA, playerA); + activateAbility(1, PhaseStep.PRECOMBAT_MAIN, playerA, "{T}: Choose"); + + setStrictChooseMode(true); + setStopAt(1, PhaseStep.END_TURN); + execute(); + assertAllCommandsUsed(); + + assertTapped(garth, true); + assertTapped("Island", true); + assertGraveyardCount(playerA, braingeyser, 0); + assertHandCount(playerA, 3); + } + + @Test + public void testTerror() { + addCard(Zone.BATTLEFIELD, playerA, "Swamp", 2); + addCard(Zone.BATTLEFIELD, playerA, garth); + addCard(Zone.BATTLEFIELD, playerA, courser); + + setChoice(playerA, terror); + setChoice(playerA, "Yes"); + addTarget(playerA, courser); + activateAbility(1, PhaseStep.PRECOMBAT_MAIN, playerA, "{T}: Choose"); + + setStrictChooseMode(true); + setStopAt(1, PhaseStep.END_TURN); + execute(); + assertAllCommandsUsed(); + + assertTapped(garth, true); + assertTapped("Swamp", true); + assertPermanentCount(playerA, courser, 0); + assertGraveyardCount(playerA, terror, 0); + assertGraveyardCount(playerA, courser, 1); + } + + @Test + public void testShivanDragon() { + addCard(Zone.BATTLEFIELD, playerA, "Mountain", 6); + addCard(Zone.BATTLEFIELD, playerA, garth); + + setChoice(playerA, dragon); + activateAbility(1, PhaseStep.PRECOMBAT_MAIN, playerA, "{T}: Choose"); + + setStopAt(1, PhaseStep.END_TURN); + execute(); + assertAllCommandsUsed(); + + assertTapped(garth, true); + assertTapped("Mountain", true); + Permanent permanent = getPermanent(dragon); + Assert.assertNotNull(dragon + " should be on the battlefield", permanent); + Assert.assertTrue(dragon + " should be a token", permanent instanceof PermanentToken); + } + + @Test + public void testRegrowth() { + addCard(Zone.BATTLEFIELD, playerA, "Forest", 2); + addCard(Zone.BATTLEFIELD, playerA, garth); + addCard(Zone.GRAVEYARD, playerA, courser); + + setChoice(playerA, regrowth); + setChoice(playerA, "Yes"); + addTarget(playerA, courser); + activateAbility(1, PhaseStep.PRECOMBAT_MAIN, playerA, "{T}: Choose"); + + setStrictChooseMode(true); + setStopAt(1, PhaseStep.END_TURN); + execute(); + assertAllCommandsUsed(); + + assertTapped(garth, true); + assertTapped("Forest", true); + assertHandCount(playerA, courser, 1); + assertGraveyardCount(playerA, regrowth, 0); + assertGraveyardCount(playerA, courser, 0); + } + + @Test + public void testBlackLotus() { + addCard(Zone.BATTLEFIELD, playerA, garth); + + setChoice(playerA, lotus); + activateAbility(1, PhaseStep.PRECOMBAT_MAIN, playerA, "{T}: Choose"); + + setStopAt(1, PhaseStep.END_TURN); + execute(); + assertAllCommandsUsed(); + + assertTapped(garth, true); + Permanent permanent = getPermanent(lotus); + Assert.assertNotNull(lotus + " should be on the battlefield", permanent); + Assert.assertTrue(lotus + " should be a token", permanent instanceof PermanentToken); + } +}