summaryrefslogtreecommitdiffstats
path: root/test/jrummikub/control
diff options
context:
space:
mode:
Diffstat (limited to 'test/jrummikub/control')
-rw-r--r--test/jrummikub/control/RoundControlTest.java143
1 files changed, 133 insertions, 10 deletions
diff --git a/test/jrummikub/control/RoundControlTest.java b/test/jrummikub/control/RoundControlTest.java
index bc0bb3d..7d13ff0 100644
--- a/test/jrummikub/control/RoundControlTest.java
+++ b/test/jrummikub/control/RoundControlTest.java
@@ -1,7 +1,16 @@
package jrummikub.control;
-import static org.junit.Assert.*;
-import jrummikub.model.GameState;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNotSame;
+import static org.junit.Assert.assertSame;
+import static org.junit.Assert.assertTrue;
+import jrummikub.model.MockGameState;
+import jrummikub.model.MockTable;
+import jrummikub.model.Position;
+import jrummikub.model.Stone;
+import jrummikub.model.StoneSet;
import jrummikub.view.MockView;
import org.junit.Before;
@@ -9,13 +18,13 @@ import org.junit.Test;
public class RoundControlTest {
private MockView view;
- private GameState testGameState;
+ private MockGameState testGameState;
private RoundControl testRound;
@Before
public void setup() {
view = new MockView();
- testGameState = new GameState();
+ testGameState = new MockGameState();
testRound = new RoundControl(testGameState, view);
}
@@ -27,6 +36,23 @@ public class RoundControlTest {
}
}
+ private void checkTurnStartSetUp() {
+ assertNotNull(view.currentPlayerName);
+ assertNotNull(view.getTablePanel().leftPlayerName);
+ assertNotNull(view.getTablePanel().topPlayerName);
+ assertNotNull(view.getTablePanel().rightPlayerName);
+ assertTrue(view.displayStartTurnPanel);
+ assertFalse(view.startTurnEvent.listeners.isEmpty());
+ }
+
+ private void resetTurnStart() {
+ view.currentPlayerName = null;
+ view.getTablePanel().leftPlayerName = null;
+ view.getTablePanel().topPlayerName = null;
+ view.getTablePanel().rightPlayerName = null;
+ view.displayStartTurnPanel = false;
+ }
+
@Test
public void testDeal() {
testRound.deal();
@@ -38,11 +64,108 @@ public class RoundControlTest {
testRound.startRound();
checkCorrectlyDealed();
- assertNotNull(view.currentPlayerName);
- assertNotNull(view.getTablePanel().leftPlayerName);
- assertNotNull(view.getTablePanel().topPlayerName);
- assertNotNull(view.getTablePanel().rightPlayerName);
- assertTrue(view.displayStartTurnPanel);
- assertFalse(view.startTurnEvent.listeners.isEmpty());
+ checkTurnStartSetUp();
+ }
+
+ @Test
+ public void testTableValidHandChanged() {
+ testRound.startRound();
+ MockTable oldTable = testGameState.table;
+ MockTable newTable = new MockTable();
+ newTable.valid = true;
+ oldTable.clonedTable = newTable;
+
+ view.startTurnEvent.emit();
+ assertFalse(view.displayStartTurnPanel);
+ testGameState.players.get(0).hand.stones.remove(0);
+ resetTurnStart();
+ view.getPlayerPanel().endTurnEvent.emit();
+
+ assertNotSame(oldTable, testGameState.table);
+ assertSame(newTable, testGameState.table);
+ assertEquals(1, testGameState.activePlayer);
+
+ checkTurnStartSetUp();
+ }
+
+ @Test
+ public void testTableInvalidHandChanged() {
+ testRound.startRound();
+ MockTable oldTable = testGameState.table;
+ MockTable newTable = new MockTable();
+ newTable.valid = false;
+ oldTable.clonedTable = newTable;
+
+ view.startTurnEvent.emit();
+ assertFalse(view.displayStartTurnPanel);
+ Stone stone = testGameState.players.get(0).hand.stones.remove(0);
+ newTable.drop(new StoneSet(stone), new Position(0, 0));
+ resetTurnStart();
+ view.getPlayerPanel().endTurnEvent.emit();
+
+ assertSame(oldTable, testGameState.table);
+ assertNotSame(newTable, testGameState.table);
+ assertEquals(1, testGameState.activePlayer);
+ assertEquals(14 + 3, testGameState.players.get(0).hand.getSize());
+ checkTurnStartSetUp();
+ }
+
+ @Test
+ public void testTableValidHandUnchanged() {
+ testRound.startRound();
+ MockTable oldTable = testGameState.table;
+ MockTable newTable = new MockTable();
+ newTable.valid = true;
+ oldTable.clonedTable = newTable;
+
+ view.startTurnEvent.emit();
+ assertFalse(view.displayStartTurnPanel);
+ resetTurnStart();
+ view.getPlayerPanel().endTurnEvent.emit();
+
+ assertEquals(14 + 1, testGameState.players.get(0).hand.getSize());
+ assertEquals(1, testGameState.activePlayer);
+ assertSame(newTable, testGameState.table);
+ assertNotSame(oldTable, testGameState.table);
+
+ checkTurnStartSetUp();
+ }
+
+ @Test
+ public void testTableInvalidHandUnchanged() {
+ testRound.startRound();
+ MockTable oldTable = testGameState.table;
+ MockTable newTable = new MockTable();
+ newTable.valid = false;
+ oldTable.clonedTable = newTable;
+
+ view.startTurnEvent.emit();
+ assertFalse(view.displayStartTurnPanel);
+ resetTurnStart();
+ view.getPlayerPanel().endTurnEvent.emit();
+
+ assertEquals(14 + 1, testGameState.players.get(0).hand.getSize());
+ assertEquals(1, testGameState.activePlayer);
+ assertNotSame(newTable, testGameState.table);
+ assertSame(oldTable, testGameState.table);
+
+ checkTurnStartSetUp();
+ }
+
+ @Test
+ public void testWinning() {
+ testRound.startRound();
+ MockTable oldTable = testGameState.table;
+ MockTable newTable = new MockTable();
+ newTable.valid = true;
+ oldTable.clonedTable = newTable;
+
+ view.startTurnEvent.emit();
+ assertFalse(view.displayStartTurnPanel);
+ testGameState.players.get(0).hand.stones.clear();
+ resetTurnStart();
+ view.getPlayerPanel().endTurnEvent.emit();
+
+ assertTrue(view.displayWinPanel);
}
}