summaryrefslogtreecommitdiffstats
path: root/test/jrummikub/control/ApplicationControlTest.java
blob: c0526505bec9e95a178fa1ad5442af67406237ff (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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
package jrummikub.control;

import static org.junit.Assert.*;
import jrummikub.util.LoginData;
import jrummikub.view.IQuitWarningPanel.QuitMode;
import jrummikub.view.IView.BottomPanelType;
import jrummikub.view.MockView;

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

/**
 * Tests for the testable parts of the application control
 */
public class ApplicationControlTest {
	ApplicationControl testAppControl;
	MockView view;

	/** */
	@Before
	public void setup() {
		view = new MockView();
	}

	/** */
	@Test
	public void enableSaving() {
		assertFalse(view.savingEnabled);
		testAppControl = new ApplicationControl(view);
		testAppControl.startApplication();
		assertTrue(view.isSettingsPanelVisible);
		view.settingsPanel.startGameEvent.emit();
		assertFalse(view.isSettingsPanelVisible);
		assertTrue(view.savingEnabled);
	}

	/** */
	@Test
	public void pauseTest() {
		testAppControl = new ApplicationControl(view);
		testAppControl.startApplication();
		view.settingsPanel.startGameEvent.emit();
		assertSame(BottomPanelType.START_TURN_PANEL, view.bottomPanelType);
		view.startTurnEvent.emit();
		assertSame(BottomPanelType.HUMAN_HAND_PANEL, view.bottomPanelType);
		view.pauseEvent.emit();
		assertTrue(view.pauseModeEnabled);
	}

	/** */
	@Test
	public void quitWarningTest() {
		testAppControl = new ApplicationControl(view);
		testAppControl.startApplication();
		view.settingsPanel.startGameEvent.emit();
		view.quitEvent.emit();
		assertSame(QuitMode.QUIT_PROCESS, view.quitWarningPanel.quitMode);
		assertTrue(view.isQuitWarningPanelVisible);
	}

	/** */
	@Test
	public void networkTest() {
		testAppControl = new ApplicationControl(view);
		testAppControl.startApplication();

		view.networkGameEvent.emit();
		assertTrue(view.isLoginPanelVisible);
	}

	/** */
	@Test
	public void networkFromRunningGameTest() {
		testAppControl = new ApplicationControl(view);
		testAppControl.startApplication();
		view.settingsPanel.startGameEvent.emit();

		view.networkGameEvent.emit();
		assertTrue(view.isQuitWarningPanelVisible);
		assertSame(QuitMode.QUIT_GAME, view.getQuitWarningPanel().getQuitMode());
		view.getQuitWarningPanel().quitEvent.emit();
		assertTrue(view.isLoginPanelVisible);
	}

	/** */
	@Test
	public void newGameFromNetworkTest() {
		testAppControl = new ApplicationControl(view);
		testAppControl.startApplication();

		view.networkGameEvent.emit();
		assertTrue(view.isLoginPanelVisible);

		LoginData data = new LoginData("Horst", "server", "horstspw", "channel");
		view.loginPanel.loginEvent.emit(data);
		assertTrue(view.isConnectPanelVisible);
		view.menuNewGameEvent.emit();
		assertTrue(view.isQuitWarningPanelVisible);
		assertSame(QuitMode.QUIT_GAME, view.getQuitWarningPanel().getQuitMode());
		view.getQuitWarningPanel().quitEvent.emit();

		assertFalse(view.isConnectPanelVisible);
		assertTrue(view.isSettingsPanelVisible);
	}

	/** */
	@Test
	public void loadTest() {
		testAppControl = new ApplicationControl(view);
		testAppControl.startApplication();

		view.loadEvent.emit();
		assertFalse(view.isQuitWarningPanelVisible);
	}

	/** */
	@Test
	public void loadFromRunningGameTest() {
		testAppControl = new ApplicationControl(view);
		testAppControl.startApplication();
		view.settingsPanel.startGameEvent.emit();

		view.loadEvent.emit();
		assertTrue(view.isQuitWarningPanelVisible);
		assertSame(QuitMode.QUIT_GAME, view.getQuitWarningPanel().getQuitMode());
		view.getQuitWarningPanel().quitEvent.emit();
		assertFalse(view.isQuitWarningPanelVisible);
		assertTrue(view.loadCalled);
	}

	/** */
	@Test
	public void newGameFromRunningGameTest() {
		testAppControl = new ApplicationControl(view);
		testAppControl.startApplication();
		view.settingsPanel.startGameEvent.emit();

		view.menuNewGameEvent.emit();
		assertTrue(view.isQuitWarningPanelVisible);
		assertSame(QuitMode.QUIT_GAME, view.getQuitWarningPanel().getQuitMode());
		view.getQuitWarningPanel().cancelEvent.emit();
		assertFalse(view.isQuitWarningPanelVisible);

		view.menuNewGameEvent.emit();
		assertTrue(view.isQuitWarningPanelVisible);
		assertSame(QuitMode.QUIT_GAME, view.getQuitWarningPanel().getQuitMode());
		view.getQuitWarningPanel().quitEvent.emit();
		assertTrue(view.isSettingsPanelVisible);
	}
}