summaryrefslogtreecommitdiffstats
path: root/test
diff options
context:
space:
mode:
authorIda Massow <massow@informatik.uni-luebeck.de>2011-07-02 12:21:10 +0200
committerIda Massow <massow@informatik.uni-luebeck.de>2011-07-02 12:21:10 +0200
commitaca4b2521072561e3dfb3ce0e5034f5c5d76c8b3 (patch)
treedecb7fcd36bc363b4ebb56522ca4fdb7e784029a /test
parent8facde1b30e8bd478409a6752eaeceebe6ba3e98 (diff)
downloadJRummikub-aca4b2521072561e3dfb3ce0e5034f5c5d76c8b3.tar
JRummikub-aca4b2521072561e3dfb3ce0e5034f5c5d76c8b3.zip
Tests für die Control Klasse, jetzt zu 91.9 Prozent abgedeckt
git-svn-id: svn://sunsvr01.isp.uni-luebeck.de/swproj13/trunk@601 72836036-5685-4462-b002-a69064685172
Diffstat (limited to 'test')
-rw-r--r--test/jrummikub/control/ApplicationControlTest.java136
-rw-r--r--test/jrummikub/control/SaveControlTest.java1
-rw-r--r--test/jrummikub/control/SettingsControlTest.java192
3 files changed, 303 insertions, 26 deletions
diff --git a/test/jrummikub/control/ApplicationControlTest.java b/test/jrummikub/control/ApplicationControlTest.java
new file mode 100644
index 0000000..88f365a
--- /dev/null
+++ b/test/jrummikub/control/ApplicationControlTest.java
@@ -0,0 +1,136 @@
+package jrummikub.control;
+
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertSame;
+import static org.junit.Assert.assertTrue;
+import jrummikub.util.LoginData;
+import jrummikub.view.IQuitWarningPanel.QuitMode;
+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();
+ view.getPlayerPanel().pauseEvent.emit();
+ // assertTrue(view.isPaused);
+ }
+
+ /** */
+ @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();
+ // TODO asserte was
+ }
+
+ /** */
+ @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);
+ }
+}
diff --git a/test/jrummikub/control/SaveControlTest.java b/test/jrummikub/control/SaveControlTest.java
index bcdd16a..58f3c98 100644
--- a/test/jrummikub/control/SaveControlTest.java
+++ b/test/jrummikub/control/SaveControlTest.java
@@ -66,6 +66,7 @@ public class SaveControlTest {
view.loadEvent.emit();
view.getQuitWarningPanel().quitEvent.emit();
+
view.loadFileEvent.emit(file);
file.delete();
}
diff --git a/test/jrummikub/control/SettingsControlTest.java b/test/jrummikub/control/SettingsControlTest.java
index cb527d2..72ac1b6 100644
--- a/test/jrummikub/control/SettingsControlTest.java
+++ b/test/jrummikub/control/SettingsControlTest.java
@@ -28,7 +28,6 @@ public class SettingsControlTest {
@Before
public void setup() {
settingsControl.getStartGameEvent().add(new IListener1<GameSettings>() {
-
@Override
public void handle(GameSettings value) {
gameSettings = value;
@@ -41,29 +40,30 @@ public class SettingsControlTest {
/** */
@Test
public void initialStateTest() {
- assertSame(ISettingsPanel.SettingsError.NO_ERROR, view.settingsPanel.error);
+ assertSame(ISettingsPanel.SettingsError.NO_ERROR,
+ view.settingsPanel.error);
+ for (Boolean enabled : view.settingsPanel.removePlayerButtonsEnabled) {
+ assertFalse(enabled);
+ }
+
view.settingsPanel.startGameEvent.emit();
assertNotNull(gameSettings);
assertEquals(2, gameSettings.getPlayerList().size());
assertEquals(2, view.settingsPanel.removePlayerButtonsEnabled.size());
-
- for (Boolean enabled : view.settingsPanel.removePlayerButtonsEnabled) {
- assertFalse(enabled);
- }
}
/** */
@Test
public void addPlayerTest() {
view.settingsPanel.addPlayerEvent.emit();
+ for (Boolean enabled : view.settingsPanel.removePlayerButtonsEnabled) {
+ assertTrue(enabled);
+ }
+
view.settingsPanel.startGameEvent.emit();
assertNotNull(gameSettings);
assertEquals(3, gameSettings.getPlayerList().size());
assertEquals(3, view.settingsPanel.removePlayerButtonsEnabled.size());
-
- for (Boolean enabled : view.settingsPanel.removePlayerButtonsEnabled) {
- assertTrue(enabled);
- }
}
/** */
@@ -73,15 +73,15 @@ public class SettingsControlTest {
view.settingsPanel.addPlayerEvent.emit();
}
view.settingsPanel.changeStoneSetNumberEvent.emit(8);
+ for (Boolean enabled : view.settingsPanel.removePlayerButtonsEnabled) {
+ assertTrue(enabled);
+ }
+ assertFalse(view.settingsPanel.addPlayerButtonEnabled);
+
view.settingsPanel.startGameEvent.emit();
assertNotNull(gameSettings);
assertEquals(16, gameSettings.getPlayerList().size());
assertEquals(16, view.settingsPanel.removePlayerButtonsEnabled.size());
- assertFalse(view.settingsPanel.addPlayerButtonEnabled);
-
- for (Boolean enabled : view.settingsPanel.removePlayerButtonsEnabled) {
- assertTrue(enabled);
- }
}
/** */
@@ -92,16 +92,15 @@ public class SettingsControlTest {
}
view.settingsPanel.removePlayerEvent.emit(0);
view.settingsPanel.changeStoneSetNumberEvent.emit(8);
+ for (Boolean enabled : view.settingsPanel.removePlayerButtonsEnabled) {
+ assertTrue(enabled);
+ }
+ assertTrue(view.settingsPanel.addPlayerButtonEnabled);
+
view.settingsPanel.startGameEvent.emit();
assertNotNull(gameSettings);
assertEquals(15, gameSettings.getPlayerList().size());
assertEquals(15, view.settingsPanel.removePlayerButtonsEnabled.size());
-
- assertTrue(view.settingsPanel.addPlayerButtonEnabled);
-
- for (Boolean enabled : view.settingsPanel.removePlayerButtonsEnabled) {
- assertTrue(enabled);
- }
}
/** */
@@ -109,14 +108,15 @@ public class SettingsControlTest {
public void removePlayerTest() {
view.settingsPanel.addPlayerEvent.emit();
view.settingsPanel.removePlayerEvent.emit(0);
+ for (Boolean enabled : view.settingsPanel.removePlayerButtonsEnabled) {
+ assertFalse(enabled);
+ }
+
view.settingsPanel.startGameEvent.emit();
+
assertNotNull(gameSettings);
assertEquals(2, gameSettings.getPlayerList().size());
assertEquals(2, view.settingsPanel.removePlayerButtonsEnabled.size());
-
- for (Boolean enabled : view.settingsPanel.removePlayerButtonsEnabled) {
- assertFalse(enabled);
- }
}
/** */
@@ -183,7 +183,8 @@ public class SettingsControlTest {
view.settingsPanel.changePlayerNameEvent.emit(1, name2);
assertTrue(view.settingsPanel.startButtonEnabled);
- assertSame(ISettingsPanel.SettingsError.NO_ERROR, view.settingsPanel.error);
+ assertSame(ISettingsPanel.SettingsError.NO_ERROR,
+ view.settingsPanel.error);
view.settingsPanel.startGameEvent.emit();
assertNotNull(gameSettings);
@@ -216,6 +217,20 @@ public class SettingsControlTest {
/** */
@Test
+ public void initialMeldWarningTest() {
+ assertEquals(initialSettings.getInitialMeldThreshold(),
+ view.settingsPanel.initialMeldThreshold);
+ view.settingsPanel.changeInitialMeldThresholdEvent.emit(900);
+ assertTrue(view.settingsPanel.startButtonEnabled);
+ assertSame(ISettingsPanel.SettingsError.TOO_HIGH_THRESHOLD_WARNING,
+ view.settingsPanel.error);
+
+ view.settingsPanel.startGameEvent.emit();
+ assertNotNull(gameSettings);
+ }
+
+ /** */
+ @Test
public void jokerNumberTest() {
assertEquals(initialSettings.getJokerNumber(),
view.settingsPanel.jokerNumber);
@@ -257,6 +272,39 @@ public class SettingsControlTest {
view.settingsPanel.startGameEvent.emit();
assertEquals(10, gameSettings.getHighestValue());
}
+
+ /** */
+ @Test
+ public void changeTurnTimeTest() {
+ assertEquals(initialSettings.getTotalTime(),
+ view.settingsPanel.totalTime);
+
+ view.settingsPanel.changeTimeEvent.emit(50);
+ view.settingsPanel.startGameEvent.emit();
+ assertEquals(50, gameSettings.getTotalTime());
+ }
+
+ /** */
+ @Test
+ public void changeNoLimitsTest() {
+ assertEquals(initialSettings.isNoLimits(),
+ view.settingsPanel.noLimits);
+
+ view.settingsPanel.changeNoLimitsEvent.emit(true);
+ view.settingsPanel.startGameEvent.emit();
+ assertEquals(true, gameSettings.isNoLimits());
+ }
+
+ /** */
+ @Test
+ public void changeSeeHandsTest() {
+ assertEquals(initialSettings.getSeeHandSize(),
+ view.settingsPanel.seeHandSize);
+
+ view.settingsPanel.changeSeeHandSizeEvent.emit(true);
+ view.settingsPanel.startGameEvent.emit();
+ assertEquals(true, gameSettings.getSeeHandSize());
+ }
/** */
@Test
@@ -270,6 +318,98 @@ public class SettingsControlTest {
assertEquals(new HashSet<StoneColor>(Arrays.asList(BLUE, RED, BLACK)),
gameSettings.getStoneColors());
}
+
+ /** */
+ @Test
+ public void notEnoghColorsErrorTest() {
+ assertEquals(initialSettings.getStoneColors(),
+ view.settingsPanel.stoneColors);
+
+ view.settingsPanel.changeStoneColorsEvent.emit(new HashSet<StoneColor>(
+ Arrays.asList(BLUE, RED)));
+ assertFalse(view.settingsPanel.startButtonEnabled);
+ assertSame(ISettingsPanel.SettingsError.NOT_ENOUGH_COLORS_ERROR,
+ view.settingsPanel.error);
+
+ view.settingsPanel.startGameEvent.emit();
+ assertNull(gameSettings);
+ }
+
+ /** */
+ @Test
+ public void childrenVariantTest(){
+ assertEquals(initialSettings.getInitialMeldThreshold(), view.settingsPanel.initialMeldThreshold);
+ assertEquals(initialSettings.getStoneSetNumber(), view.settingsPanel.stoneSetNumber);
+ assertEquals(initialSettings.getHighestValue(), view.settingsPanel.highestValue);
+ assertEquals(initialSettings.getNumberOfStonesDealt(), view.settingsPanel.numberOfStonesDealt);
+ assertEquals(initialSettings.getJokerNumber(), view.settingsPanel.jokerNumber);
+ assertEquals(initialSettings.getTotalTime(), view.settingsPanel.totalTime);
+ assertEquals(initialSettings.isNoLimits(), view.settingsPanel.noLimits);
+
+ view.settingsPanel.setVariantChildrenEvent.emit();
+
+ assertEquals(20, view.settingsPanel.initialMeldThreshold);
+ assertEquals(initialSettings.getStoneSetNumber(), view.settingsPanel.stoneSetNumber);
+ assertEquals(10, view.settingsPanel.highestValue);
+ assertEquals(initialSettings.getNumberOfStonesDealt(), view.settingsPanel.numberOfStonesDealt);
+ assertEquals(6, view.settingsPanel.jokerNumber);
+ assertEquals(120, view.settingsPanel.totalTime);
+ assertEquals(initialSettings.isNoLimits(), view.settingsPanel.noLimits);
+
+ view.settingsPanel.startGameEvent.emit();
+ assertNotNull(gameSettings);
+
+ assertEquals(20, gameSettings.getInitialMeldThreshold());
+ assertEquals(initialSettings.getStoneSetNumber(), gameSettings.getStoneSetNumber());
+ assertEquals(10, view.settingsPanel.highestValue);
+ assertEquals(initialSettings.getNumberOfStonesDealt(),gameSettings.getNumberOfStonesDealt());
+ assertEquals(6,gameSettings.getJokerNumber());
+ assertEquals(120, gameSettings.getTotalTime());
+ assertEquals(initialSettings.isNoLimits(), gameSettings.isNoLimits());
+ }
+
+ /** */
+ @Test
+ public void defaultVariantTest(){
+ assertEquals(initialSettings.getInitialMeldThreshold(), view.settingsPanel.initialMeldThreshold);
+ assertEquals(initialSettings.getStoneSetNumber(), view.settingsPanel.stoneSetNumber);
+ assertEquals(initialSettings.getHighestValue(), view.settingsPanel.highestValue);
+ assertEquals(initialSettings.getNumberOfStonesDealt(), view.settingsPanel.numberOfStonesDealt);
+ assertEquals(initialSettings.getJokerNumber(), view.settingsPanel.jokerNumber);
+ assertEquals(initialSettings.getTotalTime(), view.settingsPanel.totalTime);
+ assertEquals(initialSettings.isNoLimits(), view.settingsPanel.noLimits);
+
+ view.settingsPanel.setVariantChildrenEvent.emit();
+
+ assertEquals(20, view.settingsPanel.initialMeldThreshold);
+ assertEquals(initialSettings.getStoneSetNumber(), view.settingsPanel.stoneSetNumber);
+ assertEquals(10, view.settingsPanel.highestValue);
+ assertEquals(initialSettings.getNumberOfStonesDealt(), view.settingsPanel.numberOfStonesDealt);
+ assertEquals(6, view.settingsPanel.jokerNumber);
+ assertEquals(120, view.settingsPanel.totalTime);
+ assertEquals(initialSettings.isNoLimits(), view.settingsPanel.noLimits);
+
+ view.settingsPanel.setVariantDefaultEvent.emit();
+
+ assertEquals(initialSettings.getInitialMeldThreshold(), view.settingsPanel.initialMeldThreshold);
+ assertEquals(initialSettings.getStoneSetNumber(), view.settingsPanel.stoneSetNumber);
+ assertEquals(initialSettings.getHighestValue(), view.settingsPanel.highestValue);
+ assertEquals(initialSettings.getNumberOfStonesDealt(), view.settingsPanel.numberOfStonesDealt);
+ assertEquals(initialSettings.getJokerNumber(), view.settingsPanel.jokerNumber);
+ assertEquals(initialSettings.getTotalTime(), view.settingsPanel.totalTime);
+ assertEquals(initialSettings.isNoLimits(), view.settingsPanel.noLimits);
+
+ view.settingsPanel.startGameEvent.emit();
+ assertNotNull(gameSettings);
+
+ assertEquals(initialSettings.getInitialMeldThreshold(), gameSettings.getInitialMeldThreshold());
+ assertEquals(initialSettings.getStoneSetNumber(), gameSettings.getStoneSetNumber());
+ assertEquals(initialSettings.getHighestValue(), gameSettings.getHighestValue());
+ assertEquals(initialSettings.getNumberOfStonesDealt(), gameSettings.getNumberOfStonesDealt());
+ assertEquals(initialSettings.getJokerNumber(), gameSettings.getJokerNumber());
+ assertEquals(initialSettings.getTotalTime(),gameSettings.getTotalTime());
+ assertEquals(initialSettings.isNoLimits(), gameSettings.isNoLimits());
+ }
/** */
@Test