diff options
author | Matthias Schiffer <mschiffer@universe-factory.net> | 2011-07-04 23:53:01 +0200 |
---|---|---|
committer | Matthias Schiffer <mschiffer@universe-factory.net> | 2011-07-04 23:53:01 +0200 |
commit | cabf7868e2f476577c6f4c2c2f001ca556b11bc1 (patch) | |
tree | f30e8e84e504d4b3f2627566d6531f294a5c2eb0 | |
parent | f6a94e553f89de1544e8689db7e19709cba2b9fb (diff) | |
download | JRummikub-cabf7868e2f476577c6f4c2c2f001ca556b11bc1.tar JRummikub-cabf7868e2f476577c6f4c2c2f001ca556b11bc1.zip |
Added NetworkTurnControlTest
git-svn-id: svn://sunsvr01.isp.uni-luebeck.de/swproj13/trunk@606 72836036-5685-4462-b002-a69064685172
-rw-r--r-- | src/jrummikub/control/network/NetworkTurnControl.java | 12 | ||||
-rw-r--r-- | test/jrummikub/control/network/NetworkTurnControlTest.java | 91 |
2 files changed, 91 insertions, 12 deletions
diff --git a/src/jrummikub/control/network/NetworkTurnControl.java b/src/jrummikub/control/network/NetworkTurnControl.java index 0f9c478..c07144b 100644 --- a/src/jrummikub/control/network/NetworkTurnControl.java +++ b/src/jrummikub/control/network/NetworkTurnControl.java @@ -4,8 +4,6 @@ import jrummikub.control.RoundControl.InvalidTurnInfo; import jrummikub.control.turn.AbstractTurnControl; import jrummikub.model.IRoundState; import jrummikub.model.ITable; -import jrummikub.util.Event1; -import jrummikub.util.IEvent1; import jrummikub.util.IListener; import jrummikub.util.IListener1; import jrummikub.util.IListener2; @@ -15,7 +13,6 @@ import jrummikub.util.IListener2; */ public class NetworkTurnControl extends AbstractTurnControl { private IConnectionControl connectionControl; - private Event1<IRoundState> stateUpdateEvent = new Event1<IRoundState>(); /** * Creates new network turn control @@ -27,15 +24,6 @@ public class NetworkTurnControl extends AbstractTurnControl { this.connectionControl = connectionControl; } - /** - * The state update event is emitted when the state is sent into the network - * - * @return the event - */ - public IEvent1<IRoundState> getStateUpdateEvent() { - return stateUpdateEvent; - } - @Override public void doStartTurn() { connections.add(connectionControl.getTableUpdateEvent().add( diff --git a/test/jrummikub/control/network/NetworkTurnControlTest.java b/test/jrummikub/control/network/NetworkTurnControlTest.java new file mode 100644 index 0000000..9ed4bdd --- /dev/null +++ b/test/jrummikub/control/network/NetworkTurnControlTest.java @@ -0,0 +1,91 @@ +package jrummikub.control.network; + +import static org.junit.Assert.*; + +import java.awt.Color; + +import jrummikub.control.turn.ITurnControl.TurnInfo; +import jrummikub.control.turn.TurnMode; +import jrummikub.model.GameSettings; +import jrummikub.model.GameState; +import jrummikub.model.PlayerSettings; +import jrummikub.model.PlayerSettings.Type; +import jrummikub.model.Position; +import jrummikub.model.RoundState; +import jrummikub.model.Stone; +import jrummikub.model.StoneColor; +import jrummikub.model.StoneSet; +import jrummikub.model.Table; +import jrummikub.util.IListener; +import jrummikub.util.Pair; +import jrummikub.view.MockView; + +import org.junit.Before; +import org.junit.Test; + +public class NetworkTurnControlTest { + private MockConnectionControl connectionControl; + private MockView view; + + private GameSettings gameSettings; + private RoundState roundState; + + private NetworkTurnControl turnControl; + + private boolean fired; + + @Before + public void setup() { + gameSettings = new GameSettings(); + + gameSettings.getPlayerList().add(new PlayerSettings("Ida", Color.RED)); + gameSettings.getPlayerList().get(0).setType(Type.NETWORK); + gameSettings.getPlayerList().add( + new PlayerSettings("Matthias", Color.YELLOW)); + gameSettings.getPlayerList().get(1).setType(Type.NETWORK); + + roundState = new RoundState(gameSettings, new GameState()); + + view = new MockView(); + connectionControl = new MockConnectionControl(); + turnControl = new NetworkTurnControl(connectionControl); + } + + @Test + public void testTableUpdate() { + turnControl.setup(new TurnInfo(roundState, TurnMode.NORMAL_TURN, true), + gameSettings, view); + turnControl.startTurn(); + + Table table = new Table(gameSettings); + StoneSet set = new StoneSet(new Stone(StoneColor.RED)); + + table.drop(set, new Position(0, 0)); + connectionControl.tableUpdateEvent.emit(table); + + int n = 0; + for (Pair<StoneSet, Position> entry : view.tablePanel.stoneSets) { + assertSame(entry.getFirst(), set); + n++; + } + assertEquals(1, n); + } + + @Test + public void testRedeal() { + turnControl.getRedealEvent().add(new IListener() { + @Override + public void handle() { + fired = true; + } + }); + + turnControl.setup(new TurnInfo(roundState, TurnMode.MAY_REDEAL, true), + gameSettings, view); + turnControl.startTurn(); + + connectionControl.redealEvent.emit(); + + assertTrue(fired); + } +} |