package jrummikub.control.network; import static org.junit.Assert.*; import java.util.UUID; import jrummikub.model.PlayerSettings.Type; import jrummikub.util.LoginData; import jrummikub.view.ISettingsPanel.SettingsMode; import jrummikub.view.MockView; import org.junit.Before; import org.junit.Test; /** * Test class for network settings control */ public class NetworkSettingsControlTest { 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, null, view); networkControl.startNetwork(); mockConnection.connectedEvent.emit(); } /** */ @Test public void networkSettingsTest() { view.gameListPanel.openNewGameEvent.emit(); assertFalse(view.isGameListPanelVisible); assertTrue(view.isSettingsPanelVisible); assertEquals(SettingsMode.NETWORK_SETUP, view.settingsPanel.settingsMode); view.settingsPanel.addPlayerEvent.emit(); view.settingsPanel.addPlayerEvent.emit(); view.settingsPanel.changePlayerTypeEvent.emit(1, Type.VACANT); view.settingsPanel.changePlayerTypeEvent.emit(2, Type.COMPUTER); view.settingsPanel.changeJokerNumberEvent.emit(4); view.settingsPanel.changeHighestValueEvent.emit(10); view.settingsPanel.offerGameEvent.emit(); assertEquals(SettingsMode.NETWORK_OFFER, view.settingsPanel.settingsMode); assertEquals(4, mockConnection.offeredGame.getGameSettings() .getPlayerList().size()); assertSame(Type.VACANT, mockConnection.offeredGame.getGameSettings() .getPlayerList().get(1).getType()); assertSame(Type.COMPUTER, mockConnection.offeredGame.getGameSettings() .getPlayerList().get(2).getType()); assertSame(Type.VACANT, mockConnection.offeredGame.getGameSettings() .getPlayerList().get(3).getType()); assertEquals(4, mockConnection.offeredGame.getGameSettings() .getJokerNumber()); assertEquals(10, mockConnection.offeredGame.getGameSettings() .getHighestValue()); } }