From 579f39c3cce24314b5446345a2c10750e8604c5c Mon Sep 17 00:00:00 2001 From: jendave Date: Thu, 17 Nov 2011 16:35:43 +0000 Subject: [PATCH] Cleaning up unit tests --- .gitattributes | 4 +- ...raft_1Test.java => BoosterDraft1Test.java} | 9 +- src/test/java/forge/BoosterDraftTest.java | 8 +- src/test/java/forge/CardColorTest.java | 4 +- src/test/java/forge/CardReaderTest.java | 5 +- src/test/java/forge/GameActionTest.java | 9 +- .../java/forge/GuiDownloadPicturesLQTest.java | 2 +- .../forge/GuiDownloadSetPicturesLQTest.java | 4 +- .../GuiMigrateLocalMWSSetPicturesHQTest.java | 2 +- .../java/forge/GuiMultipleBlockers4Test.java | 2 +- .../java/forge/GuiProgressBarWindowTest.java | 4 +- src/test/java/forge/GuiQuestOptionsTest.java | 4 +- src/test/java/forge/PanelTest.java | 2 +- src/test/java/forge/PhaseTest.java | 4 +- src/test/java/forge/RunTest.java | 525 +++++++++--------- .../card/cardFactory/CardFactoryUtilTest.java | 2 +- .../java/forge/card/mana/ManaPartTest.java | 473 ++++++++++++++++ .../java/forge/card/mana/Mana_PartTest.java | 521 ----------------- .../deck/generate/Generate2ColorDeckTest.java | 17 +- .../deck/generate/Generate3ColorDeckTest.java | 18 +- .../deck/generate/Generate5ColorDeckTest.java | 18 +- .../generate/GenerateConstructedDeckTest.java | 19 +- ...GenerateConstructedMultiColorDeckTest.java | 20 +- src/test/java/forge/gui/ListChooserTest.java | 17 +- .../forge/gui/game/CardDetailPanelTest.java | 15 +- src/test/java/forge/model/BuildInfoTest.java | 148 +++-- src/test/java/forge/model/FModelTest.java | 87 +-- .../util/testng/BraidsAssertFunctions.java | 27 +- 28 files changed, 975 insertions(+), 995 deletions(-) rename src/test/java/forge/{BoosterDraft_1Test.java => BoosterDraft1Test.java} (81%) create mode 100644 src/test/java/forge/card/mana/ManaPartTest.java delete mode 100644 src/test/java/forge/card/mana/Mana_PartTest.java diff --git a/.gitattributes b/.gitattributes index fb500e99be2..d477b69c55f 100644 --- a/.gitattributes +++ b/.gitattributes @@ -10847,8 +10847,8 @@ src/main/java/tree/properties/types/FileType.java svneol=native#text/plain src/main/java/tree/properties/types/package-info.java svneol=native#text/plain src/main/resources/proxy-template.ftl -text src/site/apt/index.apt -text +src/test/java/forge/BoosterDraft1Test.java svneol=native#text/plain src/test/java/forge/BoosterDraftTest.java svneol=native#text/plain -src/test/java/forge/BoosterDraft_1Test.java svneol=native#text/plain src/test/java/forge/CardColorTest.java svneol=native#text/plain src/test/java/forge/CardReaderTest.java svneol=native#text/plain src/test/java/forge/GameActionTest.java svneol=native#text/plain @@ -10865,7 +10865,7 @@ src/test/java/forge/RunTest.java svneol=native#text/plain src/test/java/forge/TinyTest.java svneol=native#text/plain src/test/java/forge/card/cardFactory/CardFactoryTest.java svneol=native#text/plain src/test/java/forge/card/cardFactory/CardFactoryUtilTest.java svneol=native#text/plain -src/test/java/forge/card/mana/Mana_PartTest.java svneol=native#text/plain +src/test/java/forge/card/mana/ManaPartTest.java svneol=native#text/plain src/test/java/forge/deck/generate/Generate2ColorDeckTest.java svneol=native#text/plain src/test/java/forge/deck/generate/Generate3ColorDeckTest.java svneol=native#text/plain src/test/java/forge/deck/generate/Generate5ColorDeckTest.java svneol=native#text/plain diff --git a/src/test/java/forge/BoosterDraft_1Test.java b/src/test/java/forge/BoosterDraft1Test.java similarity index 81% rename from src/test/java/forge/BoosterDraft_1Test.java rename to src/test/java/forge/BoosterDraft1Test.java index 411f658631e..866e551dd5b 100644 --- a/src/test/java/forge/BoosterDraft_1Test.java +++ b/src/test/java/forge/BoosterDraft1Test.java @@ -11,15 +11,16 @@ import forge.item.ItemPoolView; * Unit test for simple App. */ @Test(groups = { "UnitTest" }, timeOut = 1000) -public class BoosterDraft_1Test { +public class BoosterDraft1Test { /** * Booster draft_1 test1. - * - * @throws Exception the exception + * + * @throws Exception + * the exception */ @Test(groups = { "UnitTest", "fast" }, timeOut = 1000) - public void BoosterDraft_1Test1() throws Exception { + public void boosterDraft1Test1() throws Exception { final BoosterDraft draft = new BoosterDraft(CardPoolLimitation.Full); while (draft.hasNextChoice()) { final ItemPoolView list = draft.nextChoice(); diff --git a/src/test/java/forge/BoosterDraftTest.java b/src/test/java/forge/BoosterDraftTest.java index 24adc0ac011..442da08d049 100644 --- a/src/test/java/forge/BoosterDraftTest.java +++ b/src/test/java/forge/BoosterDraftTest.java @@ -19,9 +19,9 @@ import forge.item.ItemPoolView; */ @Test(groups = { "UnitTest" }, timeOut = 1000, enabled = false) public class BoosterDraftTest implements IBoosterDraft { - + /** The n. */ - int n = 3; + private int n = 3; /** *

@@ -90,7 +90,9 @@ public class BoosterDraftTest implements IBoosterDraft { return null; } - /* (non-Javadoc) + /* + * (non-Javadoc) + * * @see forge.game.limited.IBoosterDraft#finishedDrafting() */ @Override diff --git a/src/test/java/forge/CardColorTest.java b/src/test/java/forge/CardColorTest.java index c1762948099..072f43e00df 100644 --- a/src/test/java/forge/CardColorTest.java +++ b/src/test/java/forge/CardColorTest.java @@ -11,12 +11,12 @@ import forge.card.mana.ManaCost; */ @Test(groups = { "UnitTest" }, timeOut = 1000) public class CardColorTest { - + /** * Card color test1. */ @Test(groups = { "UnitTest", "fast" }, timeOut = 1000) - public void CardColorTest1() { + public void cardColorTest1() { final ManaCost mc = new ManaCost("R W U"); final EnumSet col = Color.convertManaCostToColor(mc); System.out.println(col.toString()); diff --git a/src/test/java/forge/CardReaderTest.java b/src/test/java/forge/CardReaderTest.java index cf4d78d4e7c..c8db534101b 100644 --- a/src/test/java/forge/CardReaderTest.java +++ b/src/test/java/forge/CardReaderTest.java @@ -78,8 +78,9 @@ public class CardReaderTest { /** * Test_ read card_file not folder. - * - * @throws IOException Signals that an I/O exception has occurred. + * + * @throws IOException + * Signals that an I/O exception has occurred. */ @Test(groups = { "UnitTest", "fast" }, timeOut = CardReaderTest.TEST_TIMEOUT) public final void test_ReadCard_fileNotFolder() throws IOException { diff --git a/src/test/java/forge/GameActionTest.java b/src/test/java/forge/GameActionTest.java index 138f11859bd..5d25c80b385 100644 --- a/src/test/java/forge/GameActionTest.java +++ b/src/test/java/forge/GameActionTest.java @@ -14,11 +14,12 @@ public class GameActionTest { *

* main. *

- * - * @throws Exception the exception + * + * @throws Exception + * the exception */ @Test(groups = { "UnitTest", "fast" }, timeOut = 5000) - public void GameActionTest1() throws Exception { + public void gameActionTest1() throws Exception { System.out.println("GameActionTest"); final GameAction gameAction = new GameAction(); final GenerateConstructedDeck gen = new GenerateConstructedDeck(); @@ -37,6 +38,6 @@ public class GameActionTest { System.out.println("error - " + check); break; } - }// for + } // for } } diff --git a/src/test/java/forge/GuiDownloadPicturesLQTest.java b/src/test/java/forge/GuiDownloadPicturesLQTest.java index 28580988f28..0dd52736318 100644 --- a/src/test/java/forge/GuiDownloadPicturesLQTest.java +++ b/src/test/java/forge/GuiDownloadPicturesLQTest.java @@ -12,7 +12,7 @@ public class GuiDownloadPicturesLQTest { * Gui download pictures test1. */ @Test(enabled = false, timeOut = 1000) - public void GuiDownloadPicturesTest1() { + public void guiDownloadPicturesTest1() { new GuiDownloadPicturesLQ(null); } } diff --git a/src/test/java/forge/GuiDownloadSetPicturesLQTest.java b/src/test/java/forge/GuiDownloadSetPicturesLQTest.java index 693460a006d..3d786e8b7c9 100644 --- a/src/test/java/forge/GuiDownloadSetPicturesLQTest.java +++ b/src/test/java/forge/GuiDownloadSetPicturesLQTest.java @@ -7,12 +7,12 @@ import org.testng.annotations.Test; */ @Test(groups = { "UnitTest" }, timeOut = 1000, enabled = false) public class GuiDownloadSetPicturesLQTest { - + /** * Gui download set pictures lq test1. */ @Test(enabled = false, timeOut = 1000) - public void GuiDownloadSetPicturesLQTest1() { + public void g() { new GuiDownloadSetPicturesLQ(null); } } diff --git a/src/test/java/forge/GuiMigrateLocalMWSSetPicturesHQTest.java b/src/test/java/forge/GuiMigrateLocalMWSSetPicturesHQTest.java index 5ec7faa23d3..2c5265d4cb8 100644 --- a/src/test/java/forge/GuiMigrateLocalMWSSetPicturesHQTest.java +++ b/src/test/java/forge/GuiMigrateLocalMWSSetPicturesHQTest.java @@ -12,7 +12,7 @@ public class GuiMigrateLocalMWSSetPicturesHQTest { * Gui migrate local mws set pictures h q1. */ @Test(enabled = false, timeOut = 1000) - public void GuiMigrateLocalMWSSetPicturesHQ1() { + public void guiMigrateLocalMWSSetPicturesHQ1() { GuiMigrateLocalMWSSetPicturesHQ.startDownload(null); } } diff --git a/src/test/java/forge/GuiMultipleBlockers4Test.java b/src/test/java/forge/GuiMultipleBlockers4Test.java index ea9779418d5..23de76a2a54 100644 --- a/src/test/java/forge/GuiMultipleBlockers4Test.java +++ b/src/test/java/forge/GuiMultipleBlockers4Test.java @@ -12,7 +12,7 @@ public class GuiMultipleBlockers4Test { * Gui multiple blockers4 test1. */ @Test(timeOut = 1000, enabled = false) - public void GuiMultipleBlockers4Test1() { + public void guiMultipleBlockers4Test1() { final CardList list = new CardList(); list.add(AllZone.getCardFactory().getCard("Elvish Piper", null)); list.add(AllZone.getCardFactory().getCard("Lantern Kami", null)); diff --git a/src/test/java/forge/GuiProgressBarWindowTest.java b/src/test/java/forge/GuiProgressBarWindowTest.java index 757b50cb07c..b59517bbf5e 100644 --- a/src/test/java/forge/GuiProgressBarWindowTest.java +++ b/src/test/java/forge/GuiProgressBarWindowTest.java @@ -10,12 +10,12 @@ import org.testng.annotations.Test; */ @Test(groups = { "UnitTest" }) public class GuiProgressBarWindowTest { - + /** * Gui progress bar window test1. */ @Test(groups = { "UnitTest", "fast" }) - public void GuiProgressBarWindowTest1() { + public void guiProgressBarWindowTest1() { try { final GuiProgressBarWindow dialog = new GuiProgressBarWindow(); dialog.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE); diff --git a/src/test/java/forge/GuiQuestOptionsTest.java b/src/test/java/forge/GuiQuestOptionsTest.java index ac579673ea9..1ce80c96ce7 100644 --- a/src/test/java/forge/GuiQuestOptionsTest.java +++ b/src/test/java/forge/GuiQuestOptionsTest.java @@ -10,12 +10,12 @@ import forge.quest.gui.QuestOptions; */ @Test(groups = { "UnitTest" }) public class GuiQuestOptionsTest { - + /** * Gui quest options test1. */ @Test(groups = { "UnitTest", "fast" }) - public void GuiQuestOptionsTest1() { + public void guiQuestOptionsTest1() { final QuestOptions dialog = new QuestOptions(); dialog.setVisible(true); Assert.assertNotNull(dialog); diff --git a/src/test/java/forge/PanelTest.java b/src/test/java/forge/PanelTest.java index 5578716208d..91a9d524a78 100644 --- a/src/test/java/forge/PanelTest.java +++ b/src/test/java/forge/PanelTest.java @@ -32,7 +32,7 @@ public class PanelTest extends JFrame { * Phase test1. */ @Test(timeOut = 1000, enabled = false) - public void PhaseTest1() { + public void phaseTest1() { final PanelTest p = new PanelTest(); p.setSize(300, 300); p.setVisible(true); diff --git a/src/test/java/forge/PhaseTest.java b/src/test/java/forge/PhaseTest.java index b7a4ce801b3..e83b888dd8c 100644 --- a/src/test/java/forge/PhaseTest.java +++ b/src/test/java/forge/PhaseTest.java @@ -7,12 +7,12 @@ import org.testng.annotations.Test; */ @Test(groups = { "UnitTest" }, timeOut = 5000, enabled = false) public class PhaseTest { - + /** * Phase test1. */ @Test(groups = { "UnitTest", "fast" }, timeOut = 5000, enabled = false) - public void PhaseTest1() { + public void phaseTest1() { final Phase phase = new Phase(); for (int i = 0; i < phase.getPhaseOrder().length; i++) { System.out.println(phase.getPlayerTurn() + " " + phase.getPhase()); diff --git a/src/test/java/forge/RunTest.java b/src/test/java/forge/RunTest.java index 05f3496df89..a1576413e20 100644 --- a/src/test/java/forge/RunTest.java +++ b/src/test/java/forge/RunTest.java @@ -29,307 +29,300 @@ public class RunTest { */ @Test(timeOut = 1000, enabled = false) void test() { - { - Card c; - final CardFactoryInterface cf = AllZone.getCardFactory(); - // ********* test Card - c = cf.getCard("Elvish Warrior", AllZone.getComputerPlayer()); - this.check("1", c.getOwner().isComputer()); - this.check("1.1", c.getName().equals("Elvish Warrior")); - this.check("2", c.getManaCost().equals("G G")); - this.check("2.1", c.isCreature()); - this.check("2.2", c.isType("Elf")); - this.check("2.3", c.isType("Warrior")); - this.check("3", c.getText().equals("")); - this.check("4", c.getNetAttack() == 2); - this.check("5", c.getNetDefense() == 3); - this.check("6", c.getKeyword().isEmpty()); + Card c; + final CardFactoryInterface cf = AllZone.getCardFactory(); + // ********* test Card + c = cf.getCard("Elvish Warrior", AllZone.getComputerPlayer()); + this.check("1", c.getOwner().isComputer()); + this.check("1.1", c.getName().equals("Elvish Warrior")); + this.check("2", c.getManaCost().equals("G G")); + this.check("2.1", c.isCreature()); + this.check("2.2", c.isType("Elf")); + this.check("2.3", c.isType("Warrior")); + this.check("3", c.getText().equals("")); + this.check("4", c.getNetAttack() == 2); + this.check("5", c.getNetDefense() == 3); + this.check("6", c.getKeyword().isEmpty()); - c = cf.getCard("Shock", null); - this.check("14", c.isInstant()); - // check("15", - // c.getText().equals("Shock deals 2 damge to target creature or player.")); + c = cf.getCard("Shock", null); + this.check("14", c.isInstant()); + // check("15", + // c.getText().equals("Shock deals 2 damge to target creature or player.")); - c = cf.getCard("Bayou", null); - this.check("17", c.getManaCost().equals("")); - this.check("18", c.isLand()); - this.check("19", c.isType("Swamp")); - this.check("20", c.isType("Forest")); + c = cf.getCard("Bayou", null); + this.check("17", c.getManaCost().equals("")); + this.check("18", c.isLand()); + this.check("19", c.isType("Swamp")); + this.check("20", c.isType("Forest")); - // ********* test ManaCost - ManaCost manaCost = new ManaCost("G"); - this.check("21", !manaCost.isPaid()); - manaCost.payMana(Constant.Color.GREEN); - this.check("22", manaCost.isPaid()); + // ********* test ManaCost + ManaCost manaCost = new ManaCost("G"); + this.check("21", !manaCost.isPaid()); + manaCost.payMana(Constant.Color.GREEN); + this.check("22", manaCost.isPaid()); - manaCost = new ManaCost("7"); - this.check("23", !manaCost.isPaid()); - manaCost.payMana(Constant.Color.BLACK); - this.check("24", !manaCost.isPaid()); - manaCost.payMana(Constant.Color.BLUE); - this.check("25", !manaCost.isPaid()); - manaCost.payMana(Constant.Color.COLORLESS); - this.check("26", !manaCost.isPaid()); - manaCost.payMana(Constant.Color.GREEN); - this.check("27", !manaCost.isPaid()); - manaCost.payMana(Constant.Color.RED); - this.check("28", !manaCost.isPaid()); - manaCost.payMana(Constant.Color.WHITE); - this.check("29", !manaCost.isPaid()); - manaCost.payMana(Constant.Color.WHITE); - this.check("30", manaCost.isPaid()); + manaCost = new ManaCost("7"); + this.check("23", !manaCost.isPaid()); + manaCost.payMana(Constant.Color.BLACK); + this.check("24", !manaCost.isPaid()); + manaCost.payMana(Constant.Color.BLUE); + this.check("25", !manaCost.isPaid()); + manaCost.payMana(Constant.Color.COLORLESS); + this.check("26", !manaCost.isPaid()); + manaCost.payMana(Constant.Color.GREEN); + this.check("27", !manaCost.isPaid()); + manaCost.payMana(Constant.Color.RED); + this.check("28", !manaCost.isPaid()); + manaCost.payMana(Constant.Color.WHITE); + this.check("29", !manaCost.isPaid()); + manaCost.payMana(Constant.Color.WHITE); + this.check("30", manaCost.isPaid()); - manaCost = new ManaCost("2 W W G G B B U U R R"); - this.check("31", !manaCost.isPaid()); - manaCost.payMana(Constant.Color.WHITE); - this.check("32", !manaCost.isPaid()); - manaCost.payMana(Constant.Color.WHITE); - this.check("32.1", !manaCost.isPaid()); - manaCost.payMana(Constant.Color.BLACK); - this.check("33", !manaCost.isPaid()); - manaCost.payMana(Constant.Color.BLACK); - this.check("34", !manaCost.isPaid()); - manaCost.payMana(Constant.Color.BLUE); - this.check("35", !manaCost.isPaid()); - manaCost.payMana(Constant.Color.BLUE); - this.check("36", !manaCost.isPaid()); - manaCost.payMana(Constant.Color.GREEN); - this.check("37", !manaCost.isPaid()); - manaCost.payMana(Constant.Color.GREEN); - this.check("38", !manaCost.isPaid()); - manaCost.payMana(Constant.Color.RED); - this.check("39", !manaCost.isPaid()); - manaCost.payMana(Constant.Color.RED); - this.check("40", !manaCost.isPaid()); - manaCost.payMana(Constant.Color.RED); - this.check("41", !manaCost.isPaid()); - manaCost.payMana(Constant.Color.BLUE); - this.check("42", manaCost.isPaid()); + manaCost = new ManaCost("2 W W G G B B U U R R"); + this.check("31", !manaCost.isPaid()); + manaCost.payMana(Constant.Color.WHITE); + this.check("32", !manaCost.isPaid()); + manaCost.payMana(Constant.Color.WHITE); + this.check("32.1", !manaCost.isPaid()); + manaCost.payMana(Constant.Color.BLACK); + this.check("33", !manaCost.isPaid()); + manaCost.payMana(Constant.Color.BLACK); + this.check("34", !manaCost.isPaid()); + manaCost.payMana(Constant.Color.BLUE); + this.check("35", !manaCost.isPaid()); + manaCost.payMana(Constant.Color.BLUE); + this.check("36", !manaCost.isPaid()); + manaCost.payMana(Constant.Color.GREEN); + this.check("37", !manaCost.isPaid()); + manaCost.payMana(Constant.Color.GREEN); + this.check("38", !manaCost.isPaid()); + manaCost.payMana(Constant.Color.RED); + this.check("39", !manaCost.isPaid()); + manaCost.payMana(Constant.Color.RED); + this.check("40", !manaCost.isPaid()); + manaCost.payMana(Constant.Color.RED); + this.check("41", !manaCost.isPaid()); + manaCost.payMana(Constant.Color.BLUE); + this.check("42", manaCost.isPaid()); - manaCost = new ManaCost("G G"); - this.check("43", !manaCost.isPaid()); - manaCost.payMana(Constant.Color.GREEN); - this.check("44", !manaCost.isPaid()); - manaCost.payMana(Constant.Color.GREEN); - this.check("45", manaCost.isPaid()); + manaCost = new ManaCost("G G"); + this.check("43", !manaCost.isPaid()); + manaCost.payMana(Constant.Color.GREEN); + this.check("44", !manaCost.isPaid()); + manaCost.payMana(Constant.Color.GREEN); + this.check("45", manaCost.isPaid()); - manaCost = new ManaCost("1 U B"); - this.check("45", !manaCost.isPaid()); - manaCost.payMana(Constant.Color.BLACK); - this.check("46", !manaCost.isPaid()); - manaCost.payMana(Constant.Color.BLUE); - this.check("47", !manaCost.isPaid()); - manaCost.payMana(Constant.Color.BLUE); - this.check("48", manaCost.isPaid()); + manaCost = new ManaCost("1 U B"); + this.check("45", !manaCost.isPaid()); + manaCost.payMana(Constant.Color.BLACK); + this.check("46", !manaCost.isPaid()); + manaCost.payMana(Constant.Color.BLUE); + this.check("47", !manaCost.isPaid()); + manaCost.payMana(Constant.Color.BLUE); + this.check("48", manaCost.isPaid()); - // ********* test CardUtil.getColors() - c = new Card(); - c.setManaCost("G"); - ArrayList color = CardUtil.getColors(c); - this.check("49", color.contains(Constant.Color.GREEN)); - this.check("50", color.size() == 1); + // ********* test CardUtil.getColors() + c = new Card(); + c.setManaCost("G"); + ArrayList color = CardUtil.getColors(c); + this.check("49", color.contains(Constant.Color.GREEN)); + this.check("50", color.size() == 1); - c = new Card(); - c.setManaCost("W B G R U"); - color = CardUtil.getColors(c); - final Set set = new HashSet(color); - System.out.println("color: " + color); - this.check("51", set.size() == 5); - this.check("52", color.contains(Constant.Color.BLACK)); - this.check("53", color.contains(Constant.Color.BLUE)); - this.check("54", color.contains(Constant.Color.GREEN)); - this.check("55", color.contains(Constant.Color.RED)); - this.check("56", color.contains(Constant.Color.WHITE)); + c = new Card(); + c.setManaCost("W B G R U"); + color = CardUtil.getColors(c); + final Set set = new HashSet(color); + System.out.println("color: " + color); + this.check("51", set.size() == 5); + this.check("52", color.contains(Constant.Color.BLACK)); + this.check("53", color.contains(Constant.Color.BLUE)); + this.check("54", color.contains(Constant.Color.GREEN)); + this.check("55", color.contains(Constant.Color.RED)); + this.check("56", color.contains(Constant.Color.WHITE)); - c = new Card(); - c.setManaCost("2"); - color = CardUtil.getColors(c); - this.check("57", color.size() == 1); - this.check("58", color.contains(Constant.Color.COLORLESS)); + c = new Card(); + c.setManaCost("2"); + color = CardUtil.getColors(c); + this.check("57", color.size() == 1); + this.check("58", color.contains(Constant.Color.COLORLESS)); - c = new Card(); - color = CardUtil.getColors(c); - this.check("59", color.size() == 1); - this.check("60", color.contains(Constant.Color.COLORLESS)); + c = new Card(); + color = CardUtil.getColors(c); + this.check("59", color.size() == 1); + this.check("60", color.contains(Constant.Color.COLORLESS)); - c = new Card(); - c.setManaCost(""); - color = CardUtil.getColors(c); - this.check("61", color.size() == 1); - this.check("62", color.contains(Constant.Color.COLORLESS)); + c = new Card(); + c.setManaCost(""); + color = CardUtil.getColors(c); + this.check("61", color.size() == 1); + this.check("62", color.contains(Constant.Color.COLORLESS)); - c = cf.getCard("Bayou", null); - color = CardUtil.getColors(c); - this.check("63", color.size() == 1); - this.check("64", color.contains(Constant.Color.COLORLESS)); + c = cf.getCard("Bayou", null); + color = CardUtil.getColors(c); + this.check("63", color.size() == 1); + this.check("64", color.contains(Constant.Color.COLORLESS)); - c = cf.getCard("Elvish Warrior", null); - color = CardUtil.getColors(c); - this.check("65", color.size() == 1); - this.check("66", color.contains(Constant.Color.GREEN)); + c = cf.getCard("Elvish Warrior", null); + color = CardUtil.getColors(c); + this.check("65", color.size() == 1); + this.check("66", color.contains(Constant.Color.GREEN)); - c = new Card(); - c.setManaCost("11 W W B B U U R R G G"); - color = CardUtil.getColors(c); - this.check("67", color.size() == 5); + c = new Card(); + c.setManaCost("11 W W B B U U R R G G"); + color = CardUtil.getColors(c); + this.check("67", color.size() == 5); - c = new Card(); - c = cf.getCard("Elvish Warrior", null); - c.setManaCost("11"); - color = CardUtil.getColors(c); - this.check("68", color.size() == 1); - this.check("69", color.contains(Constant.Color.COLORLESS)); + c = new Card(); + c = cf.getCard("Elvish Warrior", null); + c.setManaCost("11"); + color = CardUtil.getColors(c); + this.check("68", color.size() == 1); + this.check("69", color.contains(Constant.Color.COLORLESS)); - this.check("70", c.isCreature()); - this.check("71", !c.isArtifact()); - this.check("72", !c.isBasicLand()); - this.check("73", !c.isEnchantment()); - this.check("74", !c.isGlobalEnchantment()); - this.check("75", !c.isInstant()); - this.check("76", !c.isLand()); - this.check("77", !c.isAura()); - this.check("78", c.isPermanent()); - this.check("79", !c.isSorcery()); - this.check("80", !c.isTapped()); - this.check("81", c.isUntapped()); + this.check("70", c.isCreature()); + this.check("71", !c.isArtifact()); + this.check("72", !c.isBasicLand()); + this.check("73", !c.isEnchantment()); + this.check("74", !c.isGlobalEnchantment()); + this.check("75", !c.isInstant()); + this.check("76", !c.isLand()); + this.check("77", !c.isAura()); + this.check("78", c.isPermanent()); + this.check("79", !c.isSorcery()); + this.check("80", !c.isTapped()); + this.check("81", c.isUntapped()); - c = cf.getCard("Swamp", null); - this.check("82", c.isBasicLand()); - this.check("83", c.isLand()); + c = cf.getCard("Swamp", null); + this.check("82", c.isBasicLand()); + this.check("83", c.isLand()); - c = cf.getCard("Bayou", null); - this.check("84", !c.isBasicLand()); - this.check("85", c.isLand()); + c = cf.getCard("Bayou", null); + this.check("84", !c.isBasicLand()); + this.check("85", c.isLand()); - c = cf.getCard("Shock", null); - this.check("86", !c.isCreature()); - this.check("87", !c.isArtifact()); - this.check("88", !c.isBasicLand()); - this.check("89", !c.isEnchantment()); - this.check("90", !c.isGlobalEnchantment()); - this.check("91", c.isInstant()); - this.check("92", !c.isLand()); - this.check("93", !c.isAura()); - this.check("94", !c.isPermanent()); - this.check("95", !c.isSorcery()); - this.check("96", !c.isTapped()); - this.check("97", c.isUntapped()); + c = cf.getCard("Shock", null); + this.check("86", !c.isCreature()); + this.check("87", !c.isArtifact()); + this.check("88", !c.isBasicLand()); + this.check("89", !c.isEnchantment()); + this.check("90", !c.isGlobalEnchantment()); + this.check("91", c.isInstant()); + this.check("92", !c.isLand()); + this.check("93", !c.isAura()); + this.check("94", !c.isPermanent()); + this.check("95", !c.isSorcery()); + this.check("96", !c.isTapped()); + this.check("97", c.isUntapped()); - // test Input_PayManaCostUtil - this.check("98", InputPayManaCostUtil.getLongColorString("G").equals(Constant.Color.GREEN)); - this.check("99", InputPayManaCostUtil.getLongColorString("1").equals(Constant.Color.COLORLESS)); + // test Input_PayManaCostUtil + this.check("98", InputPayManaCostUtil.getLongColorString("G").equals(Constant.Color.GREEN)); + this.check("99", InputPayManaCostUtil.getLongColorString("1").equals(Constant.Color.COLORLESS)); - /* - * check("101", - * Input_PayManaCostUtil.isManaNeeded(Constant.Color.Green, new - * ManaCost("5")) == true); check("102", - * Input_PayManaCostUtil.isManaNeeded(Constant.Color.Blue, new - * ManaCost("4")) == true); check("103", - * Input_PayManaCostUtil.isManaNeeded(Constant.Color.White, new - * ManaCost("3")) == true); check("104", - * Input_PayManaCostUtil.isManaNeeded(Constant.Color.Black, new - * ManaCost("2")) == true); check("105", - * Input_PayManaCostUtil.isManaNeeded(Constant.Color.Red, new - * ManaCost("1")) == true); - */ - /* - * ManaCost cost = new ManaCost("1 B B"); - * Input_PayManaCostUtil.isManaNeeded(Constant.Color.Black, cost); - * cost.subtractMana(Constant.Color.Black); - * cost.subtractMana(Constant.Color.Green); check("106", - * Input_PayManaCostUtil.isManaNeeded(Constant.Color.Green, cost) == - * false); - */ + /* + * check("101", Input_PayManaCostUtil.isManaNeeded(Constant.Color.Green, + * new ManaCost("5")) == true); check("102", + * Input_PayManaCostUtil.isManaNeeded(Constant.Color.Blue, new + * ManaCost("4")) == true); check("103", + * Input_PayManaCostUtil.isManaNeeded(Constant.Color.White, new + * ManaCost("3")) == true); check("104", + * Input_PayManaCostUtil.isManaNeeded(Constant.Color.Black, new + * ManaCost("2")) == true); check("105", + * Input_PayManaCostUtil.isManaNeeded(Constant.Color.Red, new + * ManaCost("1")) == true); + */ + /* + * ManaCost cost = new ManaCost("1 B B"); + * Input_PayManaCostUtil.isManaNeeded(Constant.Color.Black, cost); + * cost.subtractMana(Constant.Color.Black); + * cost.subtractMana(Constant.Color.Green); check("106", + * Input_PayManaCostUtil.isManaNeeded(Constant.Color.Green, cost) == + * false); + */ - c = new Card(); - Card c2 = new Card(); - c.addIntrinsicKeyword("Flying"); - c2.addIntrinsicKeyword("Flying"); - // check("107", CombatUtil.canBlock(c, c2)); - // check("108", CombatUtil.canBlock(c2, c)); + c = new Card(); + Card c2 = new Card(); + c.addIntrinsicKeyword("Flying"); + c2.addIntrinsicKeyword("Flying"); + // check("107", CombatUtil.canBlock(c, c2)); + // check("108", CombatUtil.canBlock(c2, c)); - c = new Card(); - c2 = new Card(); - c2.addIntrinsicKeyword("Flying"); - this.check("109", CombatUtil.canBlock(c, c2)); - this.check("110", !CombatUtil.canBlock(c2, c)); + c = new Card(); + c2 = new Card(); + c2.addIntrinsicKeyword("Flying"); + this.check("109", CombatUtil.canBlock(c, c2)); + this.check("110", !CombatUtil.canBlock(c2, c)); - c = cf.getCard("Fyndhorn Elves", null); - c2 = cf.getCard("Talas Warrior", null); - this.check("110a", !CombatUtil.canBlock(c2, c)); - this.check("110b", CombatUtil.canBlock(c, c2)); + c = cf.getCard("Fyndhorn Elves", null); + c2 = cf.getCard("Talas Warrior", null); + this.check("110a", !CombatUtil.canBlock(c2, c)); + this.check("110b", CombatUtil.canBlock(c, c2)); - c = new Card(); - c.setName("1"); - c.setUniqueNumber(1); - c2 = new Card(); - c2.setName("2"); - c2.setUniqueNumber(2); + c = new Card(); + c.setName("1"); + c.setUniqueNumber(1); + c2 = new Card(); + c2.setName("2"); + c2.setUniqueNumber(2); - // test CardList - final CardList cardList = new CardList(new Card[] { c, c2 }); - this.check("111", cardList.contains(c)); - this.check("112", cardList.contains(c2)); - this.check("113", cardList.containsName(c)); - this.check("114", cardList.containsName(c.getName())); - this.check("115", cardList.containsName(c2)); - this.check("116", cardList.containsName(c2.getName())); + // test CardList + final CardList cardList = new CardList(new Card[] { c, c2 }); + this.check("111", cardList.contains(c)); + this.check("112", cardList.contains(c2)); + this.check("113", cardList.containsName(c)); + this.check("114", cardList.containsName(c.getName())); + this.check("115", cardList.containsName(c2)); + this.check("116", cardList.containsName(c2.getName())); - c = new Card(); - this.check("117", c.hasSickness() == true); - c.addIntrinsicKeyword("Haste"); - this.check("118", c.hasSickness() == false); + c = new Card(); + this.check("117", c.hasSickness()); + c.addIntrinsicKeyword("Haste"); + this.check("118", !c.hasSickness()); - } + final CardFactoryInterface cf1 = AllZone.getCardFactory(); + final CardList c1 = new CardList(); + c1.add(cf1.getCard("Shock", null)); + c1.add(cf1.getCard("Royal Assassin", null)); + c1.add(cf1.getCard("Hymn to Tourach", null)); - { - final CardFactoryInterface cf = AllZone.getCardFactory(); - final CardList c1 = new CardList(); - c1.add(cf.getCard("Shock", null)); - c1.add(cf.getCard("Royal Assassin", null)); - c1.add(cf.getCard("Hymn to Tourach", null)); + CardList c3 = c1.filter(new CardListFilter() { + @Override + public boolean addCard(final Card c) { + return c.isCreature(); + } + }); + this.check("119", c3.containsName("Royal Assassin")); + this.check("119", c3.size() == 1); - CardList c2 = c1.filter(new CardListFilter() { - @Override - public boolean addCard(final Card c) { - return c.isCreature(); - } - }); - this.check("119", c2.containsName("Royal Assassin")); - this.check("119", c2.size() == 1); + c3 = c1.filter(new CardListFilter() { + @Override + public boolean addCard(final Card c) { + return c.isInstant(); + } + }); + this.check("120", c3.containsName("Shock")); + this.check("121", c3.size() == 1); - c2 = c1.filter(new CardListFilter() { - @Override - public boolean addCard(final Card c) { - return c.isInstant(); - } - }); - this.check("120", c2.containsName("Shock")); - this.check("121", c2.size() == 1); + c3 = c1.filter(new CardListFilter() { + @Override + public boolean addCard(final Card c) { + return c.getName().equals("Hymn to Tourach"); + } + }); + this.check("120", c3.containsName("Hymn to Tourach")); + this.check("121", c3.size() == 1); - c2 = c1.filter(new CardListFilter() { - @Override - public boolean addCard(final Card c) { - return c.getName().equals("Hymn to Tourach"); - } - }); - this.check("120", c2.containsName("Hymn to Tourach")); - this.check("121", c2.size() == 1); + final Card card = cf1.getCard("Sylvan Basilisk", null); + final Card card2 = cf1.getCard("Exalted Angel", null); - final Card card = cf.getCard("Sylvan Basilisk", null); - final Card card2 = cf.getCard("Exalted Angel", null); + this.check("121a", !CombatUtil.canDestroyAttacker(card, card2, null, false)); - this.check("121a", !CombatUtil.canDestroyAttacker(card, card2, null, false)); - } - { - this.check("122", CardUtil.getConvertedManaCost("0") == 0); - this.check("123", CardUtil.getConvertedManaCost("R") == 1); - this.check("124", CardUtil.getConvertedManaCost("R R") == 2); - this.check("125", CardUtil.getConvertedManaCost("R R R") == 3); - this.check("126", CardUtil.getConvertedManaCost("1") == 1); - this.check("127", CardUtil.getConvertedManaCost("2/R 2/G 2/W 2/B 2/U") == 10); - } - }// test() + this.check("122", CardUtil.getConvertedManaCost("0") == 0); + this.check("123", CardUtil.getConvertedManaCost("R") == 1); + this.check("124", CardUtil.getConvertedManaCost("R R") == 2); + this.check("125", CardUtil.getConvertedManaCost("R R R") == 3); + this.check("126", CardUtil.getConvertedManaCost("1") == 1); + this.check("127", CardUtil.getConvertedManaCost("2/R 2/G 2/W 2/B 2/U") == 10); + } // test() /** *

diff --git a/src/test/java/forge/card/cardFactory/CardFactoryUtilTest.java b/src/test/java/forge/card/cardFactory/CardFactoryUtilTest.java index 03eacf30734..50e43b31bf7 100644 --- a/src/test/java/forge/card/cardFactory/CardFactoryUtilTest.java +++ b/src/test/java/forge/card/cardFactory/CardFactoryUtilTest.java @@ -27,7 +27,7 @@ public class CardFactoryUtilTest { * Card factory test1. */ @Test(timeOut = 1000, enabled = false) - public void CardFactoryTest1() { + public void cardFactoryTest1() { Generator in = YieldUtils.toGenerator(AllZone.getCardFactory()); diff --git a/src/test/java/forge/card/mana/ManaPartTest.java b/src/test/java/forge/card/mana/ManaPartTest.java new file mode 100644 index 00000000000..fce4d809144 --- /dev/null +++ b/src/test/java/forge/card/mana/ManaPartTest.java @@ -0,0 +1,473 @@ +package forge.card.mana; + +import org.testng.annotations.Test; + +import forge.Card; +import forge.Constant; + +/** + *

+ * Mana_PartTest class. + *

+ * + * @author Forge + * @version $Id$ + */ +@Test(groups = { "UnitTest" }, timeOut = 1000) +public class ManaPartTest { + /** + *

+ * testPayManaCost. + *

+ */ + @Test(groups = { "UnitTest", "fast" }, timeOut = 5000) + public void testPayManaCost() { + // test constructor + @SuppressWarnings("unused") + ManaCost p = new ManaCost("G"); + p = new ManaCost("U"); + p = new ManaCost("W"); + p = new ManaCost("R"); + p = new ManaCost("B"); + p = new ManaCost("0"); + p = new ManaCost("1"); + p = new ManaCost("2"); + p = new ManaCost("3"); + p = new ManaCost("4"); + p = new ManaCost("5"); + p = new ManaCost("6"); + p = new ManaCost("7"); + p = new ManaCost("8"); + p = new ManaCost("9"); + p = new ManaCost("10"); + + p = new ManaCost("GW"); + p = new ManaCost("1 G"); + p = new ManaCost("1 GW"); + p = new ManaCost("GW GW"); + p = new ManaCost("GW GW GW"); + p = new ManaCost("GW GW GW GW"); + + p = new ManaCost("G G"); + p = new ManaCost("G G G"); + p = new ManaCost("G G G"); + p = new ManaCost("G G G G"); + + p = new ManaCost("2 GW GW GW"); + p = new ManaCost("3 G G G"); + p = new ManaCost("12 GW GW GW"); + p = new ManaCost("11 G G G"); + + p = new ManaCost("2/U"); + p = new ManaCost("2/B 2/B"); + p = new ManaCost("2/G 2/G 2/G"); + p = new ManaCost("2/R 2/R 2/R 2/R"); + p = new ManaCost("2/W 2/B 2/U 2/R 2/G"); + + final ManaCost p1 = new ManaCost("2/U"); + + this.check(0.3, p1.isNeeded("G")); + this.check(0.4, p1.isNeeded("U")); + this.check(0.5, p1.isNeeded("B")); + this.check(0.6, p1.isNeeded("W")); + this.check(0.7, p1.isNeeded("R")); + this.check(0.8, p1.isNeeded("1")); + + p1.addMana("U"); + this.check(0.9, p1.isPaid()); + + this.check(0.91, !p1.isNeeded("R")); + + final ManaCost p2 = new ManaCost("G"); + this.check(1, p2.isNeeded("G")); + + this.check(1.1, !p2.isNeeded("U")); + this.check(1.2, !p2.isNeeded("B")); + this.check(1.3, !p2.isNeeded("W")); + this.check(1.4, !p2.isNeeded("R")); + this.check(1.5, !p2.isNeeded("1")); + + p2.addMana("G"); + this.check(2, p2.isPaid()); + + this.check(2.1, !p2.isNeeded("G")); + + final ManaCost p4 = new ManaCost("1"); + + this.check(3, p4.isNeeded("G")); + this.check(4, p4.isNeeded("U")); + this.check(5, p4.isNeeded("B")); + this.check(6, p4.isNeeded("W")); + this.check(7, p4.isNeeded("R")); + this.check(8, p4.isNeeded("1")); + + p4.addMana("B"); + this.check(9, p4.isPaid()); + + this.check(9.1, !p4.isNeeded("R")); + + final ManaCost p5 = new ManaCost("GW"); + + this.check(10, p5.isNeeded("G")); + this.check(13, p5.isNeeded("W")); + + this.check(11, !p5.isNeeded("U")); + this.check(12, !p5.isNeeded("B")); + this.check(14, !p5.isNeeded("R")); + this.check(15, !p5.isNeeded("1")); + + p5.addMana("W"); + this.check(16, p5.isPaid()); + + this.check(17, !p5.isNeeded("W")); + + final ManaCost p6 = new ManaCost("BR"); + + this.check(17.1, p6.isNeeded("B")); + this.check(17.2, p6.isNeeded("R")); + + this.check(17.3, !p6.isNeeded("U")); + this.check(17.4, !p6.isNeeded("W")); + this.check(17.5, !p6.isNeeded("G")); + this.check(17.6, !p6.isNeeded("1")); + + p6.addMana("R"); + this.check(17.7, p6.isPaid()); + + this.check(17.8, !p6.isNeeded("R")); + + final ManaCost p7 = new ManaCost("1 G G"); + + p7.addMana("G"); + + this.check(18.1, p7.isNeeded("G")); + this.check(18.2, p7.isNeeded("W")); + this.check(18.3, p7.isNeeded("U")); + this.check(18.4, p7.isNeeded("B")); + this.check(18.5, p7.isNeeded("R")); + this.check(18.6, p7.isNeeded("1")); + + p7.addMana("1"); + p7.addMana("G"); + + this.check(18.7, p7.isPaid()); + + this.check(18.8, !p7.isNeeded("W")); + + final ManaCost p8 = new ManaCost("0"); + + this.check(19.1, !p8.isNeeded("1")); + this.check(19.2, !p8.isNeeded("G")); + this.check(19.3, !p8.isNeeded("U")); + + this.check(19.4, p8.isPaid()); + + this.check(19.5, !p8.isNeeded("R")); + + final ManaCost p9 = new ManaCost("G G"); + + this.check(20.1, !p9.isNeeded("1")); + this.check(20.2, p9.isNeeded("G")); + + this.check(20.3, !p9.isNeeded("U")); + + p9.addMana("G"); + p9.addMana("G"); + + this.check(20.4, p9.isPaid()); + + this.check(20.5, !p9.isNeeded("B")); + + final ManaCost p10 = new ManaCost("G G G"); + + this.check(21.1, !p10.isNeeded("W")); + this.check(21.2, p10.isNeeded("G")); + + this.check(21.3, !p10.isNeeded("R")); + + p10.addMana("G"); + p10.addMana("G"); + p10.addMana("G"); + + this.check(21.4, p10.isPaid()); + + this.check(21.5, !p10.isNeeded("U")); + + final ManaCost p11 = new ManaCost("G G G G"); + + this.check(22.1, !p11.isNeeded("W")); + this.check(22.2, p11.isNeeded("G")); + + this.check(22.3, !p11.isNeeded("R")); + + p11.addMana("G"); + p11.addMana("G"); + p11.addMana("G"); + p11.addMana("G"); + + this.check(22.4, p11.isPaid()); + + this.check(22.5, !p11.isNeeded("G")); + + final ManaCost p12 = new ManaCost("GW"); + + this.check(23.1, p12.isNeeded("W")); + this.check(23.2, p12.isNeeded("G")); + this.check(23.3, !p12.isNeeded("R")); + + p12.addMana("G"); + + this.check(23.4, p12.isPaid()); + + this.check(23.5, !p12.isNeeded("G")); + + final ManaCost p13 = new ManaCost("GW"); + + this.check(24.1, p13.isNeeded("W")); + this.check(24.2, p13.isNeeded("G")); + this.check(24.3, !p13.isNeeded("U")); + + p13.addMana("W"); + + this.check(24.4, p13.isPaid()); + + this.check(24.5, !p13.isNeeded("W")); + + final ManaCost p14 = new ManaCost("3 GW GW"); + + this.check(25.1, p14.isNeeded("W")); + this.check(25.2, p14.isNeeded("G")); + this.check(25.3, p14.isNeeded("U")); + + p14.addMana("1"); + p14.addMana("1"); + p14.addMana("1"); + + this.check(25.4, p14.isNeeded("W")); + this.check(25.5, p14.isNeeded("G")); + this.check(25.6, !p14.isNeeded("U")); + + p14.addMana("G"); + p14.addMana("W"); + + this.check(25.7, p14.isPaid()); + + this.check(25.8, !p14.isNeeded("W")); + this.check(25.9, !p14.isNeeded("G")); + this.check(25.10, !p14.isNeeded("1")); + this.check(25.11, !p14.isNeeded("R")); + + final ManaCost p15 = new ManaCost("4"); + + this.check(26.1, p15.isNeeded("W")); + this.check(26.2, p15.isNeeded("G")); + this.check(26.3, p15.isNeeded("U")); + + p15.addMana("1"); + p15.addMana("1"); + p15.addMana("1"); + p15.addMana("1"); + + this.check(26.4, p15.isPaid()); + + final ManaCost p16 = new ManaCost("10"); + + p16.addMana("G"); + p16.addMana("W"); + p16.addMana("R"); + p16.addMana("U"); + p16.addMana("B"); + + p16.addMana("1"); + + p16.addMana("W"); + p16.addMana("R"); + p16.addMana("U"); + p16.addMana("B"); + + this.check(27, p16.isPaid()); + + final ManaCost p17 = new ManaCost("12 G GW"); + + for (int i = 0; i < 12; i++) { + p17.addMana("R"); + } + + p17.addMana("G"); + p17.addMana("W"); + + this.check(28, p17.isPaid()); + + final ManaCost p18 = new ManaCost("2 W B U R G"); + + for (int i = 0; i < 1; i++) { + p18.addMana("R"); + } + + for (int i = 0; i < 2; i++) { + p18.addMana("1"); + } + + for (int i = 0; i < 1; i++) { + p18.addMana("G"); + p18.addMana("W"); + p18.addMana("B"); + p18.addMana("U"); + + } + this.check(29, p18.isPaid()); + + final ManaCost p19 = new ManaCost("W B U R G W"); + + p19.addMana("R"); + p19.addMana("G"); + p19.addMana("B"); + p19.addMana("U"); + + p19.addMana("W"); + p19.addMana("W"); + + this.check(30, p19.isPaid()); + + final ManaCost p20 = new ManaCost("W B U R G W B U R G"); + + for (int i = 0; i < 2; i++) { + p20.addMana("W"); + p20.addMana("R"); + p20.addMana("G"); + p20.addMana("B"); + p20.addMana("U"); + } + + this.check(31, p20.isPaid()); + + final ManaCost p21 = new ManaCost("2 W B U R G W B U R G G"); + + for (int i = 0; i < 2; i++) { + p21.addMana("W"); + p21.addMana("R"); + p21.addMana("G"); + p21.addMana("B"); + p21.addMana("U"); + } + + p21.addMana("1"); + p21.addMana("1"); + p21.addMana("G"); + + this.check(32, p21.isPaid()); + + final ManaCost p22 = new ManaCost("1 B R"); + + p22.addMana("B"); + p22.addMana("1"); + p22.addMana("R"); + + this.check(33, p22.isPaid()); + + final ManaCost p23 = new ManaCost("B R"); + + p23.addMana("B"); + p23.addMana("R"); + + this.check(34, p23.isPaid()); + + final ManaCost p24 = new ManaCost("2/B 2/B 2/B"); + + this.check(35, p24.isNeeded("G")); + + p24.addMana("B"); + this.check(36, p24.toString().equals("2/B 2/B")); + + p24.addMana("B"); + this.check(37, p24.toString().equals("2/B")); + + p24.addMana("B"); + this.check(38, p24.isPaid()); + + final ManaCost p25 = new ManaCost("2/G"); + + p25.addMana("1"); + this.check(39, p25.toString().equals("1")); + + p25.addMana("W"); + this.check(40, p25.isPaid()); + + final ManaCost p27 = new ManaCost("2/R 2/R"); + + p27.addMana("1"); + this.check(41, p27.toString().equals("2/R 1")); + + p27.addMana("W"); + this.check(42, p27.toString().equals("2/R")); + + final ManaCost p26 = new ManaCost("2/W 2/W"); + + for (int i = 0; i < 4; i++) { + this.check(43, !p26.isPaid()); + p26.addMana("1"); + } + + this.check(44, p26.isPaid()); + + final ManaCost p28 = new ManaCost("2/W 2/B 2/U 2/R 2/G"); + this.check(45, !p28.isPaid()); + + p28.addMana("B"); + p28.addMana("R"); + p28.addMana("G"); + p28.addMana("W"); + p28.addMana("U"); + + this.check(45.1, p28.isPaid(), p28); + + final ManaCost p29 = new ManaCost("2/W 2/B 2/U 2/R 2/G"); + this.check(46, !p29.isPaid()); + + final Card c = new Card(); + + p29.addMana(new Mana(Constant.Color.BLACK, 1, c)); + p29.addMana(new Mana(Constant.Color.RED, 1, c)); + p29.addMana(new Mana(Constant.Color.GREEN, 1, c)); + p29.addMana(new Mana(Constant.Color.WHITE, 1, c)); + p29.addMana(new Mana(Constant.Color.BLUE, 1, c)); + + this.check(46.1, p29.isPaid(), p29); + + } // testPayManaCost() + + /** + *

+ * check. + *

+ * + * @param n + * a double. + * @param b + * a boolean. + */ + void check(final double n, final boolean b) { + if (!b) { + System.out.println("failed : " + n); + } + } + + /** + *

+ * check. + *

+ * + * @param n + * a double. + * @param b + * a boolean. + * @param p + * a {@link forge.card.mana.ManaCost} object. + */ + void check(final double n, final boolean b, final ManaCost p) { + if (!b) { + System.out.println("failed : " + n); + System.out.println(p.toString()); + } + } +} diff --git a/src/test/java/forge/card/mana/Mana_PartTest.java b/src/test/java/forge/card/mana/Mana_PartTest.java deleted file mode 100644 index 929ab02c4f7..00000000000 --- a/src/test/java/forge/card/mana/Mana_PartTest.java +++ /dev/null @@ -1,521 +0,0 @@ -package forge.card.mana; - -import forge.Card; -import forge.Constant; -import org.testng.annotations.Test; - -/** - *

Mana_PartTest class.

- * - * @author Forge - * @version $Id$ - */ -@Test(groups = {"UnitTest"}, timeOut = 1000) -public class Mana_PartTest { - /** - *

testPayManaCost.

- */ - @Test(groups = {"UnitTest", "fast"}, timeOut = 5000) - public void testPayManaCost() { - { - //test constructor - @SuppressWarnings("unused") - ManaCost p = new ManaCost("G"); - p = new ManaCost("U"); - p = new ManaCost("W"); - p = new ManaCost("R"); - p = new ManaCost("B"); - p = new ManaCost("0"); - p = new ManaCost("1"); - p = new ManaCost("2"); - p = new ManaCost("3"); - p = new ManaCost("4"); - p = new ManaCost("5"); - p = new ManaCost("6"); - p = new ManaCost("7"); - p = new ManaCost("8"); - p = new ManaCost("9"); - p = new ManaCost("10"); - - p = new ManaCost("GW"); - p = new ManaCost("1 G"); - p = new ManaCost("1 GW"); - p = new ManaCost("GW GW"); - p = new ManaCost("GW GW GW"); - p = new ManaCost("GW GW GW GW"); - - p = new ManaCost("G G"); - p = new ManaCost("G G G"); - p = new ManaCost("G G G"); - p = new ManaCost("G G G G"); - - p = new ManaCost("2 GW GW GW"); - p = new ManaCost("3 G G G"); - p = new ManaCost("12 GW GW GW"); - p = new ManaCost("11 G G G"); - - p = new ManaCost("2/U"); - p = new ManaCost("2/B 2/B"); - p = new ManaCost("2/G 2/G 2/G"); - p = new ManaCost("2/R 2/R 2/R 2/R"); - p = new ManaCost("2/W 2/B 2/U 2/R 2/G"); - } - - { - ManaCost p = new ManaCost("2/U"); - - check(0.3, p.isNeeded("G")); - check(0.4, p.isNeeded("U")); - check(0.5, p.isNeeded("B")); - check(0.6, p.isNeeded("W")); - check(0.7, p.isNeeded("R")); - check(0.8, p.isNeeded("1")); - - p.addMana("U"); - check(0.9, p.isPaid()); - - check(0.91, !p.isNeeded("R")); - } - - - { - ManaCost p = new ManaCost("G"); - check(1, p.isNeeded("G")); - - check(1.1, !p.isNeeded("U")); - check(1.2, !p.isNeeded("B")); - check(1.3, !p.isNeeded("W")); - check(1.4, !p.isNeeded("R")); - check(1.5, !p.isNeeded("1")); - - p.addMana("G"); - check(2, p.isPaid()); - - check(2.1, !p.isNeeded("G")); - - } - - { - ManaCost p = new ManaCost("1"); - - check(3, p.isNeeded("G")); - check(4, p.isNeeded("U")); - check(5, p.isNeeded("B")); - check(6, p.isNeeded("W")); - check(7, p.isNeeded("R")); - check(8, p.isNeeded("1")); - - p.addMana("B"); - check(9, p.isPaid()); - - check(9.1, !p.isNeeded("R")); - } - - { - ManaCost p = new ManaCost("GW"); - - check(10, p.isNeeded("G")); - check(13, p.isNeeded("W")); - - check(11, !p.isNeeded("U")); - check(12, !p.isNeeded("B")); - check(14, !p.isNeeded("R")); - check(15, !p.isNeeded("1")); - - p.addMana("W"); - check(16, p.isPaid()); - - check(17, !p.isNeeded("W")); - } - - - { - ManaCost p = new ManaCost("BR"); - - check(17.1, p.isNeeded("B")); - check(17.2, p.isNeeded("R")); - - check(17.3, !p.isNeeded("U")); - check(17.4, !p.isNeeded("W")); - check(17.5, !p.isNeeded("G")); - check(17.6, !p.isNeeded("1")); - - p.addMana("R"); - check(17.7, p.isPaid()); - - check(17.8, !p.isNeeded("R")); - } - - - { - ManaCost p = new ManaCost("1 G G"); - - p.addMana("G"); - - check(18.1, p.isNeeded("G")); - check(18.2, p.isNeeded("W")); - check(18.3, p.isNeeded("U")); - check(18.4, p.isNeeded("B")); - check(18.5, p.isNeeded("R")); - check(18.6, p.isNeeded("1")); - - p.addMana("1"); - p.addMana("G"); - - check(18.7, p.isPaid()); - - check(18.8, !p.isNeeded("W")); - } - - { - ManaCost p = new ManaCost("0"); - - check(19.1, !p.isNeeded("1")); - check(19.2, !p.isNeeded("G")); - check(19.3, !p.isNeeded("U")); - - check(19.4, p.isPaid()); - - check(19.5, !p.isNeeded("R")); - } - - { - ManaCost p = new ManaCost("G G"); - - check(20.1, !p.isNeeded("1")); - check(20.2, p.isNeeded("G")); - - check(20.3, !p.isNeeded("U")); - - p.addMana("G"); - p.addMana("G"); - - check(20.4, p.isPaid()); - - check(20.5, !p.isNeeded("B")); - } - - { - ManaCost p = new ManaCost("G G G"); - - check(21.1, !p.isNeeded("W")); - check(21.2, p.isNeeded("G")); - - check(21.3, !p.isNeeded("R")); - - p.addMana("G"); - p.addMana("G"); - p.addMana("G"); - - check(21.4, p.isPaid()); - - check(21.5, !p.isNeeded("U")); - } - - { - ManaCost p = new ManaCost("G G G G"); - - check(22.1, !p.isNeeded("W")); - check(22.2, p.isNeeded("G")); - - check(22.3, !p.isNeeded("R")); - - p.addMana("G"); - p.addMana("G"); - p.addMana("G"); - p.addMana("G"); - - check(22.4, p.isPaid()); - - check(22.5, !p.isNeeded("G")); - } - - { - ManaCost p = new ManaCost("GW"); - - check(23.1, p.isNeeded("W")); - check(23.2, p.isNeeded("G")); - check(23.3, !p.isNeeded("R")); - - p.addMana("G"); - - check(23.4, p.isPaid()); - - check(23.5, !p.isNeeded("G")); - } - - { - ManaCost p = new ManaCost("GW"); - - check(24.1, p.isNeeded("W")); - check(24.2, p.isNeeded("G")); - check(24.3, !p.isNeeded("U")); - - p.addMana("W"); - - check(24.4, p.isPaid()); - - check(24.5, !p.isNeeded("W")); - } - - { - ManaCost p = new ManaCost("3 GW GW"); - - check(25.1, p.isNeeded("W")); - check(25.2, p.isNeeded("G")); - check(25.3, p.isNeeded("U")); - - p.addMana("1"); - p.addMana("1"); - p.addMana("1"); - - check(25.4, p.isNeeded("W")); - check(25.5, p.isNeeded("G")); - check(25.6, !p.isNeeded("U")); - - p.addMana("G"); - p.addMana("W"); - - check(25.7, p.isPaid()); - - check(25.8, !p.isNeeded("W")); - check(25.9, !p.isNeeded("G")); - check(25.10, !p.isNeeded("1")); - check(25.11, !p.isNeeded("R")); - } - - { - ManaCost p = new ManaCost("4"); - - check(26.1, p.isNeeded("W")); - check(26.2, p.isNeeded("G")); - check(26.3, p.isNeeded("U")); - - p.addMana("1"); - p.addMana("1"); - p.addMana("1"); - p.addMana("1"); - - check(26.4, p.isPaid()); - } - - { - ManaCost p = new ManaCost("10"); - - p.addMana("G"); - p.addMana("W"); - p.addMana("R"); - p.addMana("U"); - p.addMana("B"); - - p.addMana("1"); - - p.addMana("W"); - p.addMana("R"); - p.addMana("U"); - p.addMana("B"); - - check(27, p.isPaid()); - } - - { - ManaCost p = new ManaCost("12 G GW"); - - for (int i = 0; i < 12; i++) - p.addMana("R"); - - p.addMana("G"); - p.addMana("W"); - - check(28, p.isPaid()); - } - - { - ManaCost p = new ManaCost("2 W B U R G"); - - for (int i = 0; i < 1; i++) - p.addMana("R"); - - for (int i = 0; i < 2; i++) - p.addMana("1"); - - for (int i = 0; i < 1; i++) { - p.addMana("G"); - p.addMana("W"); - p.addMana("B"); - p.addMana("U"); - - } - check(29, p.isPaid()); - } - - { - ManaCost p = new ManaCost("W B U R G W"); - - p.addMana("R"); - p.addMana("G"); - p.addMana("B"); - p.addMana("U"); - - p.addMana("W"); - p.addMana("W"); - - check(30, p.isPaid()); - } - - { - ManaCost p = new ManaCost("W B U R G W B U R G"); - - for (int i = 0; i < 2; i++) { - p.addMana("W"); - p.addMana("R"); - p.addMana("G"); - p.addMana("B"); - p.addMana("U"); - } - - check(31, p.isPaid()); - } - - { - ManaCost p = new ManaCost("2 W B U R G W B U R G G"); - - for (int i = 0; i < 2; i++) { - p.addMana("W"); - p.addMana("R"); - p.addMana("G"); - p.addMana("B"); - p.addMana("U"); - } - - p.addMana("1"); - p.addMana("1"); - p.addMana("G"); - - check(32, p.isPaid()); - } - - { - ManaCost p = new ManaCost("1 B R"); - - p.addMana("B"); - p.addMana("1"); - p.addMana("R"); - - check(33, p.isPaid()); - } - - { - ManaCost p = new ManaCost("B R"); - - p.addMana("B"); - p.addMana("R"); - - check(34, p.isPaid()); - } - - - { - ManaCost p = new ManaCost("2/B 2/B 2/B"); - - check(35, p.isNeeded("G")); - - p.addMana("B"); - check(36, p.toString().equals("2/B 2/B")); - - p.addMana("B"); - check(37, p.toString().equals("2/B")); - - p.addMana("B"); - check(38, p.isPaid()); - } - - - { - ManaCost p = new ManaCost("2/G"); - - p.addMana("1"); - check(39, p.toString().equals("1")); - - p.addMana("W"); - check(40, p.isPaid()); - } - - { - ManaCost p = new ManaCost("2/R 2/R"); - - p.addMana("1"); - check(41, p.toString().equals("2/R 1")); - - p.addMana("W"); - check(42, p.toString().equals("2/R")); - } - - { - ManaCost p = new ManaCost("2/W 2/W"); - - for (int i = 0; i < 4; i++) { - check(43, p.isPaid() == false); - p.addMana("1"); - } - - check(44, p.isPaid()); - } - - { - ManaCost p = new ManaCost("2/W 2/B 2/U 2/R 2/G"); - check(45, p.isPaid() == false); - - p.addMana("B"); - p.addMana("R"); - p.addMana("G"); - p.addMana("W"); - p.addMana("U"); - - check(45.1, p.isPaid(), p); - } - - { - ManaCost p = new ManaCost("2/W 2/B 2/U 2/R 2/G"); - check(46, p.isPaid() == false); - - Card c = new Card(); - - p.addMana(new Mana(Constant.Color.BLACK, 1, c)); - p.addMana(new Mana(Constant.Color.RED, 1, c)); - p.addMana(new Mana(Constant.Color.GREEN, 1, c)); - p.addMana(new Mana(Constant.Color.WHITE, 1, c)); - p.addMana(new Mana(Constant.Color.BLUE, 1, c)); - - check(46.1, p.isPaid(), p); - } - - } //testPayManaCost() - - - /** - *

check.

- * - * @param n a double. - * @param b a boolean. - */ - void check(double n, boolean b) { - if (!b) { - System.out.println("failed : " + n); - } - } - - /** - *

check.

- * - * @param n a double. - * @param b a boolean. - * @param p a {@link forge.card.mana.ManaCost} object. - */ - void check(double n, boolean b, ManaCost p) { - if (!b) { - System.out.println("failed : " + n); - System.out.println(p.toString()); - } - } -} diff --git a/src/test/java/forge/deck/generate/Generate2ColorDeckTest.java b/src/test/java/forge/deck/generate/Generate2ColorDeckTest.java index 94b1e54db96..50acf0cab0b 100644 --- a/src/test/java/forge/deck/generate/Generate2ColorDeckTest.java +++ b/src/test/java/forge/deck/generate/Generate2ColorDeckTest.java @@ -1,24 +1,23 @@ package forge.deck.generate; -import forge.CardList; import org.testng.Assert; import org.testng.annotations.Test; +import forge.CardList; + /** - * Created by IntelliJ IDEA. - * User: dhudson + * Created by IntelliJ IDEA. User: dhudson */ -@Test(groups = {"UnitTest"}, enabled = false) +@Test(groups = { "UnitTest" }, enabled = false) public class Generate2ColorDeckTest { - /** - * + * Generate2 color deck test1. */ @Test(enabled = false) - public void Generate2ColorDeckTest1() { - Generate2ColorDeck gen = new Generate2ColorDeck("white", "blue"); - CardList cardList = gen.get2ColorDeck(60, null); + public void generate2ColorDeckTest1() { + final Generate2ColorDeck gen = new Generate2ColorDeck("white", "blue"); + final CardList cardList = gen.get2ColorDeck(60, null); Assert.assertNotNull(cardList); } } diff --git a/src/test/java/forge/deck/generate/Generate3ColorDeckTest.java b/src/test/java/forge/deck/generate/Generate3ColorDeckTest.java index 931ddb3f52b..d57e64ab2ca 100644 --- a/src/test/java/forge/deck/generate/Generate3ColorDeckTest.java +++ b/src/test/java/forge/deck/generate/Generate3ColorDeckTest.java @@ -1,25 +1,23 @@ package forge.deck.generate; -import forge.CardList; - import org.testng.Assert; import org.testng.annotations.Test; +import forge.CardList; + /** - * Created by IntelliJ IDEA. - * User: dhudson + * Created by IntelliJ IDEA. User: dhudson */ -@Test(groups = {"UnitTest"}, timeOut = 1000, enabled = false) +@Test(groups = { "UnitTest" }, timeOut = 1000, enabled = false) public class Generate3ColorDeckTest { - /** - * + * Generate3 color deck test1. */ @Test(timeOut = 1000, enabled = false) - public void Generate3ColorDeckTest1() { - Generate3ColorDeck gen = new Generate3ColorDeck("white", "blue", "black"); - CardList cardList = gen.get3ColorDeck(60, null); + public void generate3ColorDeckTest1() { + final Generate3ColorDeck gen = new Generate3ColorDeck("white", "blue", "black"); + final CardList cardList = gen.get3ColorDeck(60, null); Assert.assertNotNull(cardList); } } diff --git a/src/test/java/forge/deck/generate/Generate5ColorDeckTest.java b/src/test/java/forge/deck/generate/Generate5ColorDeckTest.java index a9b464247c2..dcd03838e44 100644 --- a/src/test/java/forge/deck/generate/Generate5ColorDeckTest.java +++ b/src/test/java/forge/deck/generate/Generate5ColorDeckTest.java @@ -1,25 +1,23 @@ package forge.deck.generate; -import forge.CardList; - import org.testng.Assert; import org.testng.annotations.Test; +import forge.CardList; + /** - * Created by IntelliJ IDEA. - * User: dhudson + * Created by IntelliJ IDEA. User: dhudson */ -@Test(groups = {"UnitTest"}, timeOut = 1000, enabled = false) +@Test(groups = { "UnitTest" }, timeOut = 1000, enabled = false) public class Generate5ColorDeckTest { - /** - * + * Generate5 color deck test1. */ @Test(timeOut = 1000, enabled = false) - public void Generate5ColorDeckTest1() { - Generate5ColorDeck gen = new Generate5ColorDeck(); - CardList cardList = gen.get5ColorDeck(60, null); + public void generate5ColorDeckTest1() { + final Generate5ColorDeck gen = new Generate5ColorDeck(); + final CardList cardList = gen.get5ColorDeck(60, null); Assert.assertNotNull(cardList); } } diff --git a/src/test/java/forge/deck/generate/GenerateConstructedDeckTest.java b/src/test/java/forge/deck/generate/GenerateConstructedDeckTest.java index 455478b574c..a1139ba8232 100644 --- a/src/test/java/forge/deck/generate/GenerateConstructedDeckTest.java +++ b/src/test/java/forge/deck/generate/GenerateConstructedDeckTest.java @@ -1,28 +1,27 @@ package forge.deck.generate; -import forge.CardList; import org.testng.annotations.Test; +import forge.CardList; + /** - * Created by IntelliJ IDEA. - * User: dhudson + * Created by IntelliJ IDEA. User: dhudson */ -@Test(groups = {"UnitTest"}, timeOut = 1000) +@Test(groups = { "UnitTest" }, timeOut = 1000) public class GenerateConstructedDeckTest { - /** - * + * Generate constructed deck test1. */ @Test(enabled = false, timeOut = 1000) - public void GenerateConstructedDeckTest1() { - GenerateConstructedDeck g = new GenerateConstructedDeck(); + public void generateConstructedDeckTest1() { + final GenerateConstructedDeck g = new GenerateConstructedDeck(); for (int i = 0; i < 50; i++) { - CardList c = g.generateDeck(); + final CardList c = g.generateDeck(); System.out.println(c.getType("Creature").size() + " - " + c.size()); } System.exit(1); - }//main + } // main } diff --git a/src/test/java/forge/deck/generate/GenerateConstructedMultiColorDeckTest.java b/src/test/java/forge/deck/generate/GenerateConstructedMultiColorDeckTest.java index 84ee05d21da..b2ae8fd6a3f 100644 --- a/src/test/java/forge/deck/generate/GenerateConstructedMultiColorDeckTest.java +++ b/src/test/java/forge/deck/generate/GenerateConstructedMultiColorDeckTest.java @@ -1,26 +1,25 @@ package forge.deck.generate; -import forge.CardList; import org.testng.annotations.Test; +import forge.CardList; + /** - * Created by IntelliJ IDEA. - * User: dhudson + * Created by IntelliJ IDEA. User: dhudson */ -@Test(groups = {"UnitTest"}, timeOut = 1000, enabled = false) +@Test(groups = { "UnitTest" }, timeOut = 1000, enabled = false) public class GenerateConstructedMultiColorDeckTest { - /** - * + * Generate constructed multi color deck test1. */ @Test(enabled = false, timeOut = 1000) - public void GenerateConstructedMultiColorDeckTest1() { - GenerateConstructedMultiColorDeck g = new GenerateConstructedMultiColorDeck(); + public void generateConstructedMultiColorDeckTest1() { + final GenerateConstructedMultiColorDeck g = new GenerateConstructedMultiColorDeck(); for (int i = 0; i < 10; i++) { System.out.println("***GENERATING DECK***"); - CardList c = g.generate3ColorDeck(); + final CardList c = g.generate3ColorDeck(); System.out.println(c.getType("Creature").size() + " - " + c.size()); for (int j = 0; j < c.size(); j++) { System.out.println(c.get(j).getName()); @@ -29,6 +28,5 @@ public class GenerateConstructedMultiColorDeckTest { } System.exit(1); - }//main + } // main } - diff --git a/src/test/java/forge/gui/ListChooserTest.java b/src/test/java/forge/gui/ListChooserTest.java index b2e69ae3bae..c8c13fbac7d 100644 --- a/src/test/java/forge/gui/ListChooserTest.java +++ b/src/test/java/forge/gui/ListChooserTest.java @@ -3,20 +3,19 @@ package forge.gui; import org.testng.annotations.Test; /** - * Created by IntelliJ IDEA. - * User: dhudson + * Created by IntelliJ IDEA. User: dhudson */ -@Test(groups = {"UnitTest"}, timeOut = 1000, enabled = false) +@Test(groups = { "UnitTest" }, timeOut = 1000, enabled = false) public class ListChooserTest { + /** - * - * + * List chooser test1. */ - @Test(groups = {"UnitTest", "fast"}, timeOut = 1000) - public void ListChooserTest1() { - ListChooser c = new ListChooser("test", "choose a or b", 0, 2, "a", "b"); + @Test(groups = { "UnitTest", "fast" }, timeOut = 1000) + public void listChooserTest1() { + final ListChooser c = new ListChooser("test", "choose a or b", 0, 2, "a", "b"); System.out.println(c.show()); - for (String s : c.getSelectedValues()) { + for (final String s : c.getSelectedValues()) { System.out.println(s); } } diff --git a/src/test/java/forge/gui/game/CardDetailPanelTest.java b/src/test/java/forge/gui/game/CardDetailPanelTest.java index f93f1658a6b..fdd3d4f57b3 100644 --- a/src/test/java/forge/gui/game/CardDetailPanelTest.java +++ b/src/test/java/forge/gui/game/CardDetailPanelTest.java @@ -4,24 +4,23 @@ import org.testng.Assert; import org.testng.annotations.Test; /** - * Created by IntelliJ IDEA. - * User: dhudson + * Created by IntelliJ IDEA. User: dhudson */ -@Test(groups = {"UnitTest"}) +@Test(groups = { "UnitTest" }) public class CardDetailPanelTest { + /** - * - * + * Card detail panel test1. */ - @Test(groups = {"UnitTest", "fast"}) + @Test(groups = { "UnitTest", "fast" }) public void cardDetailPanelTest1() { try { CardDetailPanel dialog = new CardDetailPanel(null); - //dialog.setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE); + // dialog.setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE); dialog.setVisible(true); Assert.assertNotNull(dialog); dialog = null; - } catch (Exception e) { + } catch (final Exception e) { e.printStackTrace(); } } diff --git a/src/test/java/forge/model/BuildInfoTest.java b/src/test/java/forge/model/BuildInfoTest.java index a829e822a19..21d6d12fb0b 100644 --- a/src/test/java/forge/model/BuildInfoTest.java +++ b/src/test/java/forge/model/BuildInfoTest.java @@ -1,9 +1,5 @@ package forge.model; -import static net.slightlymagic.braids.util.testng.BraidsAssertFunctions.assertThrowsException; -import static org.testng.Assert.assertEquals; -import static org.testng.Assert.assertTrue; - import java.io.File; import java.io.FileOutputStream; import java.io.IOException; @@ -11,7 +7,9 @@ import java.util.zip.ZipEntry; import java.util.zip.ZipOutputStream; import net.slightlymagic.braids.util.ClumsyRunnable; +import net.slightlymagic.braids.util.testng.BraidsAssertFunctions; +import org.testng.Assert; import org.testng.annotations.Test; /** @@ -22,119 +20,149 @@ public class BuildInfoTest { /** System property name for the class path. */ private static final String JAVA_CLASS_PATH = "java.class.path"; /** Manifest attribute name for the Build ID. */ - private static final String MF_ATTR_NAME_BUILD = "Implementation-Build"; // NOPMD by Braids on 8/12/11 10:29 AM + private static final String MF_ATTR_NAME_BUILD = "Implementation-Build"; // NOPMD + // by + // Braids + // on + // 8/12/11 + // 10:29 + // AM /** Manifest attribute name for the version string. */ - private static final String MF_ATTR_NAME_VERSION = "Implementation-Version"; // NOPMD by Braids on 8/12/11 10:29 AM + private static final String MF_ATTR_NAME_VERSION = "Implementation-Version"; // NOPMD + // by + // Braids + // on + // 8/12/11 + // 10:29 + // AM /** * Test BuildInfo using a mock jar file. - * @throws IOException rarely + * + * @throws IOException + * rarely */ @Test - public final void test_BuildInfo_mockJar() throws IOException { // NOPMD by Braids on 8/12/11 10:26 AM + public final void test_BuildInfo_mockJar() throws IOException { // NOPMD by + // Braids on + // 8/12/11 + // 10:26 AM File jarAsFile = null; try { - jarAsFile = makeTmpJarWithManifest("BuildInfoTest-", ".jar", - new String[] {MF_ATTR_NAME_VERSION, "1.2.42", MF_ATTR_NAME_BUILD, "4200"}); + jarAsFile = this.makeTmpJarWithManifest("BuildInfoTest-", ".jar", new String[] { + BuildInfoTest.MF_ATTR_NAME_VERSION, "1.2.42", BuildInfoTest.MF_ATTR_NAME_BUILD, "4200" }); final BuildInfo info = new BuildInfo(jarAsFile.getAbsolutePath()); final String actualVersion = info.getVersion(); - assertEquals(actualVersion, "1.2.42", "versions match"); + Assert.assertEquals(actualVersion, "1.2.42", "versions match"); final String actualBuildID = info.getBuildID(); - assertEquals(actualBuildID, "4200", "build IDs match"); + Assert.assertEquals(actualBuildID, "4200", "build IDs match"); } finally { - assertTrue(jarAsFile.delete(), "attempting to delete temporary jar file"); + Assert.assertTrue(jarAsFile.delete(), "attempting to delete temporary jar file"); } } /** * Test BuildInfo with one mock forge jar placed in the class path. - * @throws IOException indirectly + * + * @throws IOException + * indirectly */ @Test - public final void test_BuildInfo_oneJarInCP() throws IOException { // NOPMD by Braids on 8/12/11 10:26 AM - final String origClassPath = System.getProperty(JAVA_CLASS_PATH); + public final void test_BuildInfo_oneJarInCP() throws IOException { // NOPMD + // by + // Braids + // on + // 8/12/11 + // 10:26 + // AM + final String origClassPath = System.getProperty(BuildInfoTest.JAVA_CLASS_PATH); File jarAsFile = null; try { - jarAsFile = makeTmpJarWithManifest("forge-BuildInfoTest-", "-with-dependencies.jar", - new String[] {MF_ATTR_NAME_VERSION, "1.2.43", MF_ATTR_NAME_BUILD, "4201"}); + jarAsFile = this.makeTmpJarWithManifest("forge-BuildInfoTest-", "-with-dependencies.jar", new String[] { + BuildInfoTest.MF_ATTR_NAME_VERSION, "1.2.43", BuildInfoTest.MF_ATTR_NAME_BUILD, "4201" }); - System.setProperty(JAVA_CLASS_PATH, + System.setProperty(BuildInfoTest.JAVA_CLASS_PATH, jarAsFile.getAbsolutePath() + System.getProperty("path.separator") + origClassPath); - final BuildInfo info = new BuildInfo(); final String actualVersion = info.getVersion(); - assertEquals(actualVersion, "1.2.43", "versions match"); + Assert.assertEquals(actualVersion, "1.2.43", "versions match"); final String actualBuildID = info.getBuildID(); - assertEquals(actualBuildID, "4201", "build IDs match"); + Assert.assertEquals(actualBuildID, "4201", "build IDs match"); } finally { - assertTrue(jarAsFile.delete(), "attempting to delete temporary jar file"); - System.setProperty(JAVA_CLASS_PATH, origClassPath); + Assert.assertTrue(jarAsFile.delete(), "attempting to delete temporary jar file"); + System.setProperty(BuildInfoTest.JAVA_CLASS_PATH, origClassPath); } } /** - * Test BuildInfo with two mock forge jars placed in the class path; this - * is an error condition. - * - * @throws IOException indirectly + * Test BuildInfo with two mock forge jars placed in the class path; this is + * an error condition. + * + * @throws IOException + * indirectly */ @Test - public final void test_BuildInfo_twoJarsInCP() throws IOException { // NOPMD by Braids on 8/12/11 10:26 AM - final String origClassPath = System.getProperty(JAVA_CLASS_PATH); + public final void test_BuildInfo_twoJarsInCP() throws IOException { // NOPMD + // by + // Braids + // on + // 8/12/11 + // 10:26 + // AM + final String origClassPath = System.getProperty(BuildInfoTest.JAVA_CLASS_PATH); File jarAsFile1 = null; File jarAsFile2 = null; try { - jarAsFile1 = makeTmpJarWithManifest("forge-BuildInfoTest-1-", "-with-dependencies.jar", - new String[] {MF_ATTR_NAME_VERSION, "1.1.1", MF_ATTR_NAME_BUILD, "1111"}); + jarAsFile1 = this.makeTmpJarWithManifest("forge-BuildInfoTest-1-", "-with-dependencies.jar", new String[] { + BuildInfoTest.MF_ATTR_NAME_VERSION, "1.1.1", BuildInfoTest.MF_ATTR_NAME_BUILD, "1111" }); - jarAsFile2 = makeTmpJarWithManifest("forge-BuildInfoTest-2-", "-with-dependencies.jar", - new String[] {MF_ATTR_NAME_VERSION, "2.2.2", MF_ATTR_NAME_BUILD, "2222"}); + jarAsFile2 = this.makeTmpJarWithManifest("forge-BuildInfoTest-2-", "-with-dependencies.jar", new String[] { + BuildInfoTest.MF_ATTR_NAME_VERSION, "2.2.2", BuildInfoTest.MF_ATTR_NAME_BUILD, "2222" }); final String pathSep = System.getProperty("path.separator"); - System.setProperty(JAVA_CLASS_PATH, - jarAsFile1.getAbsolutePath() + pathSep - + jarAsFile2.getAbsolutePath() + pathSep - + origClassPath); + System.setProperty(BuildInfoTest.JAVA_CLASS_PATH, + jarAsFile1.getAbsolutePath() + pathSep + jarAsFile2.getAbsolutePath() + pathSep + origClassPath); final BuildInfo info = new BuildInfo(); - assertThrowsException(MultipleForgeJarsFoundError.class, - new ClumsyRunnable() { - public void run() throws Exception { // NOPMD by Braids on 8/12/11 10:29 AM - info.getBuildID(); - } - }); + BraidsAssertFunctions.assertThrowsException(MultipleForgeJarsFoundError.class, new ClumsyRunnable() { + @Override + public void run() throws Exception { // NOPMD by Braids on + // 8/12/11 10:29 AM + info.getBuildID(); + } + }); } finally { - assertTrue(jarAsFile1.delete(), "attempting to delete 1st temporary jar"); - assertTrue(jarAsFile2.delete(), "attempting to delete 2nd temporary jar"); - System.setProperty(JAVA_CLASS_PATH, origClassPath); + Assert.assertTrue(jarAsFile1.delete(), "attempting to delete 1st temporary jar"); + Assert.assertTrue(jarAsFile2.delete(), "attempting to delete 2nd temporary jar"); + System.setProperty(BuildInfoTest.JAVA_CLASS_PATH, origClassPath); } } - /** * Helper method to create jar files at specific locations with specific * name-value pairs in their manifests. - * - * @param jarLocation where to create the jar file - * @param nameValuePairs has the form {"name1", "value1", "name2", "value2", ...} + * + * @param jarLocation + * where to create the jar file + * @param nameValuePairs + * has the form {"name1", "value1", "name2", "value2", ...} */ private File makeTmpJarWithManifest(final String fileNamePrefix, final String fileNameSuffix, - final String[] nameValuePairs) - throws IOException { - if (nameValuePairs.length % 2 != 0) { + final String[] nameValuePairs) throws IOException { + if ((nameValuePairs.length % 2) != 0) { throw new IllegalArgumentException("nameValuePairs must contain an even number of elements."); } @@ -149,16 +177,16 @@ public class BuildInfoTest { final ZipEntry zipEntry = new ZipEntry("META-INF/MANIFEST.MF"); zipOut.putNextEntry(zipEntry); - zipOut.write(toASCII("Manifest-Version: 1.3\n")); + zipOut.write(this.toASCII("Manifest-Version: 1.3\n")); for (int ix = 0; ix < nameValuePairs.length; ix += 2) { - zipOut.write(toASCII(nameValuePairs[ix])); - zipOut.write(toASCII(": ")); - zipOut.write(toASCII(nameValuePairs[ix + 1])); - zipOut.write(toASCII("\n")); + zipOut.write(this.toASCII(nameValuePairs[ix])); + zipOut.write(this.toASCII(": ")); + zipOut.write(this.toASCII(nameValuePairs[ix + 1])); + zipOut.write(this.toASCII("\n")); } - zipOut.write(toASCII("\n")); + zipOut.write(this.toASCII("\n")); zipOut.closeEntry(); } finally { diff --git a/src/test/java/forge/model/FModelTest.java b/src/test/java/forge/model/FModelTest.java index 02372afcd83..4a39fbabc58 100644 --- a/src/test/java/forge/model/FModelTest.java +++ b/src/test/java/forge/model/FModelTest.java @@ -1,12 +1,8 @@ package forge.model; -import static org.testng.Assert.assertEquals; -import static org.testng.Assert.assertNotEquals; -import static org.testng.Assert.assertNotNull; -import static org.testng.Assert.assertNull; - import java.io.FileNotFoundException; +import org.testng.Assert; import org.testng.annotations.AfterTest; import org.testng.annotations.BeforeTest; import org.testng.annotations.Test; @@ -19,17 +15,17 @@ import forge.properties.ForgePreferences; */ public class FModelTest { - private FModel model; /** * Set up before each test, creating a default model. * - * @throws FileNotFoundException indirectly + * @throws FileNotFoundException + * indirectly */ @BeforeTest public final void setUp() throws FileNotFoundException { - model = new FModel(null); + this.model = new FModel(null); } /** @@ -37,63 +33,81 @@ public class FModelTest { */ @AfterTest public final void tearDown() { - if (model != null) { + if (this.model != null) { try { - model.close(); - } - catch (Throwable ignored) { + this.model.close(); + } catch (final Throwable ignored) { // ignore exceptions during close. } } - model = null; + this.model = null; } - /** * Test constructor (via setUp), close, and construct again. - * @throws FileNotFoundException if something is really wrong + * + * @throws FileNotFoundException + * if something is really wrong */ @Test - public final void test_ctor_close_ctor() throws FileNotFoundException { // NOPMD by Braids on 8/12/11 10:36 AM - assertNotNull(model, "model is not null"); - model.close(); + public final void test_ctor_close_ctor() throws FileNotFoundException { // NOPMD + // by + // Braids + // on + // 8/12/11 + // 10:36 + // AM + Assert.assertNotNull(this.model, "model is not null"); + this.model.close(); System.err.println("log test"); // NOPMD by Braids on 8/12/11 10:36 AM - model = new FModel(null); - assertNotNull(model, "model is not null"); + this.model = new FModel(null); + Assert.assertNotNull(this.model, "model is not null"); } /** * Test getVersion. - * @throws FileNotFoundException if something is really wrong + * + * @throws FileNotFoundException + * if something is really wrong */ @Test public final void test_getVersion() throws FileNotFoundException { - final String version = model.getBuildInfo().getVersion(); + final String version = this.model.getBuildInfo().getVersion(); - assertEquals(version, "SVN", "version is default"); + Assert.assertEquals(version, "SVN", "version is default"); } /** * Test getBuildID. - * @throws FileNotFoundException if something is really wrong + * + * @throws FileNotFoundException + * if something is really wrong */ @Test - public final void test_getBuildID() throws FileNotFoundException { // NOPMD by Braids on 8/12/11 10:36 AM + public final void test_getBuildID() throws FileNotFoundException { // NOPMD + // by + // Braids + // on + // 8/12/11 + // 10:36 + // AM // Just test for an unexpected exception. - model.getBuildInfo().getBuildID(); + this.model.getBuildInfo().getBuildID(); } /** * Test getPreferences. - * @throws FileNotFoundException indirectly + * + * @throws FileNotFoundException + * indirectly */ @Test public final void test_getPreferences() throws FileNotFoundException { - ForgePreferences prefs = model.getPreferences(); - assertNotNull(prefs, "prefs instance is not null"); + final ForgePreferences prefs = this.model.getPreferences(); + Assert.assertNotNull(prefs, "prefs instance is not null"); } /** @@ -101,17 +115,16 @@ public class FModelTest { */ @Test public final void test_resetGameState_getGameState() { - Singletons.setModel(model); - assertNull(model.getGameState(), "game state has not yet been initialized"); + Singletons.setModel(this.model); + Assert.assertNull(this.model.getGameState(), "game state has not yet been initialized"); - FGameState state1 = model.resetGameState(); - assertNotNull(state1, "first state is OK"); + final FGameState state1 = this.model.resetGameState(); + Assert.assertNotNull(state1, "first state is OK"); - FGameState state2 = model.resetGameState(); - assertNotNull(state1, "first state is OK"); - assertNotEquals(state1, state2, "first and second states are different"); + final FGameState state2 = this.model.resetGameState(); + Assert.assertNotNull(state1, "first state is OK"); + Assert.assertNotEquals(state1, state2, "first and second states are different"); } } - diff --git a/src/test/java/net/slightlymagic/braids/util/testng/BraidsAssertFunctions.java b/src/test/java/net/slightlymagic/braids/util/testng/BraidsAssertFunctions.java index 51040ee0b1f..aa0f6e6b281 100644 --- a/src/test/java/net/slightlymagic/braids/util/testng/BraidsAssertFunctions.java +++ b/src/test/java/net/slightlymagic/braids/util/testng/BraidsAssertFunctions.java @@ -9,31 +9,30 @@ import org.testng.Assert; */ public final class BraidsAssertFunctions { - /** Do not instantiate.*/ + /** Do not instantiate. */ private BraidsAssertFunctions() { - //empty + // empty } /** - * Assert that a function (ClumsyRunnable) throws the given exception, or - * a subclass of it. - * - * @param exnClass the exception we expect - * @param withScissors the code to run + * Assert that a function (ClumsyRunnable) throws the given exception, or a + * subclass of it. + * + * @param exnClass + * the exception we expect + * @param withScissors + * the code to run */ - public static void assertThrowsException( - @SuppressWarnings("rawtypes") final Class exnClass, + public static void assertThrowsException(@SuppressWarnings("rawtypes") final Class exnClass, final ClumsyRunnable withScissors) { try { withScissors.run(); - } - catch (Exception exn) { + } catch (final Exception exn) { if (!exnClass.isInstance(exn)) { - Assert.fail("caught exception " + exn.getClass().getName() - + ", but expected " + exnClass.getName()); + Assert.fail("caught exception " + exn.getClass().getName() + ", but expected " + exnClass.getName()); } - return; //success + return; // success } Assert.fail("expected exception " + exnClass.getName() + ", but none was thrown");