summaryrefslogtreecommitdiffstats
path: root/test/jrummikub
diff options
context:
space:
mode:
authorJannis Harder <harder@informatik.uni-luebeck.de>2011-07-04 23:29:05 +0200
committerJannis Harder <harder@informatik.uni-luebeck.de>2011-07-04 23:29:05 +0200
commitf6a94e553f89de1544e8689db7e19709cba2b9fb (patch)
treee5d170cd7b42352853a74f2a5928a2bdd7f5b819 /test/jrummikub
parentf1ecdcbe59cfaaad647cb5a6c50ceb39c9496c8d (diff)
downloadJRummikub-f6a94e553f89de1544e8689db7e19709cba2b9fb.tar
JRummikub-f6a94e553f89de1544e8689db7e19709cba2b9fb.zip
One class left to test completely
git-svn-id: svn://sunsvr01.isp.uni-luebeck.de/swproj13/trunk@605 72836036-5685-4462-b002-a69064685172
Diffstat (limited to 'test/jrummikub')
-rw-r--r--test/jrummikub/control/network/GameJoinControlTest.java28
-rw-r--r--test/jrummikub/control/network/NetworkGameControlTest.java114
2 files changed, 138 insertions, 4 deletions
diff --git a/test/jrummikub/control/network/GameJoinControlTest.java b/test/jrummikub/control/network/GameJoinControlTest.java
index e6168a5..dc1eed0 100644
--- a/test/jrummikub/control/network/GameJoinControlTest.java
+++ b/test/jrummikub/control/network/GameJoinControlTest.java
@@ -58,6 +58,34 @@ public class GameJoinControlTest {
view.settingsPanel.backEvent.emit();
assertTrue(view.isGameListPanelVisible);
}
+
+ /** */
+ @Test
+ public void gameWithdrawnTest() {
+ GameData data = offerTestGame(id1, "Anne");
+ view.gameListPanel.joinEvent.emit(data);
+ mockConnection.gameJoinAckEvent.emit(true);
+ assertTrue(view.isSettingsPanelVisible);
+ assertEquals(SettingsMode.NETWORK_JOIN, view.settingsPanel.settingsMode);
+ offerJoinedGame(id1, "Anne", "Karl");
+
+ mockConnection.gameWithdrawalEvent.emit(id1);
+ assertTrue(view.isGameListPanelVisible);
+ }
+
+ /** */
+ @Test
+ public void participantLeftTest() {
+ GameData data = offerTestGame(id1, "Anne");
+ view.gameListPanel.joinEvent.emit(data);
+ mockConnection.gameJoinAckEvent.emit(true);
+ assertTrue(view.isSettingsPanelVisible);
+ assertEquals(SettingsMode.NETWORK_JOIN, view.settingsPanel.settingsMode);
+ offerJoinedGame(id1, "Anne", "Karl");
+
+ mockConnection.participantLeftEvent.emit("Anne");
+ assertTrue(view.isGameListPanelVisible);
+ }
private GameData offerTestGame(UUID id, String host) {
GameSettings gsettings = new GameSettings();
diff --git a/test/jrummikub/control/network/NetworkGameControlTest.java b/test/jrummikub/control/network/NetworkGameControlTest.java
index c4db9af..b1769e2 100644
--- a/test/jrummikub/control/network/NetworkGameControlTest.java
+++ b/test/jrummikub/control/network/NetworkGameControlTest.java
@@ -1,15 +1,28 @@
package jrummikub.control.network;
+import static jrummikub.model.StoneColor.RED;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertSame;
import static org.junit.Assert.assertTrue;
import java.awt.Color;
+import java.util.Collections;
+import jrummikub.control.RoundControl.InvalidTurnInfo;
import jrummikub.control.SaveControl;
import jrummikub.model.GameSettings;
+import jrummikub.model.GameState;
+import jrummikub.model.IHand;
+import jrummikub.model.MockRoundState;
import jrummikub.model.PlayerSettings;
+import jrummikub.model.Position;
+import jrummikub.model.RoundState;
+import jrummikub.model.Stone;
+import jrummikub.model.StoneSet;
+import jrummikub.model.Table;
import jrummikub.util.IListener;
+import jrummikub.util.Pair;
import jrummikub.view.IView.BottomPanelType;
import jrummikub.view.MockView;
@@ -26,6 +39,7 @@ public class NetworkGameControlTest {
public MockView view;
public MockConnectionControl connection;
public boolean fired;
+ public RoundState roundState;
/** */
@Before
@@ -41,16 +55,108 @@ public class NetworkGameControlTest {
view, connection, true);
clientControl = new NetworkGameControl(settings, new SaveControl(view),
view, connection, false);
+ roundState = new RoundState(settings, new GameState());
fired = false;
}
/** */
@Test
- public void testStart() {
+ public void testStartClient() {
clientControl.startGame();
assertFalse(connection.startRoundCalled);
+ connection.roundStartEvent.emit();
+ connection.roundStateUpdateEvent.emit(roundState);
+
+ connection.turnStartEvent.emit();
+ assertSame(BottomPanelType.HUMAN_HAND_PANEL, view.bottomPanelType);
+ }
+
+ /** */
+ @Test
+ public void testStartHost() {
hostControl.startGame();
assertTrue(connection.startRoundCalled);
+ connection.roundStartEvent.emit();
+
+ connection.roundStateUpdateEvent.emit(roundState);
+ assertTrue(connection.turnStarted);
+ }
+
+ /** */
+ @Test
+ public void testWinHost() {
+ hostControl.startGame();
+ assertTrue(connection.startRoundCalled);
+ connection.roundStartEvent.emit();
+
+ roundState.nextTurn();
+ roundState.nextTurn();
+
+ IHand playerHand = roundState.getActivePlayer().getHand();
+
+ Stone stone1 = new Stone(9, RED);
+ Stone stone2 = new Stone(10, RED);
+ Stone stone3 = new Stone(11, RED);
+ playerHand.drop(stone1, new Position(0, 0));
+ playerHand.drop(stone2, new Position(0, 0));
+ playerHand.drop(stone3, new Position(0, 0));
+
+ connection.roundStateUpdateEvent.emit(roundState);
+
+ connection.turnStartEvent.emit();
+
+ view.handPanel.stoneClickEvent.emit(stone1, false);
+ view.handPanel.stoneClickEvent.emit(stone2, true);
+ view.handPanel.stoneClickEvent.emit(stone3, true);
+
+ view.tablePanel.clickEvent.emit(new Position(0, 0));
+ view.playerPanel.endTurnEvent.emit();
+
+ assertTrue(connection.nextPlayer);
+ connection.nextPlayerEvent.emit();
+
+ connection.turnEndEvent.emit(roundState, new InvalidTurnInfo(new Table(
+ settings), null, Collections.<StoneSet> emptyList()));
+ assertSame(BottomPanelType.WIN_PANEL, view.bottomPanelType);
+ assertTrue(view.isScorePanelVisible);
+ }
+
+ /** */
+ @Test
+ public void testWinClient() {
+ clientControl.startGame();
+ connection.roundStartEvent.emit();
+
+ roundState.nextTurn();
+ roundState.nextTurn();
+
+ IHand playerHand = roundState.getActivePlayer().getHand();
+
+ Stone stone1 = new Stone(9, RED);
+ Stone stone2 = new Stone(10, RED);
+ Stone stone3 = new Stone(11, RED);
+ playerHand.drop(stone1, new Position(0, 0));
+ playerHand.drop(stone2, new Position(0, 0));
+ playerHand.drop(stone3, new Position(0, 0));
+
+ connection.roundStateUpdateEvent.emit(roundState);
+
+ connection.turnStartEvent.emit();
+
+ view.handPanel.stoneClickEvent.emit(stone1, false);
+ view.handPanel.stoneClickEvent.emit(stone2, true);
+ view.handPanel.stoneClickEvent.emit(stone3, true);
+
+ view.tablePanel.clickEvent.emit(new Position(0, 0));
+ view.playerPanel.endTurnEvent.emit();
+
+ assertTrue(connection.nextPlayer);
+ connection.nextPlayerEvent.emit();
+
+ connection.turnEndEvent.emit(roundState, new InvalidTurnInfo(new Table(
+ settings), null, Collections.<StoneSet> emptyList()));
+ assertSame(BottomPanelType.NETWORK_WIN_PANEL, view.bottomPanelType);
+ assertTrue(view.isScorePanelVisible);
}
/** */
@@ -62,17 +168,17 @@ public class NetworkGameControlTest {
connection.participantLeftEvent.emit("Fooblubb");
assertEquals(BottomPanelType.NETWORK_CONNECTION_LOST_PANEL,
view.bottomPanelType);
-
+
hostControl.getEndOfGameEvent().add(new IListener() {
@Override
public void handle() {
fired = true;
}
});
-
+
view.newGameEvent.emit();
assertTrue(fired);
-
+
}
}