From 7e1e8b72d0317d8bd095117e850a5f997b10bfc2 Mon Sep 17 00:00:00 2001 From: "marcins78@gmail.com" Date: Tue, 17 Jan 2012 17:36:59 +0000 Subject: [PATCH] Wound AT tests. --- .../CardActionSelectionDecision.java | 14 +- .../lotro/at/effects/WoundEffectAtTest.java | 150 ++++++++++++++++++ 2 files changed, 162 insertions(+), 2 deletions(-) create mode 100644 gemp-lotr/gemp-lotr-server/src/test/java/com/gempukku/lotro/at/effects/WoundEffectAtTest.java diff --git a/gemp-lotr/gemp-lotr-logic/src/main/java/com/gempukku/lotro/logic/decisions/CardActionSelectionDecision.java b/gemp-lotr/gemp-lotr-logic/src/main/java/com/gempukku/lotro/logic/decisions/CardActionSelectionDecision.java index fee0797d2..bd5de8078 100644 --- a/gemp-lotr/gemp-lotr-logic/src/main/java/com/gempukku/lotro/logic/decisions/CardActionSelectionDecision.java +++ b/gemp-lotr/gemp-lotr-logic/src/main/java/com/gempukku/lotro/logic/decisions/CardActionSelectionDecision.java @@ -3,16 +3,17 @@ package com.gempukku.lotro.logic.decisions; import com.gempukku.lotro.game.state.LotroGame; import com.gempukku.lotro.logic.timing.Action; +import java.util.LinkedList; import java.util.List; public abstract class CardActionSelectionDecision extends AbstractAwaitingDecision { private LotroGame _game; - private List _actions; + private List _actions; public CardActionSelectionDecision(LotroGame game, int decisionId, String text, List actions) { super(decisionId, text, AwaitingDecisionType.CARD_ACTION_CHOICE); _game = game; - _actions = actions; + _actions = new LinkedList(actions); setParam("actionId", getActionIds(actions)); setParam("cardId", getCardIds(actions)); @@ -20,6 +21,15 @@ public abstract class CardActionSelectionDecision extends AbstractAwaitingDecisi setParam("actionText", getActionTexts(actions)); } + /** + * For testing, being able to inject an extra action at any point + * + * @param action + */ + public void addAction(Action action) { + _actions.add(action); + } + private String[] getActionIds(List actions) { String[] result = new String[actions.size()]; for (int i = 0; i < result.length; i++) diff --git a/gemp-lotr/gemp-lotr-server/src/test/java/com/gempukku/lotro/at/effects/WoundEffectAtTest.java b/gemp-lotr/gemp-lotr-server/src/test/java/com/gempukku/lotro/at/effects/WoundEffectAtTest.java new file mode 100644 index 000000000..edf2ba0cc --- /dev/null +++ b/gemp-lotr/gemp-lotr-server/src/test/java/com/gempukku/lotro/at/effects/WoundEffectAtTest.java @@ -0,0 +1,150 @@ +package com.gempukku.lotro.at.effects; + +import com.gempukku.lotro.at.AbstractAtTest; +import com.gempukku.lotro.cards.TriggerConditions; +import com.gempukku.lotro.cards.effects.PreventCardEffect; +import com.gempukku.lotro.common.Zone; +import com.gempukku.lotro.game.AbstractActionProxy; +import com.gempukku.lotro.game.PhysicalCardImpl; +import com.gempukku.lotro.game.state.LotroGame; +import com.gempukku.lotro.logic.actions.RequiredTriggerAction; +import com.gempukku.lotro.logic.actions.SystemQueueAction; +import com.gempukku.lotro.logic.decisions.CardActionSelectionDecision; +import com.gempukku.lotro.logic.decisions.DecisionResultInvalidException; +import com.gempukku.lotro.logic.effects.WoundCharactersEffect; +import com.gempukku.lotro.logic.timing.Effect; +import com.gempukku.lotro.logic.timing.EffectResult; +import org.junit.Test; + +import java.util.Collections; +import java.util.List; +import java.util.concurrent.atomic.AtomicInteger; + +import static org.junit.Assert.*; + +public class WoundEffectAtTest extends AbstractAtTest { + @Test + public void woundSuccessful() throws DecisionResultInvalidException { + initializeSimplestGame(); + + skipMulligans(); + + final PhysicalCardImpl merry = new PhysicalCardImpl(101, "1_303", P1, _library.getLotroCardBlueprint("1_303")); + + final AtomicInteger triggerCount = new AtomicInteger(0); + + _game.getActionsEnvironment().addUntilEndOfTurnActionProxy( + new AbstractActionProxy() { + @Override + public List getRequiredAfterTriggers(LotroGame game, EffectResult effectResult) { + if (TriggerConditions.forEachWounded(game, effectResult, merry)) { + triggerCount.incrementAndGet(); + } + return null; + } + }); + + _game.getGameState().addCardToZone(_game, merry, Zone.FREE_CHARACTERS); + + WoundCharactersEffect woundEffect = new WoundCharactersEffect(merry, merry); + + carryOutEffectInPhaseActionByPlayer(P1, woundEffect); + + assertEquals(1, _game.getGameState().getWounds(merry)); + assertTrue(woundEffect.wasSuccessful()); + assertTrue(woundEffect.wasCarriedOut()); + + assertEquals(1, triggerCount.get()); + } + + @Test + public void woundUnsuccessful() throws DecisionResultInvalidException { + initializeSimplestGame(); + + skipMulligans(); + + final PhysicalCardImpl merry = new PhysicalCardImpl(101, "1_303", P1, _library.getLotroCardBlueprint("1_303")); + + final AtomicInteger triggerCount = new AtomicInteger(0); + + _game.getActionsEnvironment().addUntilEndOfTurnActionProxy( + new AbstractActionProxy() { + @Override + public List getRequiredAfterTriggers(LotroGame game, EffectResult effectResult) { + if (TriggerConditions.forEachWounded(game, effectResult, merry)) { + triggerCount.incrementAndGet(); + } + return null; + } + }); + + _game.getGameState().addCardToZone(_game, merry, Zone.DISCARD); + + WoundCharactersEffect woundEffect = new WoundCharactersEffect(merry, merry); + + carryOutEffectInPhaseActionByPlayer(P1, woundEffect); + + assertEquals(0, _game.getGameState().getWounds(merry)); + assertFalse(woundEffect.wasSuccessful()); + assertFalse(woundEffect.wasCarriedOut()); + + assertEquals(0, triggerCount.get()); + } + + @Test + public void woundPrevention() throws DecisionResultInvalidException { + initializeSimplestGame(); + + skipMulligans(); + + final PhysicalCardImpl merry = new PhysicalCardImpl(101, "1_303", P1, _library.getLotroCardBlueprint("1_303")); + final PhysicalCardImpl pippin = new PhysicalCardImpl(102, "1_306", P1, _library.getLotroCardBlueprint("1_306")); + + final AtomicInteger triggerCount = new AtomicInteger(0); + + _game.getActionsEnvironment().addUntilEndOfTurnActionProxy( + new AbstractActionProxy() { + @Override + public List getRequiredBeforeTriggers(LotroGame game, Effect effect) { + if (TriggerConditions.isGettingWounded(effect, game, merry)) { + RequiredTriggerAction action = new RequiredTriggerAction(merry); + action.appendEffect( + new PreventCardEffect((WoundCharactersEffect) effect, merry)); + return Collections.singletonList(action); + } + return null; + } + + @Override + public List getRequiredAfterTriggers(LotroGame game, EffectResult effectResult) { + if (TriggerConditions.forEachWounded(game, effectResult, merry)) { + triggerCount.incrementAndGet(); + } + return null; + } + }); + + _game.getGameState().addCardToZone(_game, merry, Zone.FREE_CHARACTERS); + _game.getGameState().addCardToZone(_game, pippin, Zone.FREE_CHARACTERS); + + WoundCharactersEffect woundEffect = new WoundCharactersEffect(merry, merry, pippin); + + carryOutEffectInPhaseActionByPlayer(P1, woundEffect); + + assertEquals(0, _game.getGameState().getWounds(merry)); + assertEquals(1, _game.getGameState().getWounds(pippin)); + assertTrue(woundEffect.wasSuccessful()); + assertFalse(woundEffect.wasCarriedOut()); + + assertEquals(0, triggerCount.get()); + } + + private void carryOutEffectInPhaseActionByPlayer(String playerId, Effect effect) throws DecisionResultInvalidException { + CardActionSelectionDecision awaitingDecision = (CardActionSelectionDecision) _userFeedback.getAwaitingDecision(playerId); + SystemQueueAction action = new SystemQueueAction(); + action.appendEffect(effect); + awaitingDecision.addAction(action); + + playerDecided(playerId, "0"); + } +}