diff options
-rw-r--r-- | src/main/java/org/luxons/sevenwonders/game/boards/Board.java | 2 | ||||
-rw-r--r-- | src/test/java/org/luxons/sevenwonders/game/boards/BoardTest.java | 29 |
2 files changed, 30 insertions, 1 deletions
diff --git a/src/main/java/org/luxons/sevenwonders/game/boards/Board.java b/src/main/java/org/luxons/sevenwonders/game/boards/Board.java index e8afecd5..d6cfd8e1 100644 --- a/src/main/java/org/luxons/sevenwonders/game/boards/Board.java +++ b/src/main/java/org/luxons/sevenwonders/game/boards/Board.java @@ -97,7 +97,7 @@ public class Board { return military; } - private static class InsufficientFundsException extends RuntimeException { + static class InsufficientFundsException extends RuntimeException { InsufficientFundsException(int current, int required) { super(String.format("Current balance is %d gold, but %d are required", current, required)); } diff --git a/src/test/java/org/luxons/sevenwonders/game/boards/BoardTest.java b/src/test/java/org/luxons/sevenwonders/game/boards/BoardTest.java index 952561ac..35b2df7d 100644 --- a/src/test/java/org/luxons/sevenwonders/game/boards/BoardTest.java +++ b/src/test/java/org/luxons/sevenwonders/game/boards/BoardTest.java @@ -3,12 +3,15 @@ package org.luxons.sevenwonders.game.boards; import java.util.Arrays; import java.util.Collections; +import org.junit.Rule; import org.junit.experimental.theories.DataPoints; import org.junit.experimental.theories.FromDataPoints; import org.junit.experimental.theories.Theories; import org.junit.experimental.theories.Theory; +import org.junit.rules.ExpectedException; import org.junit.runner.RunWith; import org.luxons.sevenwonders.game.Settings; +import org.luxons.sevenwonders.game.boards.Board.InsufficientFundsException; import org.luxons.sevenwonders.game.cards.Color; import org.luxons.sevenwonders.game.resources.ResourceType; import org.luxons.sevenwonders.game.resources.Resources; @@ -16,6 +19,7 @@ import org.luxons.sevenwonders.game.test.TestUtils; import static junit.framework.TestCase.assertEquals; import static org.junit.Assert.assertTrue; +import static org.junit.Assume.*; @RunWith(Theories.class) public class BoardTest { @@ -40,6 +44,9 @@ public class BoardTest { return Color.values(); } + @Rule + public ExpectedException thrown = ExpectedException.none(); + @Theory public void initialGold_respectsSettings(@FromDataPoints("gold") int goldAmountInSettings) { Settings settings = new Settings(); @@ -56,6 +63,28 @@ public class BoardTest { } @Theory + public void removeOld_successfulWhenNotTooMuch(@FromDataPoints("gold") int initialGold, + @FromDataPoints("gold") int goldRemoved) { + assumeTrue(goldRemoved >= 0); + assumeTrue(initialGold >= goldRemoved); + Board board = new Board(TestUtils.createWonder(), null, new Settings()); + board.setGold(initialGold); + board.removeGold(goldRemoved); + assertEquals(initialGold - goldRemoved, board.getGold()); + } + + @Theory + public void removeOld_failsWhenTooMuch(@FromDataPoints("gold") int initialGold, + @FromDataPoints("gold") int goldRemoved) { + assumeTrue(goldRemoved >= 0); + assumeTrue(initialGold < goldRemoved); + thrown.expect(InsufficientFundsException.class); + Board board = new Board(TestUtils.createWonder(), null, new Settings()); + board.setGold(initialGold); + board.removeGold(goldRemoved); + } + + @Theory public void getNbCardsOfColor_properCount_singleColor(ResourceType type, @FromDataPoints("nbCards") int nbCards, @FromDataPoints("nbCards") int nbOtherCards, Color color) { Board board = new Board(TestUtils.createWonder(type), null, new Settings()); |