summaryrefslogtreecommitdiffstats
path: root/test
diff options
context:
space:
mode:
Diffstat (limited to 'test')
-rw-r--r--test/jrummikub/control/TurnControlTest.java138
-rw-r--r--test/jrummikub/view/MockTablePanel.java1
2 files changed, 102 insertions, 37 deletions
diff --git a/test/jrummikub/control/TurnControlTest.java b/test/jrummikub/control/TurnControlTest.java
index befe8f6..8c58352 100644
--- a/test/jrummikub/control/TurnControlTest.java
+++ b/test/jrummikub/control/TurnControlTest.java
@@ -2,10 +2,9 @@ package jrummikub.control;
import static org.junit.Assert.*;
-import java.util.Collections;
-import java.util.List;
import java.util.ArrayList;
import java.util.Arrays;
+import java.util.List;
import jrummikub.model.MockTable;
import jrummikub.model.Stone;
@@ -42,6 +41,7 @@ public class TurnControlTest {
}
+ TurnControl testControl;
MockView mockView;
MockTimer mockTimer;
MockTable mockTable;
@@ -52,14 +52,13 @@ public class TurnControlTest {
mockView = new MockView();
mockTimer = new MockTimer();
mockTable = new MockTable();
+ testControl = new TurnControl(null, mockTable, mockView, mockTimer);
}
@Test
public void viewEndOfTurn() {
eventFired = false;
mockTimer.timerRunning = true;
- TurnControl testControl = new TurnControl(null, null, mockView,
- mockTimer);
testControl.getEndOfTurnEvent().add(new IListener() {
@@ -79,8 +78,6 @@ public class TurnControlTest {
public void timerEndOfTurn() {
eventFired = false;
mockTimer.timerRunning = true;
- TurnControl testControl = new TurnControl(null, null, mockView,
- mockTimer);
testControl.getEndOfTurnEvent().add(new IListener() {
@@ -98,8 +95,6 @@ public class TurnControlTest {
@Test
public void selectStoneInHand() {
- TurnControl testControl = new TurnControl(null, null, mockView,
- mockTimer);
Stone firstStone = new Stone(StoneColor.RED);
@@ -118,8 +113,6 @@ public class TurnControlTest {
@Test
public void collectStoneInHand() {
- TurnControl testControl = new TurnControl(null, null, mockView,
- mockTimer);
Stone firstStone = new Stone(StoneColor.RED);
@@ -142,8 +135,6 @@ public class TurnControlTest {
@Test
public void deselectStoneInCollection() {
- TurnControl testControl = new TurnControl(null, null, mockView,
- mockTimer);
Stone firstStone = new Stone(StoneColor.RED);
Stone secondStone = new Stone(StoneColor.BLACK);
@@ -155,12 +146,10 @@ public class TurnControlTest {
assertCollection(Arrays.asList(secondStone));
}
-
+
@Test
public void reorderCollection() {
- TurnControl testControl = new TurnControl(null, null, mockView,
- mockTimer);
Stone firstStone = new Stone(StoneColor.RED);
Stone secondStone = new Stone(StoneColor.BLACK);
@@ -172,28 +161,24 @@ public class TurnControlTest {
assertCollection(Arrays.asList(secondStone, firstStone));
}
-
+
@Test
public void deselectWholeCollection() {
- TurnControl testControl = new TurnControl(null, null, mockView,
- mockTimer);
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.setClickEvent.emit(
- firstStone, true);
+ mockView.tablePanel.stoneCollectionPanel.setClickEvent.emit(firstStone,
+ true);
assertCollection(new ArrayList<Stone>());
}
-
+
@Test
public void selectStoneOnTable() {
- TurnControl testControl = new TurnControl(null, null, mockView,
- mockTimer);
Stone firstStone = new Stone(StoneColor.RED);
@@ -212,8 +197,6 @@ public class TurnControlTest {
@Test
public void collectStoneOnTable() {
- TurnControl testControl = new TurnControl(null, null, mockView,
- mockTimer);
Stone firstStone = new Stone(StoneColor.RED);
@@ -233,49 +216,130 @@ public class TurnControlTest {
assertCollection(Arrays.asList(secondStone));
}
-
+
@Test
public void selectSetOnTable() {
- TurnControl testControl = new TurnControl(null, mockTable, mockView,
- mockTimer);
-
+
Stone stone1 = new Stone(StoneColor.RED);
Stone stone2 = new Stone(StoneColor.BLACK);
StoneSet set1 = new StoneSet(Arrays.asList(stone1, stone2));
Stone stone3 = new Stone(1, StoneColor.RED);
Stone stone4 = new Stone(1, StoneColor.BLACK);
StoneSet set2 = new StoneSet(Arrays.asList(stone3, stone4));
-
+
mockTable.findStoneSet.put(stone1, set1);
mockTable.findStoneSet.put(stone4, set2);
-
+
mockView.tablePanel.setClickEvent.emit(stone1, false);
assertCollection(Arrays.asList(stone1, stone2));
mockView.tablePanel.setClickEvent.emit(stone4, false);
assertCollection(Arrays.asList(stone3, stone4));
}
-
+
@Test
public void collectSetOnTable() {
- TurnControl testControl = new TurnControl(null, mockTable, mockView,
- mockTimer);
-
+
Stone stone1 = new Stone(StoneColor.RED);
Stone stone2 = new Stone(StoneColor.BLACK);
StoneSet set1 = new StoneSet(Arrays.asList(stone1, stone2));
Stone stone3 = new Stone(1, StoneColor.RED);
Stone stone4 = new Stone(1, StoneColor.BLACK);
StoneSet set2 = new StoneSet(Arrays.asList(stone3, stone4));
-
+
mockTable.findStoneSet.put(stone1, set1);
mockTable.findStoneSet.put(stone4, set2);
-
+
mockView.tablePanel.setClickEvent.emit(stone1, true);
assertCollection(Arrays.asList(stone1, stone2));
mockView.tablePanel.setClickEvent.emit(stone4, true);
assertCollection(Arrays.asList(stone1, stone2, stone3, stone4));
}
+ @Test
+ public void rangeSelectOnTable() {
+
+ 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));
+
+ mockTable.findStoneSet.put(stone1, set1);
+ mockTable.findStoneSet.put(stone3, set1);
+
+ mockView.tablePanel.stoneClickEvent.emit(stone1, false);
+ mockView.tablePanel.rangeClickEvent.emit(stone3, true);
+
+ assertCollection(Arrays.asList(stone1, stone2, stone3));
+
+ }
+
+ @Test
+ public void rangeCollectOnTable() {
+ 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));
+
+ mockTable.findStoneSet.put(stone1, set1);
+ mockTable.findStoneSet.put(stone3, set1);
+
+ mockView.tablePanel.stoneClickEvent.emit(extraStone, false);
+
+ mockView.tablePanel.stoneClickEvent.emit(stone1, true);
+ mockView.tablePanel.rangeClickEvent.emit(stone3, false);
+
+ assertCollection(Arrays.asList(extraStone, stone1, stone2, stone3));
+ }
+
+ @Test
+ public void rangeFailSelect() {
+ Stone stone1 = new Stone(1, StoneColor.RED);
+ Stone stone2 = new Stone(2, StoneColor.RED);
+ StoneSet set1 = new StoneSet(Arrays.asList(stone1));
+ StoneSet set2 = new StoneSet(Arrays.asList(stone2));
+
+ mockTable.findStoneSet.put(stone1, set1);
+ mockTable.findStoneSet.put(stone2, set2);
+
+ // Select first stone
+ mockView.tablePanel.stoneClickEvent.emit(stone1, false);
+
+ assertCollection(Arrays.asList(stone1));
+
+ // Select second stone
+ mockView.tablePanel.rangeClickEvent.emit(stone2, false);
+
+ assertCollection(Arrays.asList(stone2));
+
+ }
+
+ @Test
+ public void rangeFailCollect() {
+ Stone stone1 = new Stone(1, StoneColor.RED);
+ Stone stone2 = new Stone(2, StoneColor.RED);
+ StoneSet set1 = new StoneSet(Arrays.asList(stone1));
+ StoneSet set2 = new StoneSet(Arrays.asList(stone2));
+
+ mockTable.findStoneSet.put(stone1, set1);
+ mockTable.findStoneSet.put(stone2, set2);
+
+ // Select first stone
+ mockView.tablePanel.stoneClickEvent.emit(stone1, true);
+
+ assertCollection(Arrays.asList(stone1));
+
+ // Select second stone
+ mockView.tablePanel.rangeClickEvent.emit(stone2, true);
+
+ assertCollection(Arrays.asList(stone1, stone2));
+ }
+
private void assertCollection(List<Stone> expected) {
ArrayList<Stone> selectedStones = new ArrayList<Stone>(
mockView.selectedStones);
diff --git a/test/jrummikub/view/MockTablePanel.java b/test/jrummikub/view/MockTablePanel.java
index 83b3de4..3fcc289 100644
--- a/test/jrummikub/view/MockTablePanel.java
+++ b/test/jrummikub/view/MockTablePanel.java
@@ -14,6 +14,7 @@ public class MockTablePanel implements ITablePanel {
public Event2<Stone, Boolean> stoneClickEvent = new Event2<Stone, Boolean>();
public Event2<Stone, Boolean> setClickEvent = new Event2<Stone, Boolean>();
+ public Event2<Stone, Boolean> rangeClickEvent = new Event2<Stone, Boolean>();
public MockStoneCollectionPanel stoneCollectionPanel = new MockStoneCollectionPanel();
public String leftPlayerName;