From 30fe344e23a2b35c40ae25fc172fbb41394e7d29 Mon Sep 17 00:00:00 2001 From: Oleg Agafonov Date: Sat, 29 Aug 2020 20:38:57 +0400 Subject: [PATCH] Test framework: added planes support in tests (command: addPlane) --- .../main/java/mage/server/MageServerImpl.java | 2 +- .../java/mage/server/util/SystemUtil.java | 54 +++++++++++-------- .../base/impl/CardTestPlayerAPIImpl.java | 5 ++ 3 files changed, 37 insertions(+), 24 deletions(-) diff --git a/Mage.Server/src/main/java/mage/server/MageServerImpl.java b/Mage.Server/src/main/java/mage/server/MageServerImpl.java index 0a0ae8eff1..e668311ac7 100644 --- a/Mage.Server/src/main/java/mage/server/MageServerImpl.java +++ b/Mage.Server/src/main/java/mage/server/MageServerImpl.java @@ -1102,7 +1102,7 @@ public class MageServerImpl implements MageServer { execute("removeTable", sessionId, () -> { SessionManager.instance.getSession(sessionId).ifPresent(session -> { UUID userId = session.getUserId(); - TableManager.instance.removeTable(userId, tableId); // delete account + TableManager.instance.removeTable(userId, tableId); }); }); } diff --git a/Mage.Server/src/main/java/mage/server/util/SystemUtil.java b/Mage.Server/src/main/java/mage/server/util/SystemUtil.java index 73aba819e8..eb116925a8 100644 --- a/Mage.Server/src/main/java/mage/server/util/SystemUtil.java +++ b/Mage.Server/src/main/java/mage/server/util/SystemUtil.java @@ -522,29 +522,7 @@ public final class SystemUtil { continue; } } else if ("plane".equalsIgnoreCase(command.zone)) { - // eg: plane:Human:BantPlane:1 - // Steps: 1) Remove the last plane and set its effects to discarded - for (CommandObject cobject : game.getState().getCommand()) { - if (cobject instanceof Plane) { - if (cobject.getAbilities() != null) { - for (Ability ability : cobject.getAbilities()) { - for (Effect effect : ability.getEffects()) { - if (effect instanceof ContinuousEffect) { - ((ContinuousEffect) effect).discard(); - } - } - } - } - game.getState().removeTriggersOfSourceId(cobject.getId()); - game.getState().getCommand().remove(cobject); - break; - } - } - Planes planeType = Planes.fromClassName(command.cardName); - Plane plane = Plane.createPlane(planeType); - if (plane != null) { - plane.setControllerId(player.getId()); - game.addPlane(plane, null, player.getId()); + if (putPlaneToGame(game, player, command.cardName)) { continue; } } else if ("loyalty".equalsIgnoreCase(command.zone)) { @@ -688,6 +666,36 @@ public final class SystemUtil { logger.info("Added card to player's " + zone.toString() + ": " + card.getName() + ", player = " + player.getName()); } + public static boolean putPlaneToGame(Game game, Player player, String planeClassName) { + // remove the last plane and set its effects to discarded + for (CommandObject comObject : game.getState().getCommand()) { + if (comObject instanceof Plane) { + if (comObject.getAbilities() != null) { + for (Ability ability : comObject.getAbilities()) { + for (Effect effect : ability.getEffects()) { + if (effect instanceof ContinuousEffect) { + ((ContinuousEffect) effect).discard(); + } + } + } + } + game.getState().removeTriggersOfSourceId(comObject.getId()); + game.getState().getCommand().remove(comObject); + break; + } + } + + // put new plane to game + Planes planeType = Planes.fromClassName(planeClassName); + Plane plane = Plane.createPlane(planeType); + if (plane != null) { + plane.setControllerId(player.getId()); + game.addPlane(plane, null, player.getId()); + return true; + } + return false; + } + /** * Find player by name. * diff --git a/Mage.Tests/src/test/java/org/mage/test/serverside/base/impl/CardTestPlayerAPIImpl.java b/Mage.Tests/src/test/java/org/mage/test/serverside/base/impl/CardTestPlayerAPIImpl.java index a7e11276fe..5df4d662a7 100644 --- a/Mage.Tests/src/test/java/org/mage/test/serverside/base/impl/CardTestPlayerAPIImpl.java +++ b/Mage.Tests/src/test/java/org/mage/test/serverside/base/impl/CardTestPlayerAPIImpl.java @@ -27,6 +27,7 @@ import mage.player.ai.ComputerPlayer7; import mage.player.ai.ComputerPlayerMCTS; import mage.players.ManaPool; import mage.players.Player; +import mage.server.util.SystemUtil; import mage.util.CardUtil; import org.junit.Assert; import org.junit.Before; @@ -657,6 +658,10 @@ public abstract class CardTestPlayerAPIImpl extends MageTestPlayerBase implement } } + public void addPlane(Player player, Planes plane) { + Assert.assertTrue("Can't put plane to game: " + plane.getClassName(), SystemUtil.putPlaneToGame(currentGame, player, plane.getClassName())); + } + /** * Returns card list container for specified game zone and player. *