diff options
-rw-r--r-- | game-engine/src/test/java/org/luxons/sevenwonders/game/moves/BuildWonderMoveTest.java | 57 |
1 files changed, 33 insertions, 24 deletions
diff --git a/game-engine/src/test/java/org/luxons/sevenwonders/game/moves/BuildWonderMoveTest.java b/game-engine/src/test/java/org/luxons/sevenwonders/game/moves/BuildWonderMoveTest.java index e9a75abd..31e35edc 100644 --- a/game-engine/src/test/java/org/luxons/sevenwonders/game/moves/BuildWonderMoveTest.java +++ b/game-engine/src/test/java/org/luxons/sevenwonders/game/moves/BuildWonderMoveTest.java @@ -5,43 +5,64 @@ import java.util.List; import org.junit.Test; import org.luxons.sevenwonders.game.Settings; -import org.luxons.sevenwonders.game.api.PlayerMove; import org.luxons.sevenwonders.game.api.Table; import org.luxons.sevenwonders.game.cards.Card; -import org.luxons.sevenwonders.game.resources.BoughtResources; import org.luxons.sevenwonders.game.test.TestUtils; import static org.junit.Assert.assertEquals; +import static org.junit.Assert.fail; public class BuildWonderMoveTest { - @Test - public void validate_ok() { + @Test(expected = InvalidMoveException.class) + public void validate_failsWhenCardNotInHand() { Table table = TestUtils.createTable(3); List<Card> hand = TestUtils.createSampleCards(0, 7); - Card cardToUse = hand.get(0); - Move move = createBuildWonderMove(cardToUse, Collections.emptyList()); + Card anotherCard = TestUtils.createCard("Card that is not in the hand"); + Move move = TestUtils.createMove(0, anotherCard, MoveType.UPGRADE_WONDER); move.validate(table, hand); } @Test(expected = InvalidMoveException.class) - public void validate_failsWhenCardNotInHand() { - Table table = TestUtils.createTable(3); + public void validate_failsWhenWonderIsCompletelyBuilt() { + Settings settings = TestUtils.createSettings(3); + Table table = TestUtils.createTable(settings); List<Card> hand = TestUtils.createSampleCards(0, 7); - Card cardToUse = TestUtils.createCard("Card that is not in the hand"); - Move move = createBuildWonderMove(cardToUse, Collections.emptyList()); + fillPlayerWonderLevels(settings, table, hand); + + // should fail because the wonder is already full + buildOneWonderLevel(settings, table, hand, 4); + } + + private static void fillPlayerWonderLevels(Settings settings, Table table, List<Card> hand) { + try { + int nbLevels = table.getBoard(0).getWonder().getStages().size(); + for (int i = 0; i < nbLevels; i++) { + buildOneWonderLevel(settings, table, hand, i); + } + } catch (InvalidMoveException e) { + fail("Building wonder levels should not fail before being full"); + } + } + + private static void buildOneWonderLevel(Settings settings, Table table, List<Card> hand, int cardIndex) { + Card card = hand.get(cardIndex); + Move move = TestUtils.createMove(0, card, MoveType.UPGRADE_WONDER); move.validate(table, hand); + move.place(table, Collections.emptyList(), settings); + move.activate(table, Collections.emptyList(), settings); } @Test - public void place_ok() { + public void place_increasesWonderLevel() { Settings settings = TestUtils.createSettings(3); Table table = TestUtils.createTable(settings); List<Card> hand = TestUtils.createSampleCards(0, 7); Card cardToUse = hand.get(0); - Move move = createBuildWonderMove(cardToUse, Collections.emptyList()); + Move move = TestUtils.createMove(0, cardToUse, MoveType.UPGRADE_WONDER); + move.validate(table, hand); // should not fail int initialStage = table.getBoard(0).getWonder().getNbBuiltStages(); @@ -53,16 +74,4 @@ public class BuildWonderMoveTest { assertEquals(initialStage + 1, newStage); } - private static Move createBuildWonderMove(Card card, List<BoughtResources> boughtResources) { - PlayerMove playerMove = createPlayerMove(card, MoveType.UPGRADE_WONDER, boughtResources); - return MoveType.UPGRADE_WONDER.resolve(0, card, playerMove); - } - - private static PlayerMove createPlayerMove(Card card, MoveType type, List<BoughtResources> boughtResources) { - PlayerMove playerMove = new PlayerMove(); - playerMove.setCardName(card.getName()); - playerMove.setType(type); - playerMove.setBoughtResources(boughtResources); - return playerMove; - } } |