Check displaying of table in RoundControl tests

git-svn-id: svn://sunsvr01.isp.uni-luebeck.de/swproj13/trunk@137 72836036-5685-4462-b002-a69064685172
This commit is contained in:
Jannis Harder 2011-05-05 00:43:11 +02:00
parent bc827302d0
commit d5560a8a6e
2 changed files with 34 additions and 6 deletions

View file

@ -6,11 +6,16 @@ import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNotSame;
import static org.junit.Assert.assertSame;
import static org.junit.Assert.assertTrue;
import java.util.Iterator;
import jrummikub.model.GameState;
import jrummikub.model.MockGameState;
import jrummikub.model.MockTable;
import jrummikub.model.Position;
import jrummikub.model.Stone;
import jrummikub.model.StoneSet;
import jrummikub.util.Pair;
import jrummikub.view.MockView;
import org.junit.Before;
@ -20,16 +25,22 @@ public class RoundControlTest {
private MockView view;
private MockGameState testGameState;
private RoundControl testRound;
private MockTable newTable;
@Before
public void setup() {
view = new MockView();
testGameState = new MockGameState();
testRound = new RoundControl(testGameState, view);
Stone stone = testGameState.getGameHeap().drawStone();
testGameState.table.drop(new StoneSet(stone), new Position(5, 0));
newTable = new MockTable();
newTable.drop(new StoneSet(stone), new Position(5, 0));
}
private void checkCorrectlyDealed() {
assertEquals(106 - testGameState.getPlayerCount() * 14, testGameState
assertEquals(106 - testGameState.getPlayerCount() * 14 - testGameState.table.getSize(), testGameState
.getGameHeap().getSize());
for (int i = 0; i < testGameState.getPlayerCount(); i++) {
assertEquals(14, testGameState.getPlayer(i).getHand().getSize());
@ -43,6 +54,18 @@ public class RoundControlTest {
assertNotNull(view.getTablePanel().rightPlayerName);
assertTrue(view.displayStartTurnPanel);
assertFalse(view.startTurnEvent.listeners.isEmpty());
checkTableDisplay();
}
private void checkTableDisplay() {
Iterator<Pair<StoneSet, Position>> stoneSetsView = view.tablePanel.stoneSets.iterator();
Iterator<Pair<StoneSet, Position>> stoneSetsModel = testGameState.table.sets.iterator();
while(stoneSetsView.hasNext()) {
assertTrue(stoneSetsModel.hasNext());
assertSame(stoneSetsView.next(), stoneSetsModel.next());
}
assertFalse(stoneSetsModel.hasNext());
}
private void resetTurnStart() {
@ -66,12 +89,19 @@ public class RoundControlTest {
checkTurnStartSetUp();
}
@Test
public void testStartRoundDisplayOnly() {
testRound.startRound();
checkCorrectlyDealed();
checkTableDisplay();
}
@Test
public void testTableValidHandChanged() {
testRound.startRound();
MockTable oldTable = testGameState.table;
MockTable newTable = new MockTable();
newTable.valid = true;
oldTable.clonedTable = newTable;
@ -92,7 +122,6 @@ public class RoundControlTest {
public void testTableInvalidHandChanged() {
testRound.startRound();
MockTable oldTable = testGameState.table;
MockTable newTable = new MockTable();
newTable.valid = false;
oldTable.clonedTable = newTable;
@ -114,7 +143,6 @@ public class RoundControlTest {
public void testTableValidHandUnchanged() {
testRound.startRound();
MockTable oldTable = testGameState.table;
MockTable newTable = new MockTable();
newTable.valid = true;
oldTable.clonedTable = newTable;
@ -135,7 +163,6 @@ public class RoundControlTest {
public void testTableInvalidHandUnchanged() {
testRound.startRound();
MockTable oldTable = testGameState.table;
MockTable newTable = new MockTable();
newTable.valid = false;
oldTable.clonedTable = newTable;
@ -156,7 +183,6 @@ public class RoundControlTest {
public void testWinning() {
testRound.startRound();
MockTable oldTable = testGameState.table;
MockTable newTable = new MockTable();
newTable.valid = true;
oldTable.clonedTable = newTable;

View file

@ -21,6 +21,8 @@ public class MockTablePanel implements ITablePanel {
public String leftPlayerName;
public String topPlayerName;
public String rightPlayerName;
public Iterable<Pair<StoneSet, Position>> stoneSets;
@Override
public IEvent2<Stone, Boolean> getStoneClickEvent() {