Completed all selecting/collecting tests
git-svn-id: svn://sunsvr01.isp.uni-luebeck.de/swproj13/trunk@126 72836036-5685-4462-b002-a69064685172
This commit is contained in:
parent
104f9bab94
commit
b0a90ad6f0
2 changed files with 102 additions and 37 deletions
|
@ -2,10 +2,9 @@ package jrummikub.control;
|
||||||
|
|
||||||
import static org.junit.Assert.*;
|
import static org.junit.Assert.*;
|
||||||
|
|
||||||
import java.util.Collections;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
import jrummikub.model.MockTable;
|
import jrummikub.model.MockTable;
|
||||||
import jrummikub.model.Stone;
|
import jrummikub.model.Stone;
|
||||||
|
@ -42,6 +41,7 @@ public class TurnControlTest {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
TurnControl testControl;
|
||||||
MockView mockView;
|
MockView mockView;
|
||||||
MockTimer mockTimer;
|
MockTimer mockTimer;
|
||||||
MockTable mockTable;
|
MockTable mockTable;
|
||||||
|
@ -52,14 +52,13 @@ public class TurnControlTest {
|
||||||
mockView = new MockView();
|
mockView = new MockView();
|
||||||
mockTimer = new MockTimer();
|
mockTimer = new MockTimer();
|
||||||
mockTable = new MockTable();
|
mockTable = new MockTable();
|
||||||
|
testControl = new TurnControl(null, mockTable, mockView, mockTimer);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void viewEndOfTurn() {
|
public void viewEndOfTurn() {
|
||||||
eventFired = false;
|
eventFired = false;
|
||||||
mockTimer.timerRunning = true;
|
mockTimer.timerRunning = true;
|
||||||
TurnControl testControl = new TurnControl(null, null, mockView,
|
|
||||||
mockTimer);
|
|
||||||
|
|
||||||
testControl.getEndOfTurnEvent().add(new IListener() {
|
testControl.getEndOfTurnEvent().add(new IListener() {
|
||||||
|
|
||||||
|
@ -79,8 +78,6 @@ public class TurnControlTest {
|
||||||
public void timerEndOfTurn() {
|
public void timerEndOfTurn() {
|
||||||
eventFired = false;
|
eventFired = false;
|
||||||
mockTimer.timerRunning = true;
|
mockTimer.timerRunning = true;
|
||||||
TurnControl testControl = new TurnControl(null, null, mockView,
|
|
||||||
mockTimer);
|
|
||||||
|
|
||||||
testControl.getEndOfTurnEvent().add(new IListener() {
|
testControl.getEndOfTurnEvent().add(new IListener() {
|
||||||
|
|
||||||
|
@ -98,8 +95,6 @@ public class TurnControlTest {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void selectStoneInHand() {
|
public void selectStoneInHand() {
|
||||||
TurnControl testControl = new TurnControl(null, null, mockView,
|
|
||||||
mockTimer);
|
|
||||||
|
|
||||||
Stone firstStone = new Stone(StoneColor.RED);
|
Stone firstStone = new Stone(StoneColor.RED);
|
||||||
|
|
||||||
|
@ -118,8 +113,6 @@ public class TurnControlTest {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void collectStoneInHand() {
|
public void collectStoneInHand() {
|
||||||
TurnControl testControl = new TurnControl(null, null, mockView,
|
|
||||||
mockTimer);
|
|
||||||
|
|
||||||
Stone firstStone = new Stone(StoneColor.RED);
|
Stone firstStone = new Stone(StoneColor.RED);
|
||||||
|
|
||||||
|
@ -142,8 +135,6 @@ public class TurnControlTest {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void deselectStoneInCollection() {
|
public void deselectStoneInCollection() {
|
||||||
TurnControl testControl = new TurnControl(null, null, mockView,
|
|
||||||
mockTimer);
|
|
||||||
Stone firstStone = new Stone(StoneColor.RED);
|
Stone firstStone = new Stone(StoneColor.RED);
|
||||||
Stone secondStone = new Stone(StoneColor.BLACK);
|
Stone secondStone = new Stone(StoneColor.BLACK);
|
||||||
|
|
||||||
|
@ -159,8 +150,6 @@ public class TurnControlTest {
|
||||||
@Test
|
@Test
|
||||||
public void reorderCollection() {
|
public void reorderCollection() {
|
||||||
|
|
||||||
TurnControl testControl = new TurnControl(null, null, mockView,
|
|
||||||
mockTimer);
|
|
||||||
Stone firstStone = new Stone(StoneColor.RED);
|
Stone firstStone = new Stone(StoneColor.RED);
|
||||||
Stone secondStone = new Stone(StoneColor.BLACK);
|
Stone secondStone = new Stone(StoneColor.BLACK);
|
||||||
|
|
||||||
|
@ -176,24 +165,20 @@ public class TurnControlTest {
|
||||||
@Test
|
@Test
|
||||||
public void deselectWholeCollection() {
|
public void deselectWholeCollection() {
|
||||||
|
|
||||||
TurnControl testControl = new TurnControl(null, null, mockView,
|
|
||||||
mockTimer);
|
|
||||||
Stone firstStone = new Stone(StoneColor.RED);
|
Stone firstStone = new Stone(StoneColor.RED);
|
||||||
Stone secondStone = new Stone(StoneColor.BLACK);
|
Stone secondStone = new Stone(StoneColor.BLACK);
|
||||||
|
|
||||||
mockView.playerPanel.handPanel.stoneClickEvent.emit(firstStone, true);
|
mockView.playerPanel.handPanel.stoneClickEvent.emit(firstStone, true);
|
||||||
mockView.playerPanel.handPanel.stoneClickEvent.emit(secondStone, true);
|
mockView.playerPanel.handPanel.stoneClickEvent.emit(secondStone, true);
|
||||||
|
|
||||||
mockView.tablePanel.stoneCollectionPanel.setClickEvent.emit(
|
mockView.tablePanel.stoneCollectionPanel.setClickEvent.emit(firstStone,
|
||||||
firstStone, true);
|
true);
|
||||||
|
|
||||||
assertCollection(new ArrayList<Stone>());
|
assertCollection(new ArrayList<Stone>());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void selectStoneOnTable() {
|
public void selectStoneOnTable() {
|
||||||
TurnControl testControl = new TurnControl(null, null, mockView,
|
|
||||||
mockTimer);
|
|
||||||
|
|
||||||
Stone firstStone = new Stone(StoneColor.RED);
|
Stone firstStone = new Stone(StoneColor.RED);
|
||||||
|
|
||||||
|
@ -212,8 +197,6 @@ public class TurnControlTest {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void collectStoneOnTable() {
|
public void collectStoneOnTable() {
|
||||||
TurnControl testControl = new TurnControl(null, null, mockView,
|
|
||||||
mockTimer);
|
|
||||||
|
|
||||||
Stone firstStone = new Stone(StoneColor.RED);
|
Stone firstStone = new Stone(StoneColor.RED);
|
||||||
|
|
||||||
|
@ -236,8 +219,6 @@ public class TurnControlTest {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void selectSetOnTable() {
|
public void selectSetOnTable() {
|
||||||
TurnControl testControl = new TurnControl(null, mockTable, mockView,
|
|
||||||
mockTimer);
|
|
||||||
|
|
||||||
Stone stone1 = new Stone(StoneColor.RED);
|
Stone stone1 = new Stone(StoneColor.RED);
|
||||||
Stone stone2 = new Stone(StoneColor.BLACK);
|
Stone stone2 = new Stone(StoneColor.BLACK);
|
||||||
|
@ -257,8 +238,6 @@ public class TurnControlTest {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void collectSetOnTable() {
|
public void collectSetOnTable() {
|
||||||
TurnControl testControl = new TurnControl(null, mockTable, mockView,
|
|
||||||
mockTimer);
|
|
||||||
|
|
||||||
Stone stone1 = new Stone(StoneColor.RED);
|
Stone stone1 = new Stone(StoneColor.RED);
|
||||||
Stone stone2 = new Stone(StoneColor.BLACK);
|
Stone stone2 = new Stone(StoneColor.BLACK);
|
||||||
|
@ -276,6 +255,91 @@ public class TurnControlTest {
|
||||||
assertCollection(Arrays.asList(stone1, stone2, stone3, stone4));
|
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) {
|
private void assertCollection(List<Stone> expected) {
|
||||||
ArrayList<Stone> selectedStones = new ArrayList<Stone>(
|
ArrayList<Stone> selectedStones = new ArrayList<Stone>(
|
||||||
mockView.selectedStones);
|
mockView.selectedStones);
|
||||||
|
|
|
@ -14,6 +14,7 @@ public class MockTablePanel implements ITablePanel {
|
||||||
|
|
||||||
public Event2<Stone, Boolean> stoneClickEvent = new Event2<Stone, Boolean>();
|
public Event2<Stone, Boolean> stoneClickEvent = new Event2<Stone, Boolean>();
|
||||||
public Event2<Stone, Boolean> setClickEvent = 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 MockStoneCollectionPanel stoneCollectionPanel = new MockStoneCollectionPanel();
|
||||||
public String leftPlayerName;
|
public String leftPlayerName;
|
||||||
|
|
Reference in a new issue