From 88766c6df209637ddb3e97a38e8a1aa45a8bd515 Mon Sep 17 00:00:00 2001 From: Jannis Harder Date: Wed, 4 May 2011 21:47:35 +0200 Subject: Selecting/collecting on table (without range) git-svn-id: svn://sunsvr01.isp.uni-luebeck.de/swproj13/trunk@124 72836036-5685-4462-b002-a69064685172 --- test/jrummikub/control/TurnControlTest.java | 89 +++++++++++++++++++++++++++++ test/jrummikub/model/MockTable.java | 64 +++++++++++++++++++++ test/jrummikub/view/MockTablePanel.java | 6 ++ 3 files changed, 159 insertions(+) create mode 100644 test/jrummikub/model/MockTable.java (limited to 'test') 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()); } + @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 expected) { ArrayList selectedStones = new ArrayList( 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 findStoneSet = new HashMap(); + + @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> 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 stoneClickEvent = new Event2(); + public Event2 setClickEvent = new Event2(); + public MockStoneCollectionPanel stoneCollectionPanel = new MockStoneCollectionPanel(); public String leftPlayerName; public String topPlayerName; public String rightPlayerName; + + @Override public IEvent2 getStoneClickEvent() { // TODO Auto-generated method stub -- cgit v1.2.3