From c7069227f324d42e3c1f2456f1ff6876455379fd Mon Sep 17 00:00:00 2001 From: Ida Massow Date: Sun, 19 Jun 2011 01:14:14 +0200 Subject: =?UTF-8?q?Tests=20f=C3=BCr=20networkControl=20fertig?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit git-svn-id: svn://sunsvr01.isp.uni-luebeck.de/swproj13/trunk@476 72836036-5685-4462-b002-a69064685172 --- .../control/network/NetworkControlTest.java | 139 +++++++++++++++++++++ 1 file changed, 139 insertions(+) create mode 100644 test/jrummikub/control/network/NetworkControlTest.java (limited to 'test/jrummikub/control') diff --git a/test/jrummikub/control/network/NetworkControlTest.java b/test/jrummikub/control/network/NetworkControlTest.java new file mode 100644 index 0000000..6cbd3d0 --- /dev/null +++ b/test/jrummikub/control/network/NetworkControlTest.java @@ -0,0 +1,139 @@ +package jrummikub.control.network; + +import static org.junit.Assert.*; +import static org.junit.Assert.assertEquals; + +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.MockView; +import jrummikub.view.ISettingsPanel.SettingsMode; + +import org.junit.Before; +import org.junit.Test; + +public class NetworkControlTest { + LoginData loginData; + MockConnectionControl mockConnection; + NetworkControl networkControl; + 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(); + } + + /** */ + @Test + public void connectedTest() { + mockConnection.connectedEvent.emit(); + assertTrue(view.isGameListPanelVisible); + assertEquals("channel", view.gameListPanel.channelName); + } + + /** */ + @Test + public void offeredGameTest() { + mockConnection.connectedEvent.emit(); + offerTestGame(id1, "Berta"); + + assertEquals(1, 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()); + } + + /** */ + @Test + public void offerGameTest() { + mockConnection.connectedEvent.emit(); + view.gameListPanel.openNewGameEvent.emit(); + + assertTrue(view.isSettingsPanelVisible); + assertEquals(SettingsMode.NETWORK_SETUP, + view.settingsPanel.settingsMode); + + view.settingsPanel.addPlayerEvent.emit(); + + view.settingsPanel.offerGameEvent.emit(); + + assertTrue(view.isSettingsPanelVisible); + assertEquals(SettingsMode.NETWORK_OFFER, + view.settingsPanel.settingsMode); + } + + /** */ + @Test + public void joinGameTest() { + mockConnection.connectedEvent.emit(); + GameData data = offerTestGame(id1, "Berta"); + view.gameListPanel.joinEvent.emit(data); + assertSame(data, mockConnection.joinedGame); + mockConnection.gameJoinAckEvent.emit(true); + assertTrue(view.isSettingsPanelVisible); + assertEquals(SettingsMode.NETWORK_JOIN, view.settingsPanel.settingsMode); + } + + /** */ + @Test + public void withdrawnGameTest() { + 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.gameWithdrawalEvent.emit(id1); + 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(); + + view.gameListPanel.cancelEvent.emit(); + assertFalse(view.isGameListPanelVisible); + assertFalse(mockConnection.connected); + } + + 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); + psettings.setType(Type.VACANT); + gsettings.getPlayerList().add(psettings2); + GameData gameData = new GameData(id, gsettings, host); + mockConnection.gameOfferEvent.emit(gameData); + return gameData; + } + +} -- cgit v1.2.3