summaryrefslogtreecommitdiffstats
path: root/test
diff options
context:
space:
mode:
Diffstat (limited to 'test')
-rw-r--r--test/jrummikub/control/TurnControlTest.java90
1 files changed, 90 insertions, 0 deletions
diff --git a/test/jrummikub/control/TurnControlTest.java b/test/jrummikub/control/TurnControlTest.java
new file mode 100644
index 0000000..8ba7bc4
--- /dev/null
+++ b/test/jrummikub/control/TurnControlTest.java
@@ -0,0 +1,90 @@
+package jrummikub.control;
+
+import java.util.Collection;
+
+import jrummikub.model.Stone;
+import jrummikub.util.Event;
+import jrummikub.util.IEvent;
+import jrummikub.util.IListener;
+import jrummikub.view.IHandPanel;
+import jrummikub.view.IPlayerPanel;
+import jrummikub.view.ITablePanel;
+import jrummikub.view.IView;
+import jrummikub.view.MockView;
+
+import org.junit.Before;
+import org.junit.Test;
+import static org.junit.Assert.*;
+
+public class TurnControlTest {
+
+ class MockTimer implements ITurnTimer {
+ boolean timerRunning;
+
+ @Override
+ public void startTimer() {
+ timerRunning = true;
+ }
+
+ @Override
+ public void stopTimer() {
+ timerRunning = false;
+ }
+
+ @Override
+ public IEvent getTimeRunOutEvent() {
+ return null;
+ }
+
+ }
+
+ MockView mockView;
+ MockTimer mockTimer;
+ boolean eventFired;
+
+ @Before
+ public void setUp() {
+ mockView = new MockView();
+ mockTimer = new MockTimer();
+ }
+
+ @Test
+ public void viewEndOfTurn() {
+ eventFired = false;
+ mockTimer.timerRunning = true;
+ TurnControl testControl = new TurnControl(null, null, mockView, mockTimer);
+
+ testControl.getEndOfTurnEvent().add(new IListener() {
+
+ @Override
+ public void handle() {
+ eventFired = true;
+ }
+ });
+
+ mockView.playerPanel.endTurnEvent.emit();
+
+ assertTrue(eventFired);
+ assertFalse(mockTimer.timerRunning);
+ }
+
+ @Test
+ public void timerEndOfTurn() {
+ eventFired = false;
+ mockTimer.timerRunning = true;
+ TurnControl testControl = new TurnControl(null, null, mockView, mockTimer);
+
+ testControl.getEndOfTurnEvent().add(new IListener() {
+
+ @Override
+ public void handle() {
+ eventFired = true;
+ }
+ });
+
+ mockView.playerPanel.endTurnEvent.emit();
+
+ assertTrue(eventFired);
+ assertFalse(mockTimer.timerRunning);
+ }
+}