summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--mock/jrummikub/control/network/MockConnectionControl.java5
-rw-r--r--src/jrummikub/control/network/NetworkControl.java42
-rw-r--r--test/jrummikub/control/network/NetworkControlTest.java47
3 files changed, 72 insertions, 22 deletions
diff --git a/mock/jrummikub/control/network/MockConnectionControl.java b/mock/jrummikub/control/network/MockConnectionControl.java
index faa1303..33aa4aa 100644
--- a/mock/jrummikub/control/network/MockConnectionControl.java
+++ b/mock/jrummikub/control/network/MockConnectionControl.java
@@ -73,6 +73,8 @@ public class MockConnectionControl implements IConnectionControl {
public boolean turnEnded;
/** */
public boolean nextPlayer;
+ /** */
+ public boolean startRoundCalled;
@Override
public String getNickname() {
@@ -251,8 +253,7 @@ public class MockConnectionControl implements IConnectionControl {
@Override
public void startRound() {
- // TODO Auto-generated method stub
-
+ startRoundCalled = true;
}
@Override
diff --git a/src/jrummikub/control/network/NetworkControl.java b/src/jrummikub/control/network/NetworkControl.java
index 154ea06..d31442b 100644
--- a/src/jrummikub/control/network/NetworkControl.java
+++ b/src/jrummikub/control/network/NetworkControl.java
@@ -59,8 +59,8 @@ public class NetworkControl {
this.connectionControl = connectionControl;
this.saveControl = saveControl;
- addConnectionSetupListeners(loginData, view);
- addConnectionControlListeners(view);
+ addConnectionSetupListeners(loginData);
+ addConnectionControlListeners();
addViewEventListeners();
}
@@ -98,11 +98,8 @@ public class NetworkControl {
/**
* Adds the listeners for connection control events
- *
- * @param view
- * view for events
*/
- public void addConnectionControlListeners(final IView view) {
+ private void addConnectionControlListeners() {
addOfferUpdateListener();
connections.add(connectionControl.getGameWithdrawalEvent().add(
@@ -115,6 +112,24 @@ public class NetworkControl {
updateGameList();
}
}));
+ connections.add(connectionControl.getGameJoinAckEvent().add(
+ new IListener1<Boolean>() {
+ @Override
+ public void handle(Boolean ack) {
+ if (ack) {
+ createGameJoinControl();
+ } else {
+ view.showGameListPanel(true);
+ }
+ }
+ }));
+ addConnectionLostListeners();
+ }
+
+ /**
+ * Adds the listeners for lost connection events
+ */
+ private void addConnectionLostListeners() {
connections.add(connectionControl.getParticipantLeftEvent().add(
new IListener1<String>() {
@Override
@@ -123,23 +138,13 @@ public class NetworkControl {
if (entry.getValue().getHost().equals(nickname)) {
games.remove(entry.getKey());
gameMap.remove(entry.getKey());
+ break;
}
}
updateGameList();
}
}));
- connections.add(connectionControl.getGameJoinAckEvent().add(
- new IListener1<Boolean>() {
- @Override
- public void handle(Boolean ack) {
- if (ack) {
- createGameJoinControl();
- } else {
- view.showGameListPanel(true);
- }
- }
- }));
connections.add(connectionControl.getConnectionLostEvent().add(
new IListener() {
@Override
@@ -181,8 +186,7 @@ public class NetworkControl {
}));
}
- private void addConnectionSetupListeners(final LoginData loginData,
- final IView view) {
+ private void addConnectionSetupListeners(final LoginData loginData) {
connections.add(connectionControl.getConnectedEvent().add(new IListener() {
@Override
public void handle() {
diff --git a/test/jrummikub/control/network/NetworkControlTest.java b/test/jrummikub/control/network/NetworkControlTest.java
index 2be4da0..6d772ff 100644
--- a/test/jrummikub/control/network/NetworkControlTest.java
+++ b/test/jrummikub/control/network/NetworkControlTest.java
@@ -5,6 +5,7 @@ import static org.junit.Assert.*;
import java.awt.Color;
import java.util.UUID;
+import jrummikub.control.SaveControl;
import jrummikub.model.GameSettings;
import jrummikub.model.PlayerSettings;
import jrummikub.model.PlayerSettings.Type;
@@ -35,7 +36,7 @@ public class NetworkControlTest {
mockConnection.nickname = "Karl";
view = new MockView();
loginData = new LoginData("Karl", "server", "password", "channel");
- networkControl = new NetworkControl(loginData, mockConnection, null, view);
+ networkControl = new NetworkControl(loginData, mockConnection, new SaveControl(view), view);
networkControl.startNetwork();
}
@@ -77,6 +78,7 @@ public class NetworkControlTest {
assertTrue(view.isSettingsPanelVisible);
assertEquals(SettingsMode.NETWORK_OFFER,
view.settingsPanel.settingsMode);
+ assertNotNull(mockConnection.offeredGame);
}
/** */
@@ -117,6 +119,30 @@ public class NetworkControlTest {
/** */
@Test
+ public void disconnectedGameTest() {
+ mockConnection.connectedEvent.emit();
+ offerTestGame(id1, "Berta");
+
+ offerTestGame(id2, "Horst");
+
+ assertEquals(2, view.gameListPanel.gameList.size());
+ assertEquals(2, view.gameListPanel.gameList.get(0).getGameSettings()
+ .getPlayerList().size());
+ assertEquals(id1, view.gameListPanel.gameList.get(0).getGameID());
+ assertEquals("Berta", view.gameListPanel.gameList.get(0).getHost());
+ assertEquals(2, view.gameListPanel.gameList.get(1).getGameSettings()
+ .getPlayerList().size());
+ assertEquals(id2, view.gameListPanel.gameList.get(1).getGameID());
+ assertEquals("Horst", view.gameListPanel.gameList.get(1).getHost());
+
+ mockConnection.participantLeftEvent.emit("Berta");
+ assertEquals(1, view.gameListPanel.gameList.size());
+ assertEquals(id2, view.gameListPanel.gameList.get(0).getGameID());
+ assertEquals("Horst", view.gameListPanel.gameList.get(0).getHost());
+ }
+
+ /** */
+ @Test
public void testCancel() {
mockConnection.connectedEvent.emit();
@@ -138,4 +164,23 @@ public class NetworkControlTest {
return gameData;
}
+ /** */
+ @Test
+ public void testStartGame() {
+ mockConnection.connectedEvent.emit();
+
+ view.gameListPanel.openNewGameEvent.emit();
+
+ assertTrue(view.isSettingsPanelVisible);
+ assertEquals(SettingsMode.NETWORK_SETUP,
+ view.settingsPanel.settingsMode);
+
+ view.settingsPanel.offerGameEvent.emit();
+
+ mockConnection.gameJoinEvent.emit("Blubb");
+
+ view.settingsPanel.startGameEvent.emit();
+
+ assertTrue(mockConnection.startRoundCalled);
+ }
}