From 4561c8ed16c3411a82cac0f8b910a469c5fe4f8b Mon Sep 17 00:00:00 2001 From: Matthias Schiffer Date: Tue, 21 Jun 2011 01:49:31 +0200 Subject: Fixed NetworkRoundControl test git-svn-id: svn://sunsvr01.isp.uni-luebeck.de/swproj13/trunk@526 72836036-5685-4462-b002-a69064685172 --- .../control/network/MockConnectionControl.java | 5 +- .../control/network/NetworkRoundControlTest.java | 119 ++++++++++++--------- 2 files changed, 71 insertions(+), 53 deletions(-) diff --git a/mock/jrummikub/control/network/MockConnectionControl.java b/mock/jrummikub/control/network/MockConnectionControl.java index c7b7dd9..8428fd6 100644 --- a/mock/jrummikub/control/network/MockConnectionControl.java +++ b/mock/jrummikub/control/network/MockConnectionControl.java @@ -65,6 +65,8 @@ public class MockConnectionControl implements IConnectionControl { public boolean turnStarted; /** */ public boolean turnEnded; + /** */ + public boolean nextPlayer; @Override public String getNickname() { @@ -240,7 +242,6 @@ public class MockConnectionControl implements IConnectionControl { @Override public void nextPlayer() { - // TODO Auto-generated method stub - + nextPlayer = true; } } 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. 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. 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. 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. 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); } } -- cgit v1.2.3