diff options
author | Matthias Schiffer <mschiffer@universe-factory.net> | 2011-06-21 01:49:31 +0200 |
---|---|---|
committer | Matthias Schiffer <mschiffer@universe-factory.net> | 2011-06-21 01:49:31 +0200 |
commit | 4561c8ed16c3411a82cac0f8b910a469c5fe4f8b (patch) | |
tree | 0b7a30cf89af3ca37a35f98470856efcb77de750 /test/jrummikub | |
parent | 5656d8bb82e0fde95d9ce9fdaff450053a920045 (diff) | |
download | JRummikub-4561c8ed16c3411a82cac0f8b910a469c5fe4f8b.tar JRummikub-4561c8ed16c3411a82cac0f8b910a469c5fe4f8b.zip |
Fixed NetworkRoundControl test
git-svn-id: svn://sunsvr01.isp.uni-luebeck.de/swproj13/trunk@526 72836036-5685-4462-b002-a69064685172
Diffstat (limited to 'test/jrummikub')
-rw-r--r-- | test/jrummikub/control/network/NetworkRoundControlTest.java | 119 |
1 files changed, 68 insertions, 51 deletions
diff --git a/test/jrummikub/control/network/NetworkRoundControlTest.java b/test/jrummikub/control/network/NetworkRoundControlTest.java index f444581..d8300d2 100644 --- a/test/jrummikub/control/network/NetworkRoundControlTest.java +++ b/test/jrummikub/control/network/NetworkRoundControlTest.java @@ -3,7 +3,9 @@ package jrummikub.control.network; import static org.junit.Assert.*; import java.awt.Color; +import java.util.Collections; +import jrummikub.control.RoundControl.InvalidTurnInfo; import jrummikub.control.turn.AIControl; import jrummikub.model.GameSettings; import jrummikub.model.IPlayer; @@ -13,6 +15,7 @@ import jrummikub.model.Position; import jrummikub.model.RoundState; import jrummikub.model.Stone; import jrummikub.model.StoneColor; +import jrummikub.model.StoneSet; import jrummikub.view.MockView; import org.junit.Before; @@ -35,10 +38,8 @@ public class NetworkRoundControlTest { gameSettings.getPlayerList().add(new PlayerSettings("Ida", Color.RED)); gameSettings.getPlayerList().add( new PlayerSettings("Matthias", Color.YELLOW)); - gameSettings.getPlayerList().add( - new PlayerSettings("Jannis", Color.GREEN)); - gameSettings.getPlayerList().add( - new PlayerSettings("Bennet", Color.BLACK)); + gameSettings.getPlayerList().add(new PlayerSettings("Jannis", Color.GREEN)); + gameSettings.getPlayerList().add(new PlayerSettings("Bennet", Color.BLACK)); gameSettings.getPlayerList().get(1).setType(Type.COMPUTER); gameSettings.getPlayerList().get(2).setType(Type.NETWORK); @@ -50,8 +51,7 @@ public class NetworkRoundControlTest { @Test public void testHostRound() { - connectionControl.nickname = gameSettings.getPlayerList().get(0) - .getName(); + connectionControl.nickname = gameSettings.getPlayerList().get(0).getName(); testRoundState = new RoundState(gameSettings, null); testRound = new NetworkRoundControl(testRoundState, view, @@ -67,8 +67,8 @@ public class NetworkRoundControlTest { IPlayer player = testRoundState.getNthPlayer(i); assertSame(gameSettings.getPlayerList().get(i), player.getPlayerSettings()); - assertEquals(gameSettings.getNumberOfStonesDealt(), player - .getHand().getSize()); + assertEquals(gameSettings.getNumberOfStonesDealt(), player.getHand() + .getSize()); } for (int i = 0; i < 4; ++i) { @@ -80,8 +80,7 @@ public class NetworkRoundControlTest { } } - assertSame(testRoundState.getNthPlayer(0), - testRoundState.getActivePlayer()); + assertSame(testRoundState.getNthPlayer(0), testRoundState.getActivePlayer()); assertTrue(connectionControl.turnStarted); connectionControl.turnStarted = false; @@ -92,8 +91,11 @@ public class NetworkRoundControlTest { assertTrue(connectionControl.turnEnded); connectionControl.turnEnded = false; - assertSame(testRoundState.getNthPlayer(1), - testRoundState.getActivePlayer()); + assertTrue(connectionControl.nextPlayer); + connectionControl.nextPlayer = false; + + connectionControl.nextPlayerEvent.emit(); + assertSame(testRoundState.getNthPlayer(1), testRoundState.getActivePlayer()); assertTrue(connectionControl.turnStarted); connectionControl.turnStarted = false; @@ -101,104 +103,119 @@ public class NetworkRoundControlTest { assertTrue(connectionControl.turnEnded); connectionControl.turnEnded = false; - assertSame(testRoundState.getNthPlayer(2), - testRoundState.getActivePlayer()); + assertTrue(connectionControl.nextPlayer); + connectionControl.nextPlayer = false; + + connectionControl.nextPlayerEvent.emit(); + assertSame(testRoundState.getNthPlayer(2), testRoundState.getActivePlayer()); assertTrue(connectionControl.turnStarted); connectionControl.turnStarted = false; connectionControl.turnStartEvent.emit(); assertFalse(connectionControl.turnEnded); - connectionControl.turnEndEvent.emit(testRoundState); + connectionControl.turnEndEvent.emit(testRoundState, new InvalidTurnInfo( + testRoundState.getTable(), null, Collections.<StoneSet> emptyList())); + + assertFalse(connectionControl.nextPlayer); - assertSame(testRoundState.getNthPlayer(3), - testRoundState.getActivePlayer()); + connectionControl.nextPlayerEvent.emit(); + assertSame(testRoundState.getNthPlayer(3), testRoundState.getActivePlayer()); assertFalse(connectionControl.turnStarted); - connectionControl.turnStartEvent.emit(testRoundState); + connectionControl.turnStartEvent.emit(); assertFalse(connectionControl.turnEnded); - connectionControl.turnEndEvent.emit(testRoundState.getActivePlayer() - .getHand(), testRoundState.getTable(), testRoundState - .getTable()); + connectionControl.turnEndEvent.emit(testRoundState, new InvalidTurnInfo( + testRoundState.getTable(), null, Collections.<StoneSet> emptyList())); + + assertFalse(connectionControl.nextPlayer); - assertSame(testRoundState.getNthPlayer(0), - testRoundState.getActivePlayer()); + connectionControl.nextPlayerEvent.emit(); + assertSame(testRoundState.getNthPlayer(0), testRoundState.getActivePlayer()); assertFalse(connectionControl.turnStarted); - connectionControl.turnStartEvent.emit(testRoundState); + connectionControl.turnStartEvent.emit(); assertFalse(connectionControl.turnEnded); } @Test public void testClientRound() { - connectionControl.nickname = gameSettings.getPlayerList().get(2) - .getName(); + connectionControl.nickname = gameSettings.getPlayerList().get(2).getName(); testRoundState = new RoundState(gameSettings, null); for (int i = 0; i < 4; ++i) { IPlayer player = testRoundState.getNthPlayer(i); - player.getHand() - .drop(new Stone(StoneColor.RED), new Position(0, 0)); + player.getHand().drop(new Stone(StoneColor.RED), new Position(0, 0)); } - testRound = new NetworkRoundControl(null, view, connectionControl, - false); + testRound = new NetworkRoundControl(null, view, connectionControl, false); connectionControl.turnStarted = false; connectionControl.turnEnded = false; testRound.startRound(); - assertSame(testRoundState.getNthPlayer(0), - testRoundState.getActivePlayer()); + connectionControl.roundStateUpdateEvent.emit(testRoundState); + + assertSame(testRoundState.getNthPlayer(0), testRoundState.getActivePlayer()); assertFalse(connectionControl.turnStarted); - connectionControl.turnStartEvent.emit(testRoundState); + connectionControl.turnStartEvent.emit(); + assertFalse(connectionControl.turnEnded); + + connectionControl.turnEndEvent.emit(testRoundState, new InvalidTurnInfo( + testRoundState.getTable(), null, Collections.<StoneSet> emptyList())); + assertFalse(connectionControl.turnEnded); - connectionControl.turnEndEvent.emit(testRoundState.getActivePlayer() - .getHand(), testRoundState.getTable(), testRoundState - .getTable()); + assertFalse(connectionControl.nextPlayer); - assertSame(testRoundState.getNthPlayer(1), - testRoundState.getActivePlayer()); + connectionControl.nextPlayerEvent.emit(); + assertSame(testRoundState.getNthPlayer(1), testRoundState.getActivePlayer()); assertFalse(connectionControl.turnStarted); - connectionControl.turnStartEvent.emit(testRoundState); + connectionControl.turnStartEvent.emit(); assertFalse(connectionControl.turnEnded); - connectionControl.turnEndEvent.emit(testRoundState.getActivePlayer() - .getHand(), testRoundState.getTable(), testRoundState - .getTable()); + connectionControl.turnEndEvent.emit(testRoundState, new InvalidTurnInfo( + testRoundState.getTable(), null, Collections.<StoneSet> emptyList())); + + assertFalse(connectionControl.nextPlayer); - assertSame(testRoundState.getNthPlayer(2), - testRoundState.getActivePlayer()); + connectionControl.nextPlayerEvent.emit(); + assertSame(testRoundState.getNthPlayer(2), testRoundState.getActivePlayer()); assertFalse(connectionControl.turnStarted); - connectionControl.turnStartEvent.emit(testRoundState); + connectionControl.turnStartEvent.emit(); assertFalse(connectionControl.turnEnded); view.playerPanel.endTurnEvent.emit(); assertTrue(connectionControl.turnEnded); connectionControl.turnEnded = false; - assertSame(testRoundState.getNthPlayer(3), - testRoundState.getActivePlayer()); + assertTrue(connectionControl.nextPlayer); + connectionControl.nextPlayer = false; + + connectionControl.nextPlayerEvent.emit(); + assertSame(testRoundState.getNthPlayer(3), testRoundState.getActivePlayer()); assertTrue(connectionControl.turnStarted); connectionControl.turnStarted = false; - connectionControl.turnStartEvent.emit(testRoundState); + connectionControl.turnStartEvent.emit(); assertTrue(connectionControl.turnEnded); connectionControl.turnEnded = false; - assertSame(testRoundState.getNthPlayer(0), - testRoundState.getActivePlayer()); + assertTrue(connectionControl.nextPlayer); + connectionControl.nextPlayer = false; + + connectionControl.nextPlayerEvent.emit(); + assertSame(testRoundState.getNthPlayer(0), testRoundState.getActivePlayer()); assertTrue(connectionControl.turnStarted); connectionControl.turnStarted = false; - connectionControl.turnStartEvent.emit(testRoundState); + connectionControl.turnStartEvent.emit(); assertFalse(connectionControl.turnEnded); } } |