From e2f82f3f28a0872ed626439809a292e701c9b01e Mon Sep 17 00:00:00 2001 From: Ida Massow Date: Wed, 4 May 2011 23:26:01 +0200 Subject: =?UTF-8?q?Test=20f=C3=BCr=20RoundControl=20fertig?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit git-svn-id: svn://sunsvr01.isp.uni-luebeck.de/swproj13/trunk@128 72836036-5685-4462-b002-a69064685172 --- test/jrummikub/control/RoundControlTest.java | 143 +++++++++++++++++++++++++-- test/jrummikub/model/GameStateTest.java | 2 +- test/jrummikub/model/MockGameState.java | 54 ++++++++++ test/jrummikub/model/MockHand.java | 49 +++++++++ test/jrummikub/model/MockPlayer.java | 26 +++++ test/jrummikub/model/MockTable.java | 26 ++--- test/jrummikub/view/MockPlayerPanel.java | 10 +- 7 files changed, 281 insertions(+), 29 deletions(-) create mode 100644 test/jrummikub/model/MockGameState.java create mode 100644 test/jrummikub/model/MockHand.java create mode 100644 test/jrummikub/model/MockPlayer.java (limited to 'test/jrummikub') diff --git a/test/jrummikub/control/RoundControlTest.java b/test/jrummikub/control/RoundControlTest.java index bc0bb3d..7d13ff0 100644 --- a/test/jrummikub/control/RoundControlTest.java +++ b/test/jrummikub/control/RoundControlTest.java @@ -1,7 +1,16 @@ package jrummikub.control; -import static org.junit.Assert.*; -import jrummikub.model.GameState; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +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 jrummikub.model.MockGameState; +import jrummikub.model.MockTable; +import jrummikub.model.Position; +import jrummikub.model.Stone; +import jrummikub.model.StoneSet; import jrummikub.view.MockView; import org.junit.Before; @@ -9,13 +18,13 @@ import org.junit.Test; public class RoundControlTest { private MockView view; - private GameState testGameState; + private MockGameState testGameState; private RoundControl testRound; @Before public void setup() { view = new MockView(); - testGameState = new GameState(); + testGameState = new MockGameState(); testRound = new RoundControl(testGameState, view); } @@ -27,6 +36,23 @@ public class RoundControlTest { } } + private void checkTurnStartSetUp() { + assertNotNull(view.currentPlayerName); + assertNotNull(view.getTablePanel().leftPlayerName); + assertNotNull(view.getTablePanel().topPlayerName); + assertNotNull(view.getTablePanel().rightPlayerName); + assertTrue(view.displayStartTurnPanel); + assertFalse(view.startTurnEvent.listeners.isEmpty()); + } + + private void resetTurnStart() { + view.currentPlayerName = null; + view.getTablePanel().leftPlayerName = null; + view.getTablePanel().topPlayerName = null; + view.getTablePanel().rightPlayerName = null; + view.displayStartTurnPanel = false; + } + @Test public void testDeal() { testRound.deal(); @@ -38,11 +64,108 @@ public class RoundControlTest { testRound.startRound(); checkCorrectlyDealed(); - assertNotNull(view.currentPlayerName); - assertNotNull(view.getTablePanel().leftPlayerName); - assertNotNull(view.getTablePanel().topPlayerName); - assertNotNull(view.getTablePanel().rightPlayerName); - assertTrue(view.displayStartTurnPanel); - assertFalse(view.startTurnEvent.listeners.isEmpty()); + checkTurnStartSetUp(); + } + + @Test + public void testTableValidHandChanged() { + testRound.startRound(); + MockTable oldTable = testGameState.table; + MockTable newTable = new MockTable(); + newTable.valid = true; + oldTable.clonedTable = newTable; + + view.startTurnEvent.emit(); + assertFalse(view.displayStartTurnPanel); + testGameState.players.get(0).hand.stones.remove(0); + resetTurnStart(); + view.getPlayerPanel().endTurnEvent.emit(); + + assertNotSame(oldTable, testGameState.table); + assertSame(newTable, testGameState.table); + assertEquals(1, testGameState.activePlayer); + + checkTurnStartSetUp(); + } + + @Test + public void testTableInvalidHandChanged() { + testRound.startRound(); + MockTable oldTable = testGameState.table; + MockTable newTable = new MockTable(); + newTable.valid = false; + oldTable.clonedTable = newTable; + + view.startTurnEvent.emit(); + assertFalse(view.displayStartTurnPanel); + Stone stone = testGameState.players.get(0).hand.stones.remove(0); + newTable.drop(new StoneSet(stone), new Position(0, 0)); + resetTurnStart(); + view.getPlayerPanel().endTurnEvent.emit(); + + assertSame(oldTable, testGameState.table); + assertNotSame(newTable, testGameState.table); + assertEquals(1, testGameState.activePlayer); + assertEquals(14 + 3, testGameState.players.get(0).hand.getSize()); + checkTurnStartSetUp(); + } + + @Test + public void testTableValidHandUnchanged() { + testRound.startRound(); + MockTable oldTable = testGameState.table; + MockTable newTable = new MockTable(); + newTable.valid = true; + oldTable.clonedTable = newTable; + + view.startTurnEvent.emit(); + assertFalse(view.displayStartTurnPanel); + resetTurnStart(); + view.getPlayerPanel().endTurnEvent.emit(); + + assertEquals(14 + 1, testGameState.players.get(0).hand.getSize()); + assertEquals(1, testGameState.activePlayer); + assertSame(newTable, testGameState.table); + assertNotSame(oldTable, testGameState.table); + + checkTurnStartSetUp(); + } + + @Test + public void testTableInvalidHandUnchanged() { + testRound.startRound(); + MockTable oldTable = testGameState.table; + MockTable newTable = new MockTable(); + newTable.valid = false; + oldTable.clonedTable = newTable; + + view.startTurnEvent.emit(); + assertFalse(view.displayStartTurnPanel); + resetTurnStart(); + view.getPlayerPanel().endTurnEvent.emit(); + + assertEquals(14 + 1, testGameState.players.get(0).hand.getSize()); + assertEquals(1, testGameState.activePlayer); + assertNotSame(newTable, testGameState.table); + assertSame(oldTable, testGameState.table); + + checkTurnStartSetUp(); + } + + @Test + public void testWinning() { + testRound.startRound(); + MockTable oldTable = testGameState.table; + MockTable newTable = new MockTable(); + newTable.valid = true; + oldTable.clonedTable = newTable; + + view.startTurnEvent.emit(); + assertFalse(view.displayStartTurnPanel); + testGameState.players.get(0).hand.stones.clear(); + resetTurnStart(); + view.getPlayerPanel().endTurnEvent.emit(); + + assertTrue(view.displayWinPanel); } } diff --git a/test/jrummikub/model/GameStateTest.java b/test/jrummikub/model/GameStateTest.java index a134231..e1de06c 100644 --- a/test/jrummikub/model/GameStateTest.java +++ b/test/jrummikub/model/GameStateTest.java @@ -8,7 +8,7 @@ import org.junit.Before; import org.junit.Test; public class GameStateTest { - private GameState testGame; + private IGameState testGame; @Before public void createGame() { diff --git a/test/jrummikub/model/MockGameState.java b/test/jrummikub/model/MockGameState.java new file mode 100644 index 0000000..102e9fb --- /dev/null +++ b/test/jrummikub/model/MockGameState.java @@ -0,0 +1,54 @@ +package jrummikub.model; + +import java.awt.Color; +import java.util.ArrayList; +import java.util.List; + +public class MockGameState implements IGameState { + public MockTable table; + public List players; + public int activePlayer; + public StoneHeap gameHeap; + + public MockGameState() { + table = new MockTable(); + players = new ArrayList(); + players.add(new MockPlayer(Color.red)); + players.add(new MockPlayer(Color.yellow)); + players.add(new MockPlayer(Color.green)); + players.add(new MockPlayer(Color.black)); + activePlayer = 0; + gameHeap = new StoneHeap(); + } + + @Override + public ITable getTable() { + return table; + } + + @Override + public int getPlayerCount() { + return players.size(); + } + + @Override + public IPlayer getPlayer(int i) { + return players.get(i); + } + + /** Changes the activePlayer to the next {@link Player} in the list */ + @Override + public void nextPlayer() { + activePlayer = (activePlayer + 1) % players.size(); + } + + @Override + public IPlayer getActivePlayer() { + return players.get(activePlayer); + } + + @Override + public StoneHeap getGameHeap() { + return gameHeap; + } +} diff --git a/test/jrummikub/model/MockHand.java b/test/jrummikub/model/MockHand.java new file mode 100644 index 0000000..1fc5954 --- /dev/null +++ b/test/jrummikub/model/MockHand.java @@ -0,0 +1,49 @@ +package jrummikub.model; + +import java.util.ArrayList; +import java.util.Iterator; +import java.util.List; + +import jrummikub.util.Pair; + +public class MockHand implements IHand { + + public List stones = new ArrayList(); + + @Override + public Stone pickUp(Position position) { + return null; + } + + @Override + public void drop(Stone object, Position position) { + stones.add(object); + } + + @Override + public Position getPosition(Stone object) { + // TODO Auto-generated method stub + return null; + } + + @Override + public void pickUp(Stone object) { + // TODO Auto-generated method stub + + } + + @Override + public int getSize() { + return stones.size(); + } + + @Override + public Iterator> iterator() { + // TODO Auto-generated method stub + return null; + } + + public MockHand clone() { + return null; + } +} diff --git a/test/jrummikub/model/MockPlayer.java b/test/jrummikub/model/MockPlayer.java new file mode 100644 index 0000000..adb9d85 --- /dev/null +++ b/test/jrummikub/model/MockPlayer.java @@ -0,0 +1,26 @@ +package jrummikub.model; + +import java.awt.Color; + +public class MockPlayer implements IPlayer { + + public MockHand hand; + public Color color; + + // private String name; + + public MockPlayer(Color color) { + hand = new MockHand(); + this.color = color; + } + + @Override + public IHand getHand() { + return hand; + } + + @Override + public Color getColor() { + return color; + } +} diff --git a/test/jrummikub/model/MockTable.java b/test/jrummikub/model/MockTable.java index bab1f58..4d7ef1a 100644 --- a/test/jrummikub/model/MockTable.java +++ b/test/jrummikub/model/MockTable.java @@ -1,15 +1,19 @@ package jrummikub.model; +import java.util.ArrayList; import java.util.HashMap; import java.util.Iterator; +import java.util.List; import java.util.Map; import jrummikub.util.Pair; -import jrummikub.view.MockStoneCollectionPanel; public class MockTable implements ITable { public Map findStoneSet = new HashMap(); - + public boolean valid = false; + public MockTable clonedTable; + public List> sets = new ArrayList>(); + @Override public void pickUpStone(Stone stone) { // TODO Auto-generated method stub @@ -18,8 +22,7 @@ public class MockTable implements ITable { @Override public boolean isValid() { - // TODO Auto-generated method stub - return false; + return valid; } @Override @@ -30,8 +33,7 @@ public class MockTable implements ITable { @Override public void drop(StoneSet object, Position position) { - // TODO Auto-generated method stub - + sets.add(new Pair(object, position)); } @Override @@ -43,28 +45,26 @@ public class MockTable implements ITable { @Override public void pickUp(StoneSet object) { // TODO Auto-generated method stub - + } @Override public Iterator> iterator() { - // TODO Auto-generated method stub - return null; + return sets.iterator(); } @Override public StoneSet findStoneSet(Stone stone) { return findStoneSet.get(stone); } - + public MockTable clone() { - return null; + return clonedTable; } @Override public int getSize() { - // TODO Auto-generated method stub - return 0; + return sets.size(); } } diff --git a/test/jrummikub/view/MockPlayerPanel.java b/test/jrummikub/view/MockPlayerPanel.java index 639287a..fcf560e 100644 --- a/test/jrummikub/view/MockPlayerPanel.java +++ b/test/jrummikub/view/MockPlayerPanel.java @@ -1,12 +1,12 @@ package jrummikub.view; -import jrummikub.util.Event; import jrummikub.util.IEvent; +import jrummikub.util.MockEvent; public class MockPlayerPanel implements IPlayerPanel { - public Event endTurnEvent = new Event(); + public MockEvent endTurnEvent = new MockEvent(); public MockHandPanel handPanel = new MockHandPanel(); - + @Override public IHandPanel getHandPanel() { // TODO Auto-generated method stub @@ -16,7 +16,7 @@ public class MockPlayerPanel implements IPlayerPanel { @Override public void setTimeLeft(int time) { // TODO Auto-generated method stub - + } @Override @@ -35,5 +35,5 @@ public class MockPlayerPanel implements IPlayerPanel { public IEvent getEndTurnEvent() { return endTurnEvent; } - + } -- cgit v1.2.3