summaryrefslogtreecommitdiffstats
path: root/test
diff options
context:
space:
mode:
authorJannis Harder <harder@informatik.uni-luebeck.de>2011-05-04 21:47:35 +0200
committerJannis Harder <harder@informatik.uni-luebeck.de>2011-05-04 21:47:35 +0200
commit88766c6df209637ddb3e97a38e8a1aa45a8bd515 (patch)
tree111535a302e4990090333569493663fb81a5c441 /test
parentfe019e5eae8d8e740d7620044727988c6d28a423 (diff)
downloadJRummikub-88766c6df209637ddb3e97a38e8a1aa45a8bd515.tar
JRummikub-88766c6df209637ddb3e97a38e8a1aa45a8bd515.zip
Selecting/collecting on table (without range)
git-svn-id: svn://sunsvr01.isp.uni-luebeck.de/swproj13/trunk@124 72836036-5685-4462-b002-a69064685172
Diffstat (limited to 'test')
-rw-r--r--test/jrummikub/control/TurnControlTest.java89
-rw-r--r--test/jrummikub/model/MockTable.java64
-rw-r--r--test/jrummikub/view/MockTablePanel.java6
3 files changed, 159 insertions, 0 deletions
diff --git a/test/jrummikub/control/TurnControlTest.java b/test/jrummikub/control/TurnControlTest.java
index 60ff37f..befe8f6 100644
--- a/test/jrummikub/control/TurnControlTest.java
+++ b/test/jrummikub/control/TurnControlTest.java
@@ -7,8 +7,10 @@ import java.util.List;
import java.util.ArrayList;
import java.util.Arrays;
+import jrummikub.model.MockTable;
import jrummikub.model.Stone;
import jrummikub.model.StoneColor;
+import jrummikub.model.StoneSet;
import jrummikub.util.Event;
import jrummikub.util.IEvent;
import jrummikub.util.IListener;
@@ -42,12 +44,14 @@ public class TurnControlTest {
MockView mockView;
MockTimer mockTimer;
+ MockTable mockTable;
boolean eventFired;
@Before
public void setUp() {
mockView = new MockView();
mockTimer = new MockTimer();
+ mockTable = new MockTable();
}
@Test
@@ -186,6 +190,91 @@ public class TurnControlTest {
assertCollection(new ArrayList<Stone>());
}
+ @Test
+ public void selectStoneOnTable() {
+ TurnControl testControl = new TurnControl(null, null, mockView,
+ mockTimer);
+
+ Stone firstStone = new Stone(StoneColor.RED);
+
+ // Select first stone
+ mockView.tablePanel.stoneClickEvent.emit(firstStone, false);
+
+ assertCollection(Arrays.asList(firstStone));
+
+ // Select second stone
+ Stone secondStone = new Stone(StoneColor.BLACK);
+ mockView.tablePanel.stoneClickEvent.emit(secondStone, false);
+
+ assertCollection(Arrays.asList(secondStone));
+
+ }
+
+ @Test
+ public void collectStoneOnTable() {
+ TurnControl testControl = new TurnControl(null, null, mockView,
+ mockTimer);
+
+ Stone firstStone = new Stone(StoneColor.RED);
+
+ // Select first stone
+ mockView.tablePanel.stoneClickEvent.emit(firstStone, true);
+
+ assertCollection(Arrays.asList(firstStone));
+
+ // Select second stone
+ Stone secondStone = new Stone(StoneColor.BLACK);
+ mockView.tablePanel.stoneClickEvent.emit(secondStone, true);
+
+ assertCollection(Arrays.asList(firstStone, secondStone));
+
+ // De-select first stone
+ mockView.tablePanel.stoneClickEvent.emit(firstStone, true);
+
+ 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));
+ }
private void assertCollection(List<Stone> expected) {
ArrayList<Stone> selectedStones = new ArrayList<Stone>(
diff --git a/test/jrummikub/model/MockTable.java b/test/jrummikub/model/MockTable.java
new file mode 100644
index 0000000..5ac5dca
--- /dev/null
+++ b/test/jrummikub/model/MockTable.java
@@ -0,0 +1,64 @@
+package jrummikub.model;
+
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.Map;
+
+import jrummikub.util.Pair;
+import jrummikub.view.MockStoneCollectionPanel;
+
+public class MockTable implements ITable {
+ public Map<Stone, StoneSet> findStoneSet = new HashMap<Stone, StoneSet>();
+
+ @Override
+ public void pickUpStone(Stone stone) {
+ // TODO Auto-generated method stub
+
+ }
+
+ @Override
+ public boolean isValid() {
+ // TODO Auto-generated method stub
+ return false;
+ }
+
+ @Override
+ public StoneSet pickUp(Position position) {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ @Override
+ public void drop(StoneSet object, Position position) {
+ // TODO Auto-generated method stub
+
+ }
+
+ @Override
+ public Position getPosition(StoneSet object) {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ @Override
+ public void pickUp(StoneSet object) {
+ // TODO Auto-generated method stub
+
+ }
+
+ @Override
+ public Iterator<Pair<StoneSet, Position>> iterator() {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ @Override
+ public StoneSet findStoneSet(Stone stone) {
+ return findStoneSet.get(stone);
+ }
+
+ public MockTable clone() {
+ return null;
+ }
+
+}
diff --git a/test/jrummikub/view/MockTablePanel.java b/test/jrummikub/view/MockTablePanel.java
index 58ca9c6..83b3de4 100644
--- a/test/jrummikub/view/MockTablePanel.java
+++ b/test/jrummikub/view/MockTablePanel.java
@@ -6,16 +6,22 @@ import jrummikub.model.Position;
import jrummikub.model.Stone;
import jrummikub.model.StoneSet;
import jrummikub.util.Event1;
+import jrummikub.util.Event2;
import jrummikub.util.IEvent1;
import jrummikub.util.IEvent2;
public class MockTablePanel implements ITablePanel {
+ public Event2<Stone, Boolean> stoneClickEvent = new Event2<Stone, Boolean>();
+ public Event2<Stone, Boolean> setClickEvent = new Event2<Stone, Boolean>();
+
public MockStoneCollectionPanel stoneCollectionPanel = new MockStoneCollectionPanel();
public String leftPlayerName;
public String topPlayerName;
public String rightPlayerName;
+
+
@Override
public IEvent2<Stone, Boolean> getStoneClickEvent() {
// TODO Auto-generated method stub