summaryrefslogtreecommitdiffstats
path: root/test/jrummikub/control/network
diff options
context:
space:
mode:
authorMatthias Schiffer <mschiffer@universe-factory.net>2011-06-19 19:46:06 +0200
committerMatthias Schiffer <mschiffer@universe-factory.net>2011-06-19 19:46:06 +0200
commit45656861ab2e618938764f0c46f830184099a71d (patch)
tree8e5cd9ab28d47f242408d6dcfc29317902048605 /test/jrummikub/control/network
parent9b7aac51f58eb628978ed0e4d1a922a959917a3b (diff)
downloadJRummikub-45656861ab2e618938764f0c46f830184099a71d.tar
JRummikub-45656861ab2e618938764f0c46f830184099a71d.zip
Added NetworkRoundControlTest and started NetworkRoundControl and NetworkTurnControl implementation
git-svn-id: svn://sunsvr01.isp.uni-luebeck.de/swproj13/trunk@491 72836036-5685-4462-b002-a69064685172
Diffstat (limited to 'test/jrummikub/control/network')
-rw-r--r--test/jrummikub/control/network/NetworkRoundControlTest.java128
1 files changed, 128 insertions, 0 deletions
diff --git a/test/jrummikub/control/network/NetworkRoundControlTest.java b/test/jrummikub/control/network/NetworkRoundControlTest.java
new file mode 100644
index 0000000..c8eb54d
--- /dev/null
+++ b/test/jrummikub/control/network/NetworkRoundControlTest.java
@@ -0,0 +1,128 @@
+package jrummikub.control.network;
+
+import static org.junit.Assert.*;
+
+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 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));
+ 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);
+ 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.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(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);
+ view.playerPanel.endTurnEvent.emit();
+ assertTrue(turnEnded);
+ turnEnded = false;
+ turnStarted = false;
+
+ assertSame(testRoundState.getNthPlayer(2), testRoundState.getActivePlayer());
+
+ connectionControl.turnStartEvent.emit(testRoundState);
+ assertTrue(turnStarted);
+ turnStarted = false;
+
+ assertFalse(turnEnded);
+ connectionControl.turnEndEvent.emit(testRoundState.getTable());
+ assertTrue(turnEnded);
+ turnEnded = false;
+
+ assertSame(testRoundState.getNthPlayer(3), testRoundState.getActivePlayer());
+
+ connectionControl.turnStartEvent.emit(testRoundState);
+ assertTrue(turnStarted);
+ turnStarted = false;
+
+ assertFalse(turnEnded);
+ connectionControl.turnEndEvent.emit(testRoundState.getTable());
+ assertTrue(turnEnded);
+ turnEnded = false;
+
+ assertSame(testRoundState.getNthPlayer(0), testRoundState.getActivePlayer());
+ }
+}