One class left to test completely

git-svn-id: svn://sunsvr01.isp.uni-luebeck.de/swproj13/trunk@605 72836036-5685-4462-b002-a69064685172
This commit is contained in:
Jannis Harder 2011-07-04 23:29:05 +02:00
parent f1ecdcbe59
commit f6a94e553f
2 changed files with 138 additions and 4 deletions

View file

@ -58,6 +58,34 @@ public class GameJoinControlTest {
view.settingsPanel.backEvent.emit(); view.settingsPanel.backEvent.emit();
assertTrue(view.isGameListPanelVisible); 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) { private GameData offerTestGame(UUID id, String host) {
GameSettings gsettings = new GameSettings(); GameSettings gsettings = new GameSettings();

View file

@ -1,15 +1,28 @@
package jrummikub.control.network; package jrummikub.control.network;
import static jrummikub.model.StoneColor.RED;
import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertSame;
import static org.junit.Assert.assertTrue; import static org.junit.Assert.assertTrue;
import java.awt.Color; import java.awt.Color;
import java.util.Collections;
import jrummikub.control.RoundControl.InvalidTurnInfo;
import jrummikub.control.SaveControl; import jrummikub.control.SaveControl;
import jrummikub.model.GameSettings; import jrummikub.model.GameSettings;
import jrummikub.model.GameState;
import jrummikub.model.IHand;
import jrummikub.model.MockRoundState;
import jrummikub.model.PlayerSettings; 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.IListener;
import jrummikub.util.Pair;
import jrummikub.view.IView.BottomPanelType; import jrummikub.view.IView.BottomPanelType;
import jrummikub.view.MockView; import jrummikub.view.MockView;
@ -26,6 +39,7 @@ public class NetworkGameControlTest {
public MockView view; public MockView view;
public MockConnectionControl connection; public MockConnectionControl connection;
public boolean fired; public boolean fired;
public RoundState roundState;
/** */ /** */
@Before @Before
@ -41,16 +55,108 @@ public class NetworkGameControlTest {
view, connection, true); view, connection, true);
clientControl = new NetworkGameControl(settings, new SaveControl(view), clientControl = new NetworkGameControl(settings, new SaveControl(view),
view, connection, false); view, connection, false);
roundState = new RoundState(settings, new GameState());
fired = false; fired = false;
} }
/** */ /** */
@Test @Test
public void testStart() { public void testStartClient() {
clientControl.startGame(); clientControl.startGame();
assertFalse(connection.startRoundCalled); 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(); hostControl.startGame();
assertTrue(connection.startRoundCalled); 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"); connection.participantLeftEvent.emit("Fooblubb");
assertEquals(BottomPanelType.NETWORK_CONNECTION_LOST_PANEL, assertEquals(BottomPanelType.NETWORK_CONNECTION_LOST_PANEL,
view.bottomPanelType); view.bottomPanelType);
hostControl.getEndOfGameEvent().add(new IListener() { hostControl.getEndOfGameEvent().add(new IListener() {
@Override @Override
public void handle() { public void handle() {
fired = true; fired = true;
} }
}); });
view.newGameEvent.emit(); view.newGameEvent.emit();
assertTrue(fired); assertTrue(fired);
} }
} }