Selecting/collecting on table (without range)

git-svn-id: svn://sunsvr01.isp.uni-luebeck.de/swproj13/trunk@124 72836036-5685-4462-b002-a69064685172
This commit is contained in:
Jannis Harder 2011-05-04 21:47:35 +02:00
parent fe019e5eae
commit 88766c6df2
3 changed files with 159 additions and 0 deletions

View file

@ -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>(