summaryrefslogtreecommitdiffstats
path: root/test/jrummikub/control
diff options
context:
space:
mode:
Diffstat (limited to 'test/jrummikub/control')
-rw-r--r--test/jrummikub/control/RoundControlTest.java4
-rw-r--r--test/jrummikub/control/network/NetworkRoundControlTest.java128
-rw-r--r--test/jrummikub/control/turn/AIControlTest.java29
-rw-r--r--test/jrummikub/control/turn/TurnControlTest.java88
4 files changed, 187 insertions, 62 deletions
diff --git a/test/jrummikub/control/RoundControlTest.java b/test/jrummikub/control/RoundControlTest.java
index 02eb3b8..d37a370 100644
--- a/test/jrummikub/control/RoundControlTest.java
+++ b/test/jrummikub/control/RoundControlTest.java
@@ -919,7 +919,7 @@ public class RoundControlTest {
testRound.startRound();
Hand hand = new Hand();
for (int i = 0; i < 6; i++) {
- hand.drop(new Stone(i / 2, RED), new Position(0, 0));
+ hand.drop(new Stone(i / 2 + 1, RED), new Position(0, 0));
}
testRoundState.players.get(0).hand = hand;
testRound.clonedHand = (IHand) hand.clone();
@@ -929,6 +929,6 @@ public class RoundControlTest {
view.playerPanel.endTurnEvent.emit();
view.startTurnEvent.emit();
}
- assertEquals( TurnMode.NORMAL_TURN, view.playerPanel.turnMode);
+ assertEquals(TurnMode.NORMAL_TURN, view.playerPanel.turnMode);
}
}
diff --git a/test/jrummikub/control/network/NetworkRoundControlTest.java b/test/jrummikub/control/network/NetworkRoundControlTest.java
new file mode 100644
index 0000000..c8eb54d
--- /dev/null
+++ b/test/jrummikub/control/network/NetworkRoundControlTest.java
@@ -0,0 +1,128 @@
+package jrummikub.control.network;
+
+import static org.junit.Assert.*;
+
+import java.awt.Color;
+
+import jrummikub.control.turn.AIControl;
+import jrummikub.model.GameSettings;
+import jrummikub.model.IPlayer;
+import jrummikub.model.IRoundState;
+import jrummikub.model.ITable;
+import jrummikub.model.PlayerSettings;
+import jrummikub.model.PlayerSettings.Type;
+import jrummikub.model.RoundState;
+import jrummikub.model.Stone;
+import jrummikub.util.IListener1;
+import jrummikub.view.MockView;
+
+import org.junit.Before;
+import org.junit.Test;
+
+public class NetworkRoundControlTest {
+ private MockConnectionControl connectionControl;
+ private MockView view;
+ private RoundState testRoundState;
+ private NetworkRoundControl testRound;
+
+ private GameSettings gameSettings;
+
+ private boolean turnStarted;
+ private boolean turnEnded;
+
+ @Before
+ public void setup() {
+ AIControl.useBackgroundThread = false;
+
+ gameSettings = new GameSettings();
+
+ gameSettings.getPlayerList().add(new PlayerSettings("Ida", Color.RED));
+ gameSettings.getPlayerList().add(
+ new PlayerSettings("Matthias", Color.YELLOW));
+ gameSettings.getPlayerList().add(new PlayerSettings("Jannis", Color.GREEN));
+ gameSettings.getPlayerList().add(new PlayerSettings("Bennet", Color.BLACK));
+
+ gameSettings.getPlayerList().get(1).setType(Type.COMPUTER);
+ gameSettings.getPlayerList().get(2).setType(Type.NETWORK);
+ gameSettings.getPlayerList().get(3).setType(Type.COMPUTER);
+ testRoundState = new RoundState(gameSettings);
+
+ view = new MockView();
+ connectionControl = new MockConnectionControl();
+ }
+
+ @Test
+ public void testHostRound() {
+ testRound = new NetworkRoundControl(testRoundState, view, connectionControl, true);
+
+ connectionControl.getTurnStartEvent().add(new IListener1<IRoundState>() {
+ @Override
+ public void handle(IRoundState roundState) {
+ assertSame(testRoundState, roundState);
+
+ turnStarted = true;
+ }
+ });
+
+ connectionControl.getTurnEndEvent().add(new IListener1<ITable>() {
+ @Override
+ public void handle(ITable table) {
+ turnEnded = true;
+ }
+ });
+
+ turnStarted = false;
+ turnEnded = false;
+
+ testRound.startRound();
+ assertTrue(turnStarted);
+ turnStarted = false;
+
+ assertEquals(4, testRoundState.getPlayerCount());
+ for (int i = 0; i < 4; ++i) {
+ IPlayer player = testRoundState.getNthPlayer(i);
+ assertSame(gameSettings.getPlayerList().get(i), player.getPlayerSettings());
+ assertEquals(gameSettings.getNumberOfStonesDealt(), player.getHand().getSize());
+ }
+ assertSame(testRoundState.getNthPlayer(0), testRoundState.getActivePlayer());
+
+ for (int i = 0; i < 4; ++i) {
+ IPlayer player = testRoundState.getNthPlayer(i);
+
+ while (player.getHand().getSize() > 1) {
+ Stone stone = player.getHand().iterator().next().getFirst();
+ player.getHand().pickUp(stone);
+ }
+ }
+
+ assertFalse(turnEnded);
+ view.playerPanel.endTurnEvent.emit();
+ assertTrue(turnEnded);
+ turnEnded = false;
+ turnStarted = false;
+
+ assertSame(testRoundState.getNthPlayer(2), testRoundState.getActivePlayer());
+
+ connectionControl.turnStartEvent.emit(testRoundState);
+ assertTrue(turnStarted);
+ turnStarted = false;
+
+ assertFalse(turnEnded);
+ connectionControl.turnEndEvent.emit(testRoundState.getTable());
+ assertTrue(turnEnded);
+ turnEnded = false;
+
+ assertSame(testRoundState.getNthPlayer(3), testRoundState.getActivePlayer());
+
+ connectionControl.turnStartEvent.emit(testRoundState);
+ assertTrue(turnStarted);
+ turnStarted = false;
+
+ assertFalse(turnEnded);
+ connectionControl.turnEndEvent.emit(testRoundState.getTable());
+ assertTrue(turnEnded);
+ turnEnded = false;
+
+ assertSame(testRoundState.getNthPlayer(0), testRoundState.getActivePlayer());
+ }
+}
diff --git a/test/jrummikub/control/turn/AIControlTest.java b/test/jrummikub/control/turn/AIControlTest.java
index 6da4b00..a8974ea 100644
--- a/test/jrummikub/control/turn/AIControlTest.java
+++ b/test/jrummikub/control/turn/AIControlTest.java
@@ -16,6 +16,7 @@ import jrummikub.model.Stone;
import jrummikub.model.StoneColor;
import jrummikub.model.Table;
import jrummikub.util.IListener;
+import jrummikub.util.IListener1;
import jrummikub.view.MockView;
import org.junit.Before;
@@ -47,10 +48,9 @@ public class AIControlTest {
turnEnded = false;
redealt = false;
- aiControl.getEndOfTurnEvent().add(new IListener() {
-
+ aiControl.getEndOfTurnEvent().add(new IListener1<ITable>() {
@Override
- public void handle() {
+ public void handle(ITable newTable) {
turnEnded = true;
}
@@ -73,12 +73,13 @@ public class AIControlTest {
/**
* @throws InterruptedException
- * if timeout
+ * if timeout
*/
@Test(timeout = 10000)
public void testTurnZeroNoRedealing() throws InterruptedException {
- aiControl.setup(new ITurnControl.TurnInfo(table, player.getHand(),
- player.getLaidOut(), TurnMode.MAY_REDEAL), gameSettings, view);
+ aiControl.setup(
+ new ITurnControl.TurnInfo(table, player.getHand(), player.getLaidOut(),
+ TurnMode.MAY_REDEAL), gameSettings, view);
aiControl.startTurn();
assertTrue(turnEnded);
assertFalse(redealt);
@@ -87,14 +88,13 @@ public class AIControlTest {
/**
* @throws InterruptedException
- * if timeout
+ * if timeout
*/
@Test(timeout = 10000)
public void testTurnZeroNotMelding() throws InterruptedException {
- aiControl
- .setup(new ITurnControl.TurnInfo(table, player.getHand(),
- player.getLaidOut(), TurnMode.INSPECT_ONLY),
- gameSettings, view);
+ aiControl.setup(
+ new ITurnControl.TurnInfo(table, player.getHand(), player.getLaidOut(),
+ TurnMode.INSPECT_ONLY), gameSettings, view);
aiControl.startTurn();
assertTrue(turnEnded);
assertFalse(redealt);
@@ -103,12 +103,13 @@ public class AIControlTest {
/**
* @throws InterruptedException
- * if timeout
+ * if timeout
*/
@Test(timeout = 10000)
public void testNormalTurnMelding() throws InterruptedException {
- aiControl.setup(new ITurnControl.TurnInfo(table, player.getHand(),
- player.getLaidOut(), TurnMode.NORMAL_TURN), gameSettings, view);
+ aiControl.setup(
+ new ITurnControl.TurnInfo(table, player.getHand(), player.getLaidOut(),
+ TurnMode.NORMAL_TURN), gameSettings, view);
aiControl.startTurn();
assertTrue(turnEnded);
assertFalse(redealt);
diff --git a/test/jrummikub/control/turn/TurnControlTest.java b/test/jrummikub/control/turn/TurnControlTest.java
index f334b29..5e3e09c 100644
--- a/test/jrummikub/control/turn/TurnControlTest.java
+++ b/test/jrummikub/control/turn/TurnControlTest.java
@@ -25,7 +25,7 @@ import jrummikub.model.StoneSet;
import jrummikub.model.Table;
import jrummikub.util.Event;
import jrummikub.util.IEvent;
-import jrummikub.util.IListener;
+import jrummikub.util.IListener1;
import jrummikub.util.Pair;
import jrummikub.view.IView.BottomPanelType;
import jrummikub.view.MockView;
@@ -133,8 +133,8 @@ public class TurnControlTest {
mockPlayer = new MockPlayer(null, null);
mockPlayer.hand = mockHand;
testControl = new HumanTurnControl(mockTimer);
- testControl.setup(new ITurnControl.TurnInfo(mockTable, mockPlayer
- .getHand(), mockPlayer.getLaidOut(), TurnMode.NORMAL_TURN),
+ testControl.setup(new ITurnControl.TurnInfo(mockTable,
+ mockPlayer.getHand(), mockPlayer.getLaidOut(), TurnMode.NORMAL_TURN),
new GameSettings(), mockView);
}
@@ -159,8 +159,8 @@ public class TurnControlTest {
mockHand.iterable = stones;
testControl = new HumanTurnControl(mockTimer);
- testControl.setup(new ITurnControl.TurnInfo(mockTable, mockPlayer
- .getHand(), mockPlayer.getLaidOut(), TurnMode.NORMAL_TURN),
+ testControl.setup(new ITurnControl.TurnInfo(mockTable,
+ mockPlayer.getHand(), mockPlayer.getLaidOut(), TurnMode.NORMAL_TURN),
new GameSettings(), mockView);
testControl.startTurn();
@@ -182,10 +182,9 @@ public class TurnControlTest {
eventFired = false;
mockTimer.timerRunning = true;
- testControl.getEndOfTurnEvent().add(new IListener() {
-
+ testControl.getEndOfTurnEvent().add(new IListener1<ITable>() {
@Override
- public void handle() {
+ public void handle(ITable newTable) {
eventFired = true;
}
});
@@ -205,10 +204,9 @@ public class TurnControlTest {
eventFired = false;
mockTimer.timerRunning = true;
- testControl.getEndOfTurnEvent().add(new IListener() {
-
+ testControl.getEndOfTurnEvent().add(new IListener1<ITable>() {
@Override
- public void handle() {
+ public void handle(ITable newTable) {
eventFired = true;
}
});
@@ -292,8 +290,8 @@ public class TurnControlTest {
mockView.handPanel.stoneClickEvent.emit(redJoker, true);
mockView.handPanel.stoneClickEvent.emit(blackJoker, true);
- mockView.tablePanel.stoneCollectionPanel.stoneClickEvent.emit(
- blackJoker, true);
+ mockView.tablePanel.stoneCollectionPanel.stoneClickEvent.emit(blackJoker,
+ true);
assertCollection(Arrays.asList(redJoker, blackJoker));
}
@@ -309,8 +307,7 @@ public class TurnControlTest {
mockView.tablePanel.stoneCollectionPanel.stoneClickEvent.emit(redJoker,
true);
- mockView.tablePanel.stoneCollectionPanel.setClickEvent.emit(redJoker,
- true);
+ mockView.tablePanel.stoneCollectionPanel.setClickEvent.emit(redJoker, true);
assertCollection(new ArrayList<Stone>());
}
@@ -408,8 +405,8 @@ public class TurnControlTest {
testControl.startTurn();
Stone stone4 = new Stone(4, StoneColor.RED);
- StoneSet set1 = new StoneSet(Arrays.asList(redOne, redTwo, redThree,
- stone4));
+ StoneSet set1 = new StoneSet(
+ Arrays.asList(redOne, redTwo, redThree, stone4));
mockTable.findStoneSet.put(redOne, set1);
mockTable.findStoneSet.put(redThree, set1);
@@ -576,15 +573,15 @@ public class TurnControlTest {
public void testAddLeft() {
AccessibleTable table = new AccessibleTable();
HumanTurnControl turnControl = new HumanTurnControl(mockTimer);
- turnControl.setup(new ITurnControl.TurnInfo(table,
- mockPlayer.getHand(), mockPlayer.getLaidOut(),
- TurnMode.NORMAL_TURN), new GameSettings(), mockView);
+ turnControl.setup(new ITurnControl.TurnInfo(table, mockPlayer.getHand(),
+ mockPlayer.getLaidOut(), TurnMode.NORMAL_TURN), new GameSettings(),
+ mockView);
turnControl.startTurn();
- StoneSet oldSet1 = new StoneSet(Arrays.asList(blueOne, redOne,
- blackOne, redTwo, redThree, redFour, blackTwo, blackThree));
- StoneSet oldSet2 = new StoneSet(Arrays.asList(blueTwo, blackFour,
- blackFive));
+ StoneSet oldSet1 = new StoneSet(Arrays.asList(blueOne, redOne, blackOne,
+ redTwo, redThree, redFour, blackTwo, blackThree));
+ StoneSet oldSet2 = new StoneSet(
+ Arrays.asList(blueTwo, blackFour, blackFive));
table.drop(oldSet1, new Position(0, 0));
table.drop(oldSet2, new Position(0, 0));
mockHand.drop(blueThree, new Position(0, 0));
@@ -683,14 +680,14 @@ public class TurnControlTest {
public void testAddRight() {
AccessibleTable table = new AccessibleTable();
HumanTurnControl turnControl = new HumanTurnControl(mockTimer);
- turnControl.setup(new ITurnControl.TurnInfo(table,
- mockPlayer.getHand(), mockPlayer.getLaidOut(),
- TurnMode.NORMAL_TURN), new GameSettings(), mockView);
+ turnControl.setup(new ITurnControl.TurnInfo(table, mockPlayer.getHand(),
+ mockPlayer.getLaidOut(), TurnMode.NORMAL_TURN), new GameSettings(),
+ mockView);
turnControl.startTurn();
- StoneSet oldSet1 = new StoneSet(Arrays.asList(blueOne, redOne,
- blackOne, redTwo, redThree, redFour, blackTwo, blackThree));
- StoneSet oldSet2 = new StoneSet(Arrays.asList(blueTwo, blackFour,
- blackFive));
+ StoneSet oldSet1 = new StoneSet(Arrays.asList(blueOne, redOne, blackOne,
+ redTwo, redThree, redFour, blackTwo, blackThree));
+ StoneSet oldSet2 = new StoneSet(
+ Arrays.asList(blueTwo, blackFour, blackFive));
table.drop(oldSet1, new Position(0, 0));
table.drop(oldSet2, new Position(0, 0));
mockHand.drop(blueThree, new Position(0, 0));
@@ -789,14 +786,14 @@ public class TurnControlTest {
public void testAddNewSet() {
AccessibleTable table = new AccessibleTable();
HumanTurnControl turnControl = new HumanTurnControl(mockTimer);
- turnControl.setup(new ITurnControl.TurnInfo(table,
- mockPlayer.getHand(), mockPlayer.getLaidOut(),
- TurnMode.NORMAL_TURN), new GameSettings(), mockView);
+ turnControl.setup(new ITurnControl.TurnInfo(table, mockPlayer.getHand(),
+ mockPlayer.getLaidOut(), TurnMode.NORMAL_TURN), new GameSettings(),
+ mockView);
turnControl.startTurn();
- StoneSet oldSet1 = new StoneSet(Arrays.asList(blueOne, redOne,
- blackOne, redTwo, redThree, redFour, blackTwo, blackThree));
- StoneSet oldSet2 = new StoneSet(Arrays.asList(blueTwo, blackFour,
- blackFive));
+ StoneSet oldSet1 = new StoneSet(Arrays.asList(blueOne, redOne, blackOne,
+ redTwo, redThree, redFour, blackTwo, blackThree));
+ StoneSet oldSet2 = new StoneSet(
+ Arrays.asList(blueTwo, blackFour, blackFive));
table.drop(oldSet1, new Position(0, 0));
table.drop(oldSet2, new Position(0, 0));
mockHand.drop(blueThree, new Position(0, 0));
@@ -887,8 +884,8 @@ public class TurnControlTest {
List<Pair<Stone, Position>> stones = new ArrayList<Pair<Stone, Position>>(
mockHand.stones);
- Collections.sort(stones,
- new HumanTurnControl.HandStonePositionComparator());
+ Collections
+ .sort(stones, new HumanTurnControl.HandStonePositionComparator());
assertEquals(stones.size(), 13);
@@ -936,8 +933,8 @@ public class TurnControlTest {
List<Pair<Stone, Position>> stones = new ArrayList<Pair<Stone, Position>>(
mockHand.stones);
- Collections.sort(stones,
- new HumanTurnControl.HandStonePositionComparator());
+ Collections
+ .sort(stones, new HumanTurnControl.HandStonePositionComparator());
assertEquals(stones.size(), 13);
@@ -977,8 +974,8 @@ public class TurnControlTest {
assertCollection(new ArrayList<Stone>());
- Set<Stone> expected = new HashSet<Stone>(Arrays.asList(redJoker,
- blackJoker));
+ Set<Stone> expected = new HashSet<Stone>(
+ Arrays.asList(redJoker, blackJoker));
assertEquals(expected, mockHand.pickups);
Set<Stone> handStones = new HashSet<Stone>();
@@ -1005,8 +1002,7 @@ public class TurnControlTest {
assertCollection(Arrays.asList(blackJoker));
- Set<Stone> expected = new HashSet<Stone>(Arrays.asList(redJoker,
- black13));
+ Set<Stone> expected = new HashSet<Stone>(Arrays.asList(redJoker, black13));
assertEquals(expected, mockHand.pickups);
Set<Stone> handStones = new HashSet<Stone>();