summaryrefslogtreecommitdiffstats
path: root/test/jrummikub/control/network/GameOfferControlTest.java
blob: 635ea5718fd4fdc7234d255a86305993ef1d577b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
package jrummikub.control.network;

import static org.junit.Assert.*;

import java.awt.Color;
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 game offer control
 */
public class GameOfferControlTest {
	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 withdrawGameTest() {
		view.gameListPanel.openNewGameEvent.emit();
		assertFalse(view.isGameListPanelVisible);
		assertTrue(view.isSettingsPanelVisible);
		assertEquals(SettingsMode.NETWORK_SETUP,
				view.settingsPanel.settingsMode);
		view.settingsPanel.offerGameEvent.emit();
		assertEquals(SettingsMode.NETWORK_OFFER,
				view.settingsPanel.settingsMode);
		view.settingsPanel.changePlayerColorEvent.emit(0, Color.PINK);
		assertEquals(Color.PINK, mockConnection.playerColor);
		view.settingsPanel.backEvent.emit();
		assertFalse(view.isSettingsPanelVisible);
		assertTrue(view.isGameListPanelVisible);
	}

	/** */
	@Test
	public void getJoinLeaveTest() {
		view.gameListPanel.openNewGameEvent.emit();
		view.settingsPanel.offerGameEvent.emit();

		mockConnection.gameJoinEvent.emit("Berta");

		assertEquals("Berta", mockConnection.offeredGame.getGameSettings()
				.getPlayerList().get(1).getName());
		assertSame(Type.NETWORK, mockConnection.offeredGame.getGameSettings()
				.getPlayerList().get(1).getType());

		mockConnection.changeColorEvent.emit("Berta", Color.BLUE);

		assertEquals(Color.BLUE, mockConnection.offeredGame.getGameSettings()
				.getPlayerList().get(1).getColor());

		mockConnection.gameLeaveEvent.emit("Berta");

		assertEquals("Offen", mockConnection.offeredGame.getGameSettings()
				.getPlayerList().get(1).getName());
		assertSame(Type.VACANT, mockConnection.offeredGame.getGameSettings()
				.getPlayerList().get(1).getType());
	}

}