summaryrefslogtreecommitdiffstats
path: root/test/jrummikub
diff options
context:
space:
mode:
Diffstat (limited to 'test/jrummikub')
-rw-r--r--test/jrummikub/control/RoundControlTest.java4
-rw-r--r--test/jrummikub/control/TurnControlTest.java142
2 files changed, 97 insertions, 49 deletions
diff --git a/test/jrummikub/control/RoundControlTest.java b/test/jrummikub/control/RoundControlTest.java
index 9569fbd..38060c0 100644
--- a/test/jrummikub/control/RoundControlTest.java
+++ b/test/jrummikub/control/RoundControlTest.java
@@ -136,7 +136,7 @@ public class RoundControlTest {
view.startTurnEvent.emit();
assertFalse(view.displayStartTurnPanel);
- Stone stone = testGameState.players.get(0).hand.stones.remove(0);
+ Stone stone = testGameState.players.get(0).hand.stones.remove(0).getFirst();
newTable.drop(new StoneSet(stone), new Position(0, 0));
resetTurnStart();
view.getPlayerPanel().endTurnEvent.emit();
@@ -194,7 +194,7 @@ public class RoundControlTest {
view.startTurnEvent.emit();
assertFalse(view.displayStartTurnPanel);
- Stone stone = testGameState.players.get(0).hand.stones.remove(0);
+ Stone stone = testGameState.players.get(0).hand.stones.remove(0).getFirst();
newTable.drop(new StoneSet(stone), new Position(0, 0));
testGameState.players.get(0).hand.stones.clear();
resetTurnStart();
diff --git a/test/jrummikub/control/TurnControlTest.java b/test/jrummikub/control/TurnControlTest.java
index 9617233..0335bc7 100644
--- a/test/jrummikub/control/TurnControlTest.java
+++ b/test/jrummikub/control/TurnControlTest.java
@@ -10,8 +10,11 @@ import static org.junit.Assert.assertTrue;
import java.util.ArrayList;
import java.util.Arrays;
+import java.util.Iterator;
import java.util.List;
+import jrummikub.model.IHand;
+import jrummikub.model.ITable;
import jrummikub.model.MockHand;
import jrummikub.model.MockTable;
import jrummikub.model.Position;
@@ -29,8 +32,8 @@ import org.junit.Before;
import org.junit.Test;
public class TurnControlTest {
- static class AccessibleTable extends Table{
- StoneSet[] getSetArray(){
+ static class AccessibleTable extends Table {
+ StoneSet[] getSetArray() {
return objects.keySet().toArray(new StoneSet[0]);
}
}
@@ -63,6 +66,30 @@ public class TurnControlTest {
MockHand mockHand;
boolean eventFired;
+ private void checkTableDisplay(ITable table) {
+ Iterator<Pair<StoneSet, Position>> stoneSetsView = mockView.tablePanel.stoneSets
+ .iterator();
+ Iterator<Pair<StoneSet, Position>> stoneSetsModel = table.iterator();
+
+ while (stoneSetsView.hasNext()) {
+ assertTrue(stoneSetsModel.hasNext());
+ assertSame(stoneSetsView.next(), stoneSetsModel.next());
+ }
+ assertFalse(stoneSetsModel.hasNext());
+ }
+
+ private void checkHandDisplay(IHand hand) {
+ Iterator<Pair<Stone, Position>> stoneSetsView = mockView.playerPanel.handPanel.stones
+ .iterator();
+ Iterator<Pair<Stone, Position>> stoneSetsModel = hand.iterator();
+
+ while (stoneSetsView.hasNext()) {
+ assertTrue(stoneSetsModel.hasNext());
+ assertSame(stoneSetsView.next(), stoneSetsModel.next());
+ }
+ assertFalse(stoneSetsModel.hasNext());
+ }
+
@Before
public void setUp() {
mockView = new MockView();
@@ -70,28 +97,23 @@ public class TurnControlTest {
mockTable = new MockTable();
mockHand = new MockHand();
testControl = new TurnControl(mockHand, mockTable, mockView, mockTimer);
- testControl.startTurn();
}
@Test
public void startTimer() {
+ testControl.startTurn();
+
assertTrue(mockTimer.timerRunning);
}
@SuppressWarnings("unchecked")
@Test
public void showInitialHand() {
- mockView = new MockView();
- mockTimer = new MockTimer();
- mockTable = new MockTable();
- mockHand = new MockHand();
-
mockView.displayStartTurnPanel = true;
- List<Pair<Stone, Position>> stones = Arrays
- .asList(new Pair<Stone, Position>(new Stone(RED), new Position(
- 0, 0)), new Pair<Stone, Position>(new Stone(BLACK),
- new Position(1, 0)));
+ List<Pair<Stone, Position>> stones = Arrays.asList(
+ new Pair<Stone, Position>(new Stone(RED), new Position(0, 0)),
+ new Pair<Stone, Position>(new Stone(BLACK), new Position(1, 0)));
mockHand.iterable = stones;
@@ -111,6 +133,8 @@ public class TurnControlTest {
@Test
public void viewEndOfTurn() {
+ testControl.startTurn();
+
eventFired = false;
mockTimer.timerRunning = true;
@@ -131,6 +155,8 @@ public class TurnControlTest {
@Test
public void timerEndOfTurn() {
+ testControl.startTurn();
+
eventFired = false;
mockTimer.timerRunning = true;
@@ -150,6 +176,7 @@ public class TurnControlTest {
@Test
public void deselctOnEndOfTurn() {
+ testControl.startTurn();
Stone firstStone = new Stone(StoneColor.RED);
@@ -162,6 +189,7 @@ public class TurnControlTest {
@Test
public void selectStoneInHand() {
+ testControl.startTurn();
Stone firstStone = new Stone(StoneColor.RED);
@@ -180,6 +208,7 @@ public class TurnControlTest {
@Test
public void collectStoneInHand() {
+ testControl.startTurn();
Stone firstStone = new Stone(StoneColor.RED);
@@ -202,20 +231,23 @@ public class TurnControlTest {
@Test
public void deselectStoneInCollection() {
+ testControl.startTurn();
+
Stone firstStone = new Stone(StoneColor.RED);
Stone secondStone = new Stone(StoneColor.BLACK);
mockView.playerPanel.handPanel.stoneClickEvent.emit(firstStone, true);
mockView.playerPanel.handPanel.stoneClickEvent.emit(secondStone, true);
- mockView.tablePanel.stoneCollectionPanel.stoneClickEvent.emit(
- firstStone, false);
+ mockView.tablePanel.stoneCollectionPanel.stoneClickEvent.emit(firstStone,
+ false);
assertCollection(Arrays.asList(secondStone));
}
@Test
public void reorderCollection() {
+ testControl.startTurn();
Stone firstStone = new Stone(StoneColor.RED);
Stone secondStone = new Stone(StoneColor.BLACK);
@@ -223,14 +255,15 @@ public class TurnControlTest {
mockView.playerPanel.handPanel.stoneClickEvent.emit(firstStone, true);
mockView.playerPanel.handPanel.stoneClickEvent.emit(secondStone, true);
- mockView.tablePanel.stoneCollectionPanel.stoneClickEvent.emit(
- firstStone, true);
+ mockView.tablePanel.stoneCollectionPanel.stoneClickEvent.emit(firstStone,
+ true);
assertCollection(Arrays.asList(secondStone, firstStone));
}
@Test
public void deselectWholeCollection() {
+ testControl.startTurn();
Stone firstStone = new Stone(StoneColor.RED);
Stone secondStone = new Stone(StoneColor.BLACK);
@@ -246,6 +279,7 @@ public class TurnControlTest {
@Test
public void selectStoneOnTable() {
+ testControl.startTurn();
Stone firstStone = new Stone(StoneColor.RED);
@@ -264,6 +298,7 @@ public class TurnControlTest {
@Test
public void collectStoneOnTable() {
+ testControl.startTurn();
Stone firstStone = new Stone(StoneColor.RED);
@@ -286,6 +321,7 @@ public class TurnControlTest {
@Test
public void selectSetOnTable() {
+ testControl.startTurn();
Stone stone1 = new Stone(StoneColor.RED);
Stone stone2 = new Stone(StoneColor.BLACK);
@@ -305,6 +341,7 @@ public class TurnControlTest {
@Test
public void collectSetOnTable() {
+ testControl.startTurn();
Stone stone1 = new Stone(StoneColor.RED);
Stone stone2 = new Stone(StoneColor.BLACK);
@@ -324,13 +361,13 @@ public class TurnControlTest {
@Test
public void rangeSelectOnTable() {
+ testControl.startTurn();
Stone stone1 = new Stone(1, StoneColor.RED);
Stone stone2 = new Stone(2, StoneColor.RED);
Stone stone3 = new Stone(3, StoneColor.RED);
Stone stone4 = new Stone(4, StoneColor.RED);
- StoneSet set1 = new StoneSet(Arrays.asList(stone1, stone2, stone3,
- stone4));
+ StoneSet set1 = new StoneSet(Arrays.asList(stone1, stone2, stone3, stone4));
mockTable.findStoneSet.put(stone1, set1);
mockTable.findStoneSet.put(stone3, set1);
@@ -344,14 +381,15 @@ public class TurnControlTest {
@Test
public void rangeCollectOnTable() {
+ testControl.startTurn();
+
Stone extraStone = new Stone(StoneColor.RED);
Stone stone1 = new Stone(1, StoneColor.RED);
Stone stone2 = new Stone(2, StoneColor.RED);
Stone stone3 = new Stone(3, StoneColor.RED);
Stone stone4 = new Stone(4, StoneColor.RED);
- StoneSet set1 = new StoneSet(Arrays.asList(stone1, stone2, stone3,
- stone4));
+ StoneSet set1 = new StoneSet(Arrays.asList(stone1, stone2, stone3, stone4));
mockTable.findStoneSet.put(stone1, set1);
mockTable.findStoneSet.put(stone3, set1);
@@ -366,6 +404,8 @@ public class TurnControlTest {
@Test
public void rangeFailSelect() {
+ testControl.startTurn();
+
Stone stone1 = new Stone(1, StoneColor.RED);
Stone stone2 = new Stone(2, StoneColor.RED);
StoneSet set1 = new StoneSet(Arrays.asList(stone1));
@@ -388,6 +428,8 @@ public class TurnControlTest {
@Test
public void rangeFailCollect() {
+ testControl.startTurn();
+
Stone stone1 = new Stone(1, StoneColor.RED);
Stone stone2 = new Stone(2, StoneColor.RED);
StoneSet set1 = new StoneSet(Arrays.asList(stone1));
@@ -416,8 +458,9 @@ public class TurnControlTest {
@Test
public void testAddLeft() {
- AccessibleTable table=new AccessibleTable();
- TurnControl turnControl=new TurnControl(mockHand, table, mockView, mockTimer);
+ AccessibleTable table = new AccessibleTable();
+ TurnControl turnControl = new TurnControl(mockHand, table, mockView,
+ mockTimer);
turnControl.startTurn();
Stone blueOne = new Stone(1, BLUE);
Stone redOne = new Stone(1, RED);
@@ -432,10 +475,10 @@ public class TurnControlTest {
Stone blackThree = new Stone(3, BLACK);
Stone blackFour = new Stone(4, BLACK);
Stone blackFive = new Stone(5, BLACK);
- 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));
@@ -446,7 +489,7 @@ public class TurnControlTest {
mockView.tablePanel.leftConnectorClickEvent.emit(oldSet1);
// handcheck
assertEquals(1, mockHand.getSize());
- assertSame(mockHand.stones.get(0), blueFour);
+ assertSame(mockHand.stones.get(0).getFirst(), blueFour);
// tablecheck
assertEquals(2, table.getSize());
StoneSet newSet1, newSet2;
@@ -475,12 +518,12 @@ public class TurnControlTest {
mockView.tablePanel.leftConnectorClickEvent.emit(oldSet2);
// handcheck
assertEquals(1, mockHand.getSize());
- assertSame(mockHand.stones.get(0), blueFour);
+ assertSame(mockHand.stones.get(0).getFirst(), blueFour);
// tablecheck
assertEquals(2, table.getSize());
if (table.getSetArray()[0].size() == 5) {
- newSet2 =table.getSetArray()[0];
- newSet1 =table.getSetArray()[1];
+ newSet2 = table.getSetArray()[0];
+ newSet1 = table.getSetArray()[1];
} else {
newSet1 = table.getSetArray()[0];
newSet2 = table.getSetArray()[1];
@@ -529,8 +572,9 @@ public class TurnControlTest {
@Test
public void testAddRight() {
- AccessibleTable table=new AccessibleTable();
- TurnControl turnControl=new TurnControl(mockHand, table, mockView, mockTimer);
+ AccessibleTable table = new AccessibleTable();
+ TurnControl turnControl = new TurnControl(mockHand, table, mockView,
+ mockTimer);
turnControl.startTurn();
Stone blueOne = new Stone(1, BLUE);
Stone redOne = new Stone(1, RED);
@@ -545,10 +589,10 @@ public class TurnControlTest {
Stone blackThree = new Stone(3, BLACK);
Stone blackFour = new Stone(4, BLACK);
Stone blackFive = new Stone(5, BLACK);
- 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));
@@ -559,7 +603,7 @@ public class TurnControlTest {
mockView.tablePanel.rightConnectorClickEvent.emit(oldSet1);
// handcheck
assertEquals(1, mockHand.getSize());
- assertSame(mockHand.stones.get(0), blueFour);
+ assertSame(mockHand.stones.get(0).getFirst(), blueFour);
// tablecheck
assertEquals(2, table.getSize());
StoneSet newSet1, newSet2;
@@ -588,7 +632,7 @@ public class TurnControlTest {
mockView.tablePanel.rightConnectorClickEvent.emit(oldSet2);
// handcheck
assertEquals(1, mockHand.getSize());
- assertSame(mockHand.stones.get(0), blueFour);
+ assertSame(mockHand.stones.get(0).getFirst(), blueFour);
// tablecheck
assertEquals(2, table.getSize());
if (table.getSetArray()[0].size() == 5) {
@@ -642,8 +686,9 @@ public class TurnControlTest {
@Test
public void testAddNewSet() {
- AccessibleTable table=new AccessibleTable();
- TurnControl turnControl=new TurnControl(mockHand, table, mockView, mockTimer);
+ AccessibleTable table = new AccessibleTable();
+ TurnControl turnControl = new TurnControl(mockHand, table, mockView,
+ mockTimer);
turnControl.startTurn();
Stone blueOne = new Stone(1, BLUE);
Stone redOne = new Stone(1, RED);
@@ -658,10 +703,10 @@ public class TurnControlTest {
Stone blackThree = new Stone(3, BLACK);
Stone blackFour = new Stone(4, BLACK);
Stone blackFive = new Stone(5, BLACK);
- 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));
@@ -673,10 +718,10 @@ public class TurnControlTest {
mockView.tablePanel.clickEvent.emit(new Position(0, 0));
// handcheck
assertEquals(1, mockHand.getSize());
- assertSame(blueFour, mockHand.stones.get(0));
+ assertSame(blueFour, mockHand.stones.get(0).getFirst());
// tablecheck
StoneSet newSet1, newSet2, newSet3;
- assertEquals(2, table.getSize());
+ assertEquals(3, table.getSize());
if (table.getSetArray()[0].size() == 2) {
newSet2 = table.getSetArray()[0];
if (table.getSetArray()[1].size() == 4) {
@@ -701,7 +746,7 @@ public class TurnControlTest {
newSet2 = table.getSetArray()[1];
newSet3 = table.getSetArray()[2];
} else {
- newSet2 =table.getSetArray()[2];
+ newSet2 = table.getSetArray()[2];
newSet3 = table.getSetArray()[1];
}
}
@@ -724,5 +769,8 @@ public class TurnControlTest {
assertSame(newSet3.get(1), redOne);
assertSame(newSet3.get(2), redThree);
assertSame(newSet3.get(3), blueTwo);
+
+ checkTableDisplay(table);
+ checkHandDisplay(mockHand);
}
}