diff options
author | Jannis Harder <harder@informatik.uni-luebeck.de> | 2011-05-27 17:54:46 +0200 |
---|---|---|
committer | Jannis Harder <harder@informatik.uni-luebeck.de> | 2011-05-27 17:54:46 +0200 |
commit | 2d198820a9634c30d62c77f6f310aa227ee29733 (patch) | |
tree | 5096eaf907f64343b9997abea3f51ee4c070cb00 /test | |
parent | 63397e2f5fc62c7d1fc2efbe8f4c686b2343e471 (diff) | |
download | JRummikub-2d198820a9634c30d62c77f6f310aa227ee29733.tar JRummikub-2d198820a9634c30d62c77f6f310aa227ee29733.zip |
GameControl tests, temporary handler in SettingsControl and small
fixes
git-svn-id: svn://sunsvr01.isp.uni-luebeck.de/swproj13/trunk@288 72836036-5685-4462-b002-a69064685172
Diffstat (limited to 'test')
-rw-r--r-- | test/jrummikub/control/GameControlTest.java | 100 |
1 files changed, 100 insertions, 0 deletions
diff --git a/test/jrummikub/control/GameControlTest.java b/test/jrummikub/control/GameControlTest.java new file mode 100644 index 0000000..706928c --- /dev/null +++ b/test/jrummikub/control/GameControlTest.java @@ -0,0 +1,100 @@ +package jrummikub.control; + +import static jrummikub.model.StoneColor.RED; +import static org.junit.Assert.assertSame; +import static org.junit.Assert.assertTrue; + +import java.awt.Color; + +import jrummikub.model.GameSettings; +import jrummikub.model.IHand; +import jrummikub.model.PlayerSettings; +import jrummikub.model.Position; +import jrummikub.model.Stone; +import jrummikub.util.Pair; +import jrummikub.view.MockView; + +import org.junit.Before; +import org.junit.Test; + +/** + * Tests for the game control + */ +public class GameControlTest { + private GameControl gameControl; + private GameSettings gameSettings; + private MockView view; + + /** */ + @Before + public void setUp() { + view = new MockView(); + gameSettings = new GameSettings(); + gameSettings.getPlayerList().add( + new PlayerSettings("Foo", new Color(1.0f, 0, 0))); + gameSettings.getPlayerList().add( + new PlayerSettings("Bar", new Color(0, 1.0f, 0))); + gameControl = new GameControl(gameSettings, view); + } + + /** */ + @Test + public void testStartFirstRound() { + gameControl.startGame(); + assertTrue(view.displayStartTurnPanel); + } + + /** */ + @Test + public void testEndOfRound() { + gameControl.startGame(); + // Manipulate first players hand, to allow player1 to win + IHand playerHand = gameControl.roundControl.roundState + .getActivePlayer().getHand(); + for (Pair<Stone, Position> entry : playerHand.clone()) { + playerHand.pickUp(entry.getFirst()); + } + Stone stone1 = new Stone(9, RED); + Stone stone2 = new Stone(10, RED); + Stone stone3 = new Stone(11, RED); + playerHand.drop(stone1, new Position(0, 0)); + playerHand.drop(stone2, new Position(0, 0)); + playerHand.drop(stone3, new Position(0, 0)); + // Done setting up first players hand + + view.startTurnEvent.emit(); + view.playerPanel.endTurnEvent.emit(); + view.startTurnEvent.emit(); + view.playerPanel.endTurnEvent.emit(); + view.startTurnEvent.emit(); + + view.handPanel.stoneClickEvent.emit(stone1, false); + view.handPanel.stoneClickEvent.emit(stone2, true); + view.handPanel.stoneClickEvent.emit(stone3, true); + + view.tablePanel.clickEvent.emit(new Position(0, 0)); + + view.playerPanel.endTurnEvent.emit(); + assertTrue(view.displayWinPanel); + + view.newRoundEvent.emit(); + assertTrue(view.displayStartTurnPanel); + } + + /** */ + @Test + public void testRedealing() { + gameControl.startGame(); + view.startTurnEvent.emit(); + PlayerSettings firstPlayer = gameControl.roundControl.roundState + .getActivePlayer().getPlayerSettings(); + view.playerPanel.endTurnEvent.emit(); + view.startTurnEvent.emit(); + view.playerPanel.redealEvent.emit(); + assertTrue(view.displayStartTurnPanel); + view.startTurnEvent.emit(); + assertSame(firstPlayer, gameControl.roundControl.roundState + .getActivePlayer().getPlayerSettings()); + + } +} |