From d6c4da62243310b85a82e73e55249de9af7fdb11 Mon Sep 17 00:00:00 2001 From: Matthias Schiffer Date: Wed, 22 Jun 2011 03:08:37 +0200 Subject: Show in start turn panel if a player has redealed or drawn the last stone git-svn-id: svn://sunsvr01.isp.uni-luebeck.de/swproj13/trunk@570 72836036-5685-4462-b002-a69064685172 --- .../control/network/GameJoinControlTest.java | 12 +-- .../control/network/NetworkRoundControlTest.java | 103 ++++++++------------- 2 files changed, 45 insertions(+), 70 deletions(-) (limited to 'test/jrummikub/control/network') diff --git a/test/jrummikub/control/network/GameJoinControlTest.java b/test/jrummikub/control/network/GameJoinControlTest.java index 179c583..e6168a5 100644 --- a/test/jrummikub/control/network/GameJoinControlTest.java +++ b/test/jrummikub/control/network/GameJoinControlTest.java @@ -33,13 +33,12 @@ public class GameJoinControlTest { @Before public void setup() { mockConnection = new MockConnectionControl(); - mockConnection.nickname = "Karl"; view = new MockView(); loginData = new LoginData("Karl", "server", "password", "channel"); networkControl = new NetworkControl(loginData, mockConnection, null, view); networkControl.startNetwork(); - mockConnection.connectedEvent.emit(); + mockConnection.connectedEvent.emit(); } /** */ @@ -52,7 +51,8 @@ public class GameJoinControlTest { assertEquals(SettingsMode.NETWORK_JOIN, view.settingsPanel.settingsMode); offerJoinedGame(id1, "Anne", "Karl"); view.settingsPanel.changePlayerColorEvent.emit(1, Color.GRAY); - assertEquals(Type.HUMAN, mockConnection.getCurrentGame().getGameSettings().getPlayerList().get(1).getType()); + assertEquals(Type.HUMAN, mockConnection.getCurrentGame().getGameSettings() + .getPlayerList().get(1).getType()); assertEquals(Color.GRAY, mockConnection.playerColor); view.settingsPanel.backEvent.emit(); @@ -71,14 +71,14 @@ public class GameJoinControlTest { mockConnection.gameOfferEvent.emit(gameData); return gameData; } - + private GameData offerJoinedGame(UUID id, String host, String player) { GameSettings gsettings = new GameSettings(); PlayerSettings psettings = new PlayerSettings(host, Color.BLACK); - psettings.setType(Type.HUMAN); + psettings.setType(Type.NETWORK); gsettings.getPlayerList().add(psettings); PlayerSettings psettings2 = new PlayerSettings(player, Color.RED); - psettings2.setType(Type.NETWORK); + psettings2.setType(Type.HUMAN); gsettings.getPlayerList().add(psettings2); GameData gameData = new GameData(id, gsettings, host); mockConnection.gameOfferEvent.emit(gameData); diff --git a/test/jrummikub/control/network/NetworkRoundControlTest.java b/test/jrummikub/control/network/NetworkRoundControlTest.java index acf1e84..29ba122 100644 --- a/test/jrummikub/control/network/NetworkRoundControlTest.java +++ b/test/jrummikub/control/network/NetworkRoundControlTest.java @@ -8,6 +8,7 @@ import java.util.Collections; import jrummikub.control.RoundControl.InvalidTurnInfo; import jrummikub.control.turn.AIControl; import jrummikub.model.GameSettings; +import jrummikub.model.GameState; import jrummikub.model.IPlayer; import jrummikub.model.PlayerSettings; import jrummikub.model.PlayerSettings.Type; @@ -21,9 +22,6 @@ import jrummikub.view.MockView; import org.junit.Before; import org.junit.Test; -/** - * Tests for network round control - */ public class NetworkRoundControlTest { private MockConnectionControl connectionControl; private MockView view; @@ -32,7 +30,6 @@ public class NetworkRoundControlTest { private GameSettings gameSettings; - /** */ @Before public void setup() { AIControl.useBackgroundThread = false; @@ -42,26 +39,20 @@ 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().get(1).setType(Type.COMPUTER); - gameSettings.getPlayerList().get(2).setType(Type.NETWORK); - gameSettings.getPlayerList().get(3).setType(Type.COMPUTER); + gameSettings.getPlayerList().add(new PlayerSettings("Jannis", Color.GREEN)); + gameSettings.getPlayerList().add(new PlayerSettings("Bennet", Color.BLACK)); view = new MockView(); connectionControl = new MockConnectionControl(); } - /** */ @Test public void testHostRound() { - connectionControl.nickname = gameSettings.getPlayerList().get(0) - .getName(); + gameSettings.getPlayerList().get(1).setType(Type.COMPUTER); + gameSettings.getPlayerList().get(2).setType(Type.NETWORK); + gameSettings.getPlayerList().get(3).setType(Type.COMPUTER); - testRoundState = new RoundState(gameSettings, null); + testRoundState = new RoundState(gameSettings, new GameState()); testRound = new NetworkRoundControl(testRoundState, view, connectionControl, true); @@ -75,8 +66,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) { @@ -88,8 +79,7 @@ public class NetworkRoundControlTest { } } - assertSame(testRoundState.getNthPlayer(0), - testRoundState.getActivePlayer()); + assertSame(testRoundState.getNthPlayer(0), testRoundState.getActivePlayer()); assertTrue(connectionControl.turnStarted); connectionControl.turnStarted = false; @@ -104,8 +94,7 @@ public class NetworkRoundControlTest { connectionControl.nextPlayer = false; connectionControl.nextPlayerEvent.emit(); - assertSame(testRoundState.getNthPlayer(1), - testRoundState.getActivePlayer()); + assertSame(testRoundState.getNthPlayer(1), testRoundState.getActivePlayer()); assertTrue(connectionControl.turnStarted); connectionControl.turnStarted = false; @@ -117,59 +106,52 @@ public class NetworkRoundControlTest { connectionControl.nextPlayer = false; connectionControl.nextPlayerEvent.emit(); - assertSame(testRoundState.getNthPlayer(2), - testRoundState.getActivePlayer()); - assertTrue(connectionControl.turnStarted); - connectionControl.turnStarted = false; + assertSame(testRoundState.getNthPlayer(2), testRoundState.getActivePlayer()); + assertFalse(connectionControl.turnStarted); connectionControl.turnStartEvent.emit(); assertFalse(connectionControl.turnEnded); - connectionControl.turnEndEvent.emit(testRoundState, - new InvalidTurnInfo(testRoundState.getTable(), null, - Collections. emptyList())); + connectionControl.turnEndEvent.emit(testRoundState, new InvalidTurnInfo( + testRoundState.getTable(), null, Collections. emptyList())); assertFalse(connectionControl.nextPlayer); connectionControl.nextPlayerEvent.emit(); - assertSame(testRoundState.getNthPlayer(3), - testRoundState.getActivePlayer()); + assertSame(testRoundState.getNthPlayer(3), testRoundState.getActivePlayer()); assertFalse(connectionControl.turnStarted); connectionControl.turnStartEvent.emit(); assertFalse(connectionControl.turnEnded); - connectionControl.turnEndEvent.emit(testRoundState, - new InvalidTurnInfo(testRoundState.getTable(), null, - Collections. emptyList())); + connectionControl.turnEndEvent.emit(testRoundState, new InvalidTurnInfo( + testRoundState.getTable(), null, Collections. emptyList())); assertFalse(connectionControl.nextPlayer); connectionControl.nextPlayerEvent.emit(); - assertSame(testRoundState.getNthPlayer(0), - testRoundState.getActivePlayer()); - assertFalse(connectionControl.turnStarted); + assertSame(testRoundState.getNthPlayer(0), testRoundState.getActivePlayer()); + assertTrue(connectionControl.turnStarted); + connectionControl.turnStarted = false; connectionControl.turnStartEvent.emit(); assertFalse(connectionControl.turnEnded); } - /** */ @Test public void testClientRound() { - connectionControl.nickname = gameSettings.getPlayerList().get(2) - .getName(); + gameSettings.getPlayerList().get(0).setType(Type.NETWORK); + gameSettings.getPlayerList().get(1).setType(Type.COMPUTER); + gameSettings.getPlayerList().get(3).setType(Type.COMPUTER); - testRoundState = new RoundState(gameSettings, null); + testRoundState = new RoundState(gameSettings, new GameState()); 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; @@ -178,39 +160,35 @@ public class NetworkRoundControlTest { connectionControl.roundStateUpdateEvent.emit(testRoundState); - assertSame(testRoundState.getNthPlayer(0), - testRoundState.getActivePlayer()); + assertSame(testRoundState.getNthPlayer(0), testRoundState.getActivePlayer()); assertFalse(connectionControl.turnStarted); connectionControl.turnStartEvent.emit(); assertFalse(connectionControl.turnEnded); - connectionControl.turnEndEvent.emit(testRoundState, - new InvalidTurnInfo(testRoundState.getTable(), null, - Collections. emptyList())); + connectionControl.turnEndEvent.emit(testRoundState, new InvalidTurnInfo( + testRoundState.getTable(), null, Collections. emptyList())); assertFalse(connectionControl.turnEnded); assertFalse(connectionControl.nextPlayer); connectionControl.nextPlayerEvent.emit(); - assertSame(testRoundState.getNthPlayer(1), - testRoundState.getActivePlayer()); + assertSame(testRoundState.getNthPlayer(1), testRoundState.getActivePlayer()); assertFalse(connectionControl.turnStarted); connectionControl.turnStartEvent.emit(); assertFalse(connectionControl.turnEnded); - connectionControl.turnEndEvent.emit(testRoundState, - new InvalidTurnInfo(testRoundState.getTable(), null, - Collections. emptyList())); + connectionControl.turnEndEvent.emit(testRoundState, new InvalidTurnInfo( + testRoundState.getTable(), null, Collections. emptyList())); assertFalse(connectionControl.nextPlayer); connectionControl.nextPlayerEvent.emit(); - assertSame(testRoundState.getNthPlayer(2), - testRoundState.getActivePlayer()); - assertFalse(connectionControl.turnStarted); + assertSame(testRoundState.getNthPlayer(2), testRoundState.getActivePlayer()); + assertTrue(connectionControl.turnStarted); + connectionControl.turnStarted = false; connectionControl.turnStartEvent.emit(); @@ -223,8 +201,7 @@ public class NetworkRoundControlTest { connectionControl.nextPlayer = false; connectionControl.nextPlayerEvent.emit(); - assertSame(testRoundState.getNthPlayer(3), - testRoundState.getActivePlayer()); + assertSame(testRoundState.getNthPlayer(3), testRoundState.getActivePlayer()); assertTrue(connectionControl.turnStarted); connectionControl.turnStarted = false; @@ -236,10 +213,8 @@ public class NetworkRoundControlTest { connectionControl.nextPlayer = false; connectionControl.nextPlayerEvent.emit(); - assertSame(testRoundState.getNthPlayer(0), - testRoundState.getActivePlayer()); - assertTrue(connectionControl.turnStarted); - connectionControl.turnStarted = false; + assertSame(testRoundState.getNthPlayer(0), testRoundState.getActivePlayer()); + assertFalse(connectionControl.turnStarted); connectionControl.turnStartEvent.emit(); assertFalse(connectionControl.turnEnded); -- cgit v1.2.3