diff options
author | Ida Massow <massow@informatik.uni-luebeck.de> | 2011-06-19 02:45:49 +0200 |
---|---|---|
committer | Ida Massow <massow@informatik.uni-luebeck.de> | 2011-06-19 02:45:49 +0200 |
commit | 4ddf87fc9638a7a099c57d650ed878571d0b0954 (patch) | |
tree | 50f5754c83dd556af6fcc81b1d64823f8b69b9b9 | |
parent | f641b76bcac15871458e649cdde02331c2cef882 (diff) | |
download | JRummikub-4ddf87fc9638a7a099c57d650ed878571d0b0954.tar JRummikub-4ddf87fc9638a7a099c57d650ed878571d0b0954.zip |
Test für game join control
git-svn-id: svn://sunsvr01.isp.uni-luebeck.de/swproj13/trunk@478 72836036-5685-4462-b002-a69064685172
-rw-r--r-- | mock/jrummikub/control/network/MockConnectionControl.java | 5 | ||||
-rw-r--r-- | mock/jrummikub/view/MockSettingsPanel.java | 4 | ||||
-rw-r--r-- | test/jrummikub/control/network/GameJoinControlTest.java | 80 |
3 files changed, 86 insertions, 3 deletions
diff --git a/mock/jrummikub/control/network/MockConnectionControl.java b/mock/jrummikub/control/network/MockConnectionControl.java index 7d97c78..1f68d65 100644 --- a/mock/jrummikub/control/network/MockConnectionControl.java +++ b/mock/jrummikub/control/network/MockConnectionControl.java @@ -41,6 +41,8 @@ public class MockConnectionControl implements IConnectionControl { public boolean failOnConnect; /** */ public GameData joinedGame; + /** */ + public Color playerColor; @Override public String getNickname() { @@ -142,7 +144,6 @@ public class MockConnectionControl implements IConnectionControl { @Override public void changeColor(Color color) { - // TODO Auto-generated method stub - + playerColor = color; } } diff --git a/mock/jrummikub/view/MockSettingsPanel.java b/mock/jrummikub/view/MockSettingsPanel.java index 594a3b3..16c183c 100644 --- a/mock/jrummikub/view/MockSettingsPanel.java +++ b/mock/jrummikub/view/MockSettingsPanel.java @@ -76,7 +76,9 @@ public class MockSettingsPanel implements ISettingsPanel { public int highestValue; /** */ public Set<StoneColor> stoneColors; - private MockEvent backEvent = new MockEvent(); + /** */ + public MockEvent backEvent = new MockEvent(); + /** */ public SettingsMode settingsMode; @Override diff --git a/test/jrummikub/control/network/GameJoinControlTest.java b/test/jrummikub/control/network/GameJoinControlTest.java index 9e175b1..31f76da 100644 --- a/test/jrummikub/control/network/GameJoinControlTest.java +++ b/test/jrummikub/control/network/GameJoinControlTest.java @@ -1,6 +1,86 @@ package jrummikub.control.network; +import static org.junit.Assert.*; +import static org.junit.Assert.assertSame; + +import java.awt.Color; +import java.util.UUID; + +import jrummikub.model.GameSettings; +import jrummikub.model.PlayerSettings; +import jrummikub.model.PlayerSettings.Type; +import jrummikub.util.GameData; +import jrummikub.util.LoginData; +import jrummikub.view.ISettingsPanel.SettingsMode; +import jrummikub.view.MockView; + +import org.junit.Before; +import org.junit.Test; public class GameJoinControlTest { + LoginData loginData; + MockConnectionControl mockConnection; + NetworkControl networkControl; + GameJoinControl joinControl; + MockView view; + UUID id1 = UUID.randomUUID(); + UUID id2 = UUID.randomUUID(); + UUID id3 = UUID.randomUUID(); + + /** */ + @Before + public void setup() { + mockConnection = new MockConnectionControl(); + mockConnection.nickname = "Karl"; + view = new MockView(); + loginData = new LoginData("Karl", "server", "password", "channel"); + networkControl = new NetworkControl(loginData, mockConnection, view); + networkControl.startNetwork(); + + mockConnection.connectedEvent.emit(); + } + + /** */ + @Test + public void joinCancelTest() { + 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"); + view.settingsPanel.changePlayerColorEvent.emit(1, Color.GRAY); + assertEquals(Type.HUMAN, mockConnection.getCurrentGame().getGameSettings().getPlayerList().get(1).getType()); + assertEquals(Color.GRAY, mockConnection.playerColor); + + view.settingsPanel.backEvent.emit(); + assertTrue(view.isGameListPanelVisible); + } + + private GameData offerTestGame(UUID id, String host) { + GameSettings gsettings = new GameSettings(); + PlayerSettings psettings = new PlayerSettings(host, Color.BLACK); + psettings.setType(Type.HUMAN); + gsettings.getPlayerList().add(psettings); + PlayerSettings psettings2 = new PlayerSettings("Offen", Color.RED); + psettings2.setType(Type.VACANT); + gsettings.getPlayerList().add(psettings2); + GameData gameData = new GameData(id, gsettings, host); + mockConnection.gameOfferEvent.emit(gameData); + return gameData; + } + + private GameData offerJoinedGame(UUID id, String host, String player) { + GameSettings gsettings = new GameSettings(); + PlayerSettings psettings = new PlayerSettings(host, Color.BLACK); + psettings.setType(Type.HUMAN); + gsettings.getPlayerList().add(psettings); + PlayerSettings psettings2 = new PlayerSettings(player, Color.RED); + psettings2.setType(Type.NETWORK); + gsettings.getPlayerList().add(psettings2); + GameData gameData = new GameData(id, gsettings, host); + mockConnection.gameOfferEvent.emit(gameData); + return gameData; + } } |