summaryrefslogtreecommitdiffstats
path: root/test/jrummikub/control/network/NetworkGameControlTest.java
blob: ea0dabebe68d2de130da8a23ed524d48cf468814 (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
package jrummikub.control.network;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;

import java.awt.Color;

import jrummikub.control.SaveControl;
import jrummikub.model.GameSettings;
import jrummikub.model.PlayerSettings;
import jrummikub.util.IListener;
import jrummikub.view.IView.BottomPanelType;
import jrummikub.view.MockView;

import org.junit.Before;
import org.junit.Test;

/**
 * Tests for the network game control
 */
public class NetworkGameControlTest {

	public NetworkGameControl hostControl, clientControl;
	public GameSettings settings;
	public MockView view;
	public MockConnectionControl connection;
	public boolean fired;

	/** */
	@Before
	public void setUp() {
		settings = new GameSettings();
		settings.getPlayerList().add(new PlayerSettings("Foobar", Color.BLACK));
		PlayerSettings player = new PlayerSettings("Fooblubb", Color.BLACK);
		player.setType(PlayerSettings.Type.NETWORK);
		settings.getPlayerList().add(player);
		view = new MockView();
		connection = new MockConnectionControl();
		hostControl = new NetworkGameControl(settings, new SaveControl(view),
				view, connection, true);
		clientControl = new NetworkGameControl(settings, new SaveControl(view),
				view, connection, false);
		fired = false;
	}

	/** */
	@Test
	public void testStart() {
		clientControl.startGame();
		assertFalse(connection.startRoundCalled);
		hostControl.startGame();
		assertTrue(connection.startRoundCalled);
	}

	/** */
	@Test
	public void testParticipantLeft() {

		connection.participantLeftEvent.emit("Horst");
		assertTrue(BottomPanelType.NETWORK_CONNECTION_LOST_PANEL != view.bottomPanelType);
		connection.participantLeftEvent.emit("Fooblubb");
		assertEquals(BottomPanelType.NETWORK_CONNECTION_LOST_PANEL,
				view.bottomPanelType);
		
		hostControl.getBackEvent().add(new IListener() {
			@Override
			public void handle() {
				fired = true;
			}
		});
		
		view.newGameEvent.emit();
		assertTrue(fired);
		
	}

}