From 6eef8f9e0c04219a559c2eea6a6dd7f5229b2ea9 Mon Sep 17 00:00:00 2001 From: Ingmar Goudt Date: Thu, 13 May 2021 13:19:08 +0200 Subject: [PATCH] add assertions for winning and losing the game --- .../mage/test/cards/copy/HiveMindTest.java | 4 ++-- .../cards/replacement/WinLoseEffectsTest.java | 10 ++++----- .../cards/single/afr/VorpalSwordTest.java | 3 ++- .../test/cards/triggers/BiovisionaryTest.java | 10 ++++----- .../duel/TeferiMageOfZhalfirTest.java | 4 ++-- .../mage/test/game/ends/GameIsADrawTest.java | 12 +++++------ .../game/ends/PhageTheUntouchableTest.java | 2 +- .../base/impl/CardTestPlayerAPIImpl.java | 21 +++++++++++++++++++ 8 files changed, 44 insertions(+), 22 deletions(-) diff --git a/Mage.Tests/src/test/java/org/mage/test/cards/copy/HiveMindTest.java b/Mage.Tests/src/test/java/org/mage/test/cards/copy/HiveMindTest.java index 7bc1b8ec59..3295ba79d1 100644 --- a/Mage.Tests/src/test/java/org/mage/test/cards/copy/HiveMindTest.java +++ b/Mage.Tests/src/test/java/org/mage/test/cards/copy/HiveMindTest.java @@ -65,8 +65,8 @@ public class HiveMindTest extends CardTestPlayerBase { assertGraveyardCount(playerA, "Pact of the Titan", 1); assertPermanentCount(playerA, "Giant", 0); // was countered by Chalice assertPermanentCount(playerB, "Giant", 1); // was not countered by Chalice because it was not cast - Assert.assertTrue("Player A must have won", playerA.hasWon()); - Assert.assertTrue("Player B must have lost", playerB.hasLost()); + assertWonTheGame(playerA); + assertLostTheGame(playerB); assertLife(playerB, 20); assertLife(playerA, 20); } diff --git a/Mage.Tests/src/test/java/org/mage/test/cards/replacement/WinLoseEffectsTest.java b/Mage.Tests/src/test/java/org/mage/test/cards/replacement/WinLoseEffectsTest.java index 45bb421761..0e2f5ab768 100644 --- a/Mage.Tests/src/test/java/org/mage/test/cards/replacement/WinLoseEffectsTest.java +++ b/Mage.Tests/src/test/java/org/mage/test/cards/replacement/WinLoseEffectsTest.java @@ -34,7 +34,7 @@ public class WinLoseEffectsTest extends CardTestPlayerBase { execute(); Assert.assertEquals("Player A library is empty", 0 , playerA.getLibrary().size()); - Assert.assertTrue("Player A has not won but should have", playerA.hasWon()); + assertWonTheGame(playerA); assertLife(playerA, 20); assertLife(playerB, 20); } @@ -67,7 +67,7 @@ public class WinLoseEffectsTest extends CardTestPlayerBase { assertPermanentCount(playerA, "Platinum Angel", 0); assertLibraryCount(playerA, 1); // Angel returned to top of library assertLibraryCount(playerA, "Platinum Angel", 1); - Assert.assertFalse("Player A should not have lost yet", playerA.hasLost()); + assertHasNotLostTheGame(playerA); } /** @@ -96,7 +96,7 @@ public class WinLoseEffectsTest extends CardTestPlayerBase { execute(); Assert.assertEquals("Player A library is empty", 0 , playerA.getLibrary().size()); - Assert.assertTrue("Player A has not won but should have", playerA.hasWon()); + assertWonTheGame(playerA); assertLife(playerA, 20); assertLife(playerB, 20); @@ -148,8 +148,8 @@ public class WinLoseEffectsTest extends CardTestPlayerBase { assertLife(playerA, -5); assertLife(playerB, 20); - - Assert.assertTrue("Player A has not won but should have", playerA.hasWon()); + + assertWonTheGame(playerA); } } diff --git a/Mage.Tests/src/test/java/org/mage/test/cards/single/afr/VorpalSwordTest.java b/Mage.Tests/src/test/java/org/mage/test/cards/single/afr/VorpalSwordTest.java index cffb43b09c..90b197368e 100644 --- a/Mage.Tests/src/test/java/org/mage/test/cards/single/afr/VorpalSwordTest.java +++ b/Mage.Tests/src/test/java/org/mage/test/cards/single/afr/VorpalSwordTest.java @@ -23,7 +23,8 @@ public class VorpalSwordTest extends CardTestPlayerBase { setStopAt(3, PhaseStep.POSTCOMBAT_MAIN); execute(); assertAllCommandsUsed(); - Assert.assertTrue("Player A has won.", playerA.hasWon()); + assertWonTheGame(playerA); + assertLostTheGame(playerB); } } diff --git a/Mage.Tests/src/test/java/org/mage/test/cards/triggers/BiovisionaryTest.java b/Mage.Tests/src/test/java/org/mage/test/cards/triggers/BiovisionaryTest.java index 4ba7acdb2b..6291ae1fcc 100644 --- a/Mage.Tests/src/test/java/org/mage/test/cards/triggers/BiovisionaryTest.java +++ b/Mage.Tests/src/test/java/org/mage/test/cards/triggers/BiovisionaryTest.java @@ -31,9 +31,9 @@ public class BiovisionaryTest extends CardTestPlayerBase { assertLife(playerB, 20); assertPermanentCount(playerA, "Biovisionary", 4); - - Assert.assertTrue("Player B loses",playerB.hasLost()); - Assert.assertTrue("Player A wins with four Biovisionary",playerA.hasWon()); + + assertLostTheGame(playerB); + assertWonTheGame(playerA); } @@ -61,8 +61,8 @@ public class BiovisionaryTest extends CardTestPlayerBase { assertLife(playerB, 20); assertPermanentCount(playerA, "Biovisionary", 4); - Assert.assertTrue("Player B loses",playerB.hasLost()); - Assert.assertTrue("Player A wins with four Biovisionary",playerA.hasWon()); + assertLostTheGame(playerB); + assertWonTheGame(playerA); } } diff --git a/Mage.Tests/src/test/java/org/mage/test/commander/duel/TeferiMageOfZhalfirTest.java b/Mage.Tests/src/test/java/org/mage/test/commander/duel/TeferiMageOfZhalfirTest.java index ea39296364..717d8bc06d 100644 --- a/Mage.Tests/src/test/java/org/mage/test/commander/duel/TeferiMageOfZhalfirTest.java +++ b/Mage.Tests/src/test/java/org/mage/test/commander/duel/TeferiMageOfZhalfirTest.java @@ -73,7 +73,7 @@ public class TeferiMageOfZhalfirTest extends CardTestCommanderDuelBase { assertPermanentCount(playerA, "Daxos of Meletis", 1); assertPowerToughness(playerA, "Daxos of Meletis", 6, 6); // no effects removes after game over -- users and tests can get last game state with all affected effects - Assert.assertEquals("Player A has won because of commander damage", true, playerA.hasWon()); - Assert.assertEquals("Player B has lost because of commander damage", true, playerB.hasLost()); + assertWonTheGame(playerA); + assertLostTheGame(playerB); } } \ No newline at end of file diff --git a/Mage.Tests/src/test/java/org/mage/test/game/ends/GameIsADrawTest.java b/Mage.Tests/src/test/java/org/mage/test/game/ends/GameIsADrawTest.java index 32df2b0748..6ed52f4c5c 100644 --- a/Mage.Tests/src/test/java/org/mage/test/game/ends/GameIsADrawTest.java +++ b/Mage.Tests/src/test/java/org/mage/test/game/ends/GameIsADrawTest.java @@ -37,8 +37,8 @@ public class GameIsADrawTest extends CardTestPlayerBase { assertLife(playerA, 0); assertLife(playerB, 0); - Assert.assertFalse("Player A has not won.", playerA.hasWon()); - Assert.assertFalse("Player B has not won.", playerB.hasWon()); + assertHasNotWonTheGame(playerA); + assertHasNotWonTheGame(playerB); Assert.assertTrue("Game has ended.", currentGame.hasEnded()); @@ -65,8 +65,8 @@ public class GameIsADrawTest extends CardTestPlayerBase { assertLife(playerA, 20); assertLife(playerB, 20); - Assert.assertFalse("Player A has not won.", playerA.hasWon()); - Assert.assertFalse("Player B has not won.", playerB.hasWon()); + assertHasNotWonTheGame(playerA); + assertHasNotWonTheGame(playerB); Assert.assertTrue("Game has ended.", currentGame.hasEnded()); @@ -106,8 +106,8 @@ public class GameIsADrawTest extends CardTestPlayerBase { Permanent shield = getPermanent("Pariah's Shield"); Assert.assertTrue("Pariah's Shield is attached", shield.getAttachedTo() != null); - Assert.assertFalse("Player A has not won.", playerA.hasWon()); - Assert.assertFalse("Player B has not won.", playerB.hasWon()); + assertHasNotWonTheGame(playerA); + assertHasNotWonTheGame(playerB); Assert.assertTrue("Game has ended.", currentGame.hasEnded()); diff --git a/Mage.Tests/src/test/java/org/mage/test/game/ends/PhageTheUntouchableTest.java b/Mage.Tests/src/test/java/org/mage/test/game/ends/PhageTheUntouchableTest.java index 04abf5db4b..752843e46e 100644 --- a/Mage.Tests/src/test/java/org/mage/test/game/ends/PhageTheUntouchableTest.java +++ b/Mage.Tests/src/test/java/org/mage/test/game/ends/PhageTheUntouchableTest.java @@ -49,7 +49,7 @@ public class PhageTheUntouchableTest extends CardTestPlayerBase { assertPermanentCount(playerB, "Phage the Untouchable", 1); Assert.assertTrue("Game has ended.", currentGame.hasEnded()); - Assert.assertTrue("Player A has won.", playerA.hasWon()); + assertWonTheGame(playerA); Assert.assertTrue("Game ist At end phase", currentGame.getPhase().getType() == TurnPhase.END); } 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 ca574fb47a..664e7bebc6 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 @@ -2095,4 +2095,25 @@ public abstract class CardTestPlayerAPIImpl extends MageTestPlayerBase implement } } + + public void assertWonTheGame(Player player){ + + Assert.assertTrue(player.getName() + " has not won the game.", player.hasWon()); + } + + public void assertHasNotWonTheGame(Player player){ + + Assert.assertFalse(player.getName() + " has won the game.", player.hasWon()); + } + + public void assertLostTheGame(Player player){ + + Assert.assertTrue(player.getName() + " has not lost the game.", player.hasLost()); + } + + public void assertHasNotLostTheGame(Player player){ + + Assert.assertFalse(player.getName() + " has lost the game.", player.hasLost()); + } + }