Continued NetworkControlTest
git-svn-id: svn://sunsvr01.isp.uni-luebeck.de/swproj13/trunk@592 72836036-5685-4462-b002-a69064685172
This commit is contained in:
parent
f5aa073827
commit
73c1072ba6
3 changed files with 75 additions and 25 deletions
|
@ -73,6 +73,8 @@ public class MockConnectionControl implements IConnectionControl {
|
||||||
public boolean turnEnded;
|
public boolean turnEnded;
|
||||||
/** */
|
/** */
|
||||||
public boolean nextPlayer;
|
public boolean nextPlayer;
|
||||||
|
/** */
|
||||||
|
public boolean startRoundCalled;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getNickname() {
|
public String getNickname() {
|
||||||
|
@ -251,8 +253,7 @@ public class MockConnectionControl implements IConnectionControl {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void startRound() {
|
public void startRound() {
|
||||||
// TODO Auto-generated method stub
|
startRoundCalled = true;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -59,8 +59,8 @@ public class NetworkControl {
|
||||||
this.connectionControl = connectionControl;
|
this.connectionControl = connectionControl;
|
||||||
this.saveControl = saveControl;
|
this.saveControl = saveControl;
|
||||||
|
|
||||||
addConnectionSetupListeners(loginData, view);
|
addConnectionSetupListeners(loginData);
|
||||||
addConnectionControlListeners(view);
|
addConnectionControlListeners();
|
||||||
addViewEventListeners();
|
addViewEventListeners();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -98,11 +98,8 @@ public class NetworkControl {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Adds the listeners for connection control events
|
* Adds the listeners for connection control events
|
||||||
*
|
|
||||||
* @param view
|
|
||||||
* view for events
|
|
||||||
*/
|
*/
|
||||||
public void addConnectionControlListeners(final IView view) {
|
private void addConnectionControlListeners() {
|
||||||
addOfferUpdateListener();
|
addOfferUpdateListener();
|
||||||
|
|
||||||
connections.add(connectionControl.getGameWithdrawalEvent().add(
|
connections.add(connectionControl.getGameWithdrawalEvent().add(
|
||||||
|
@ -112,20 +109,6 @@ public class NetworkControl {
|
||||||
games.remove(uuid);
|
games.remove(uuid);
|
||||||
gameMap.remove(uuid);
|
gameMap.remove(uuid);
|
||||||
|
|
||||||
updateGameList();
|
|
||||||
}
|
|
||||||
}));
|
|
||||||
connections.add(connectionControl.getParticipantLeftEvent().add(
|
|
||||||
new IListener1<String>() {
|
|
||||||
@Override
|
|
||||||
public void handle(String nickname) {
|
|
||||||
for (Map.Entry<UUID, GameData> entry : gameMap.entrySet()) {
|
|
||||||
if (entry.getValue().getHost().equals(nickname)) {
|
|
||||||
games.remove(entry.getKey());
|
|
||||||
gameMap.remove(entry.getKey());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
updateGameList();
|
updateGameList();
|
||||||
}
|
}
|
||||||
}));
|
}));
|
||||||
|
@ -140,6 +123,28 @@ public class NetworkControl {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}));
|
}));
|
||||||
|
addConnectionLostListeners();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Adds the listeners for lost connection events
|
||||||
|
*/
|
||||||
|
private void addConnectionLostListeners() {
|
||||||
|
connections.add(connectionControl.getParticipantLeftEvent().add(
|
||||||
|
new IListener1<String>() {
|
||||||
|
@Override
|
||||||
|
public void handle(String nickname) {
|
||||||
|
for (Map.Entry<UUID, GameData> entry : gameMap.entrySet()) {
|
||||||
|
if (entry.getValue().getHost().equals(nickname)) {
|
||||||
|
games.remove(entry.getKey());
|
||||||
|
gameMap.remove(entry.getKey());
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
updateGameList();
|
||||||
|
}
|
||||||
|
}));
|
||||||
connections.add(connectionControl.getConnectionLostEvent().add(
|
connections.add(connectionControl.getConnectionLostEvent().add(
|
||||||
new IListener() {
|
new IListener() {
|
||||||
@Override
|
@Override
|
||||||
|
@ -181,8 +186,7 @@ public class NetworkControl {
|
||||||
}));
|
}));
|
||||||
}
|
}
|
||||||
|
|
||||||
private void addConnectionSetupListeners(final LoginData loginData,
|
private void addConnectionSetupListeners(final LoginData loginData) {
|
||||||
final IView view) {
|
|
||||||
connections.add(connectionControl.getConnectedEvent().add(new IListener() {
|
connections.add(connectionControl.getConnectedEvent().add(new IListener() {
|
||||||
@Override
|
@Override
|
||||||
public void handle() {
|
public void handle() {
|
||||||
|
|
|
@ -5,6 +5,7 @@ import static org.junit.Assert.*;
|
||||||
import java.awt.Color;
|
import java.awt.Color;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
|
||||||
|
import jrummikub.control.SaveControl;
|
||||||
import jrummikub.model.GameSettings;
|
import jrummikub.model.GameSettings;
|
||||||
import jrummikub.model.PlayerSettings;
|
import jrummikub.model.PlayerSettings;
|
||||||
import jrummikub.model.PlayerSettings.Type;
|
import jrummikub.model.PlayerSettings.Type;
|
||||||
|
@ -35,7 +36,7 @@ public class NetworkControlTest {
|
||||||
mockConnection.nickname = "Karl";
|
mockConnection.nickname = "Karl";
|
||||||
view = new MockView();
|
view = new MockView();
|
||||||
loginData = new LoginData("Karl", "server", "password", "channel");
|
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();
|
networkControl.startNetwork();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -77,6 +78,7 @@ public class NetworkControlTest {
|
||||||
assertTrue(view.isSettingsPanelVisible);
|
assertTrue(view.isSettingsPanelVisible);
|
||||||
assertEquals(SettingsMode.NETWORK_OFFER,
|
assertEquals(SettingsMode.NETWORK_OFFER,
|
||||||
view.settingsPanel.settingsMode);
|
view.settingsPanel.settingsMode);
|
||||||
|
assertNotNull(mockConnection.offeredGame);
|
||||||
}
|
}
|
||||||
|
|
||||||
/** */
|
/** */
|
||||||
|
@ -115,6 +117,30 @@ public class NetworkControlTest {
|
||||||
assertEquals("Horst", view.gameListPanel.gameList.get(0).getHost());
|
assertEquals("Horst", view.gameListPanel.gameList.get(0).getHost());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** */
|
||||||
|
@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
|
@Test
|
||||||
public void testCancel() {
|
public void testCancel() {
|
||||||
|
@ -138,4 +164,23 @@ public class NetworkControlTest {
|
||||||
return gameData;
|
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);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Reference in a new issue