summaryrefslogtreecommitdiff
path: root/game-engine/src
diff options
context:
space:
mode:
authorJoffrey Bion <joffrey.bion@amadeus.com>2018-04-25 17:48:38 +0200
committerJoffrey Bion <joffrey.bion@amadeus.com>2018-04-25 17:48:38 +0200
commit72a18fc2a8934a4b2dddb0c0c5a2aa5d8c35c6c3 (patch)
treef8f534d261311aa4aaf5a1898e417c86e30ce8af /game-engine/src
parentFix WonderStage creation to add at least an empty effect list (diff)
downloadseven-wonders-72a18fc2a8934a4b2dddb0c0c5a2aa5d8c35c6c3.tar.gz
seven-wonders-72a18fc2a8934a4b2dddb0c0c5a2aa5d8c35c6c3.tar.bz2
seven-wonders-72a18fc2a8934a4b2dddb0c0c5a2aa5d8c35c6c3.zip
Add tests for BuildWonderMove
Diffstat (limited to 'game-engine/src')
-rw-r--r--game-engine/src/test/java/org/luxons/sevenwonders/game/moves/BuildWonderMoveTest.java57
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;
- }
}
bgstack15