From 3cd6dee363700133ec827ea9fdb40ae302b35459 Mon Sep 17 00:00:00 2001 From: Jannis Harder Date: Wed, 4 May 2011 17:33:46 +0200 Subject: Implemented first turn control tests git-svn-id: svn://sunsvr01.isp.uni-luebeck.de/swproj13/trunk@111 72836036-5685-4462-b002-a69064685172 --- test/jrummikub/control/TurnControlTest.java | 90 +++++++++++++++++++++++++++++ 1 file changed, 90 insertions(+) create mode 100644 test/jrummikub/control/TurnControlTest.java 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); + } +} -- cgit v1.2.3