diff options
author | Matthias Schiffer <mschiffer@universe-factory.net> | 2011-06-19 23:19:01 +0200 |
---|---|---|
committer | Matthias Schiffer <mschiffer@universe-factory.net> | 2011-06-19 23:19:01 +0200 |
commit | 9df549727672e8df768d46e3ef1fb0c7957f0f89 (patch) | |
tree | 3ad4ef018dfb850aee56771c4227d9ce0b32be7e /test | |
parent | 890051a3e93a31d0e1a6bc1a1d1bc14a7205b8b9 (diff) | |
download | JRummikub-9df549727672e8df768d46e3ef1fb0c7957f0f89.tar JRummikub-9df549727672e8df768d46e3ef1fb0c7957f0f89.zip |
Make NetworkRoundControl test work
git-svn-id: svn://sunsvr01.isp.uni-luebeck.de/swproj13/trunk@496 72836036-5685-4462-b002-a69064685172
Diffstat (limited to 'test')
-rw-r--r-- | test/jrummikub/control/network/NetworkRoundControlTest.java | 110 |
1 files changed, 50 insertions, 60 deletions
diff --git a/test/jrummikub/control/network/NetworkRoundControlTest.java b/test/jrummikub/control/network/NetworkRoundControlTest.java index c8eb54d..797c481 100644 --- a/test/jrummikub/control/network/NetworkRoundControlTest.java +++ b/test/jrummikub/control/network/NetworkRoundControlTest.java @@ -7,33 +7,27 @@ import java.awt.Color; import jrummikub.control.turn.AIControl; import jrummikub.model.GameSettings; import jrummikub.model.IPlayer; -import jrummikub.model.IRoundState; -import jrummikub.model.ITable; import jrummikub.model.PlayerSettings; import jrummikub.model.PlayerSettings.Type; import jrummikub.model.RoundState; import jrummikub.model.Stone; -import jrummikub.util.IListener1; import jrummikub.view.MockView; import org.junit.Before; import org.junit.Test; public class NetworkRoundControlTest { - private MockConnectionControl connectionControl; + private MockConnectionControl connectionControl; private MockView view; private RoundState testRoundState; private NetworkRoundControl testRound; private GameSettings gameSettings; - private boolean turnStarted; - private boolean turnEnded; - @Before public void setup() { AIControl.useBackgroundThread = false; - + gameSettings = new GameSettings(); gameSettings.getPlayerList().add(new PlayerSettings("Ida", Color.RED)); @@ -46,83 +40,79 @@ public class NetworkRoundControlTest { gameSettings.getPlayerList().get(2).setType(Type.NETWORK); gameSettings.getPlayerList().get(3).setType(Type.COMPUTER); testRoundState = new RoundState(gameSettings); - + view = new MockView(); connectionControl = new MockConnectionControl(); } - + @Test public void testHostRound() { - testRound = new NetworkRoundControl(testRoundState, view, connectionControl, true); - - connectionControl.getTurnStartEvent().add(new IListener1<IRoundState>() { - @Override - public void handle(IRoundState roundState) { - assertSame(testRoundState, roundState); - - turnStarted = true; - } - }); - - connectionControl.getTurnEndEvent().add(new IListener1<ITable>() { - @Override - public void handle(ITable table) { - turnEnded = true; - } - }); - - turnStarted = false; - turnEnded = false; - + testRound = new NetworkRoundControl(testRoundState, view, + connectionControl, true); + + connectionControl.turnStarted = false; + connectionControl.turnEnded = false; + testRound.startRound(); - assertTrue(turnStarted); - turnStarted = false; - + assertEquals(4, testRoundState.getPlayerCount()); for (int i = 0; i < 4; ++i) { IPlayer player = testRoundState.getNthPlayer(i); - assertSame(gameSettings.getPlayerList().get(i), player.getPlayerSettings()); - assertEquals(gameSettings.getNumberOfStonesDealt(), player.getHand().getSize()); + assertSame(gameSettings.getPlayerList().get(i), + player.getPlayerSettings()); + assertEquals(gameSettings.getNumberOfStonesDealt(), player.getHand() + .getSize()); } - assertSame(testRoundState.getNthPlayer(0), testRoundState.getActivePlayer()); - + for (int i = 0; i < 4; ++i) { IPlayer player = testRoundState.getNthPlayer(i); - + while (player.getHand().getSize() > 1) { Stone stone = player.getHand().iterator().next().getFirst(); player.getHand().pickUp(stone); } } - - assertFalse(turnEnded); + + assertSame(testRoundState.getNthPlayer(0), testRoundState.getActivePlayer()); + assertTrue(connectionControl.turnStarted); + connectionControl.turnStarted = false; + + connectionControl.turnStartEvent.emit(testRoundState); + + assertFalse(connectionControl.turnEnded); view.playerPanel.endTurnEvent.emit(); - assertTrue(turnEnded); - turnEnded = false; - turnStarted = false; + assertTrue(connectionControl.turnEnded); + connectionControl.turnEnded = false; + + assertSame(testRoundState.getNthPlayer(1), testRoundState.getActivePlayer()); + assertTrue(connectionControl.turnStarted); + connectionControl.turnStarted = false; + + connectionControl.turnStartEvent.emit(testRoundState); + assertTrue(connectionControl.turnEnded); + connectionControl.turnEnded = false; assertSame(testRoundState.getNthPlayer(2), testRoundState.getActivePlayer()); - + assertTrue(connectionControl.turnStarted); + connectionControl.turnStarted = false; + connectionControl.turnStartEvent.emit(testRoundState); - assertTrue(turnStarted); - turnStarted = false; - - assertFalse(turnEnded); + assertFalse(connectionControl.turnEnded); + connectionControl.turnEndEvent.emit(testRoundState.getTable()); - assertTrue(turnEnded); - turnEnded = false; - + assertSame(testRoundState.getNthPlayer(3), testRoundState.getActivePlayer()); - + assertFalse(connectionControl.turnStarted); + connectionControl.turnStartEvent.emit(testRoundState); - assertTrue(turnStarted); - turnStarted = false; - - assertFalse(turnEnded); + assertFalse(connectionControl.turnEnded); + connectionControl.turnEndEvent.emit(testRoundState.getTable()); - assertTrue(turnEnded); - turnEnded = false; - + assertSame(testRoundState.getNthPlayer(0), testRoundState.getActivePlayer()); + assertFalse(connectionControl.turnStarted); + + connectionControl.turnStartEvent.emit(testRoundState); + assertFalse(connectionControl.turnEnded); } } |