From b0a90ad6f052037260c6304b537a9550a7422e30 Mon Sep 17 00:00:00 2001 From: Jannis Harder Date: Wed, 4 May 2011 22:37:26 +0200 Subject: Completed all selecting/collecting tests git-svn-id: svn://sunsvr01.isp.uni-luebeck.de/swproj13/trunk@126 72836036-5685-4462-b002-a69064685172 --- test/jrummikub/control/TurnControlTest.java | 138 ++++++++++++++++++++-------- 1 file changed, 101 insertions(+), 37 deletions(-) (limited to 'test/jrummikub/control') diff --git a/test/jrummikub/control/TurnControlTest.java b/test/jrummikub/control/TurnControlTest.java index befe8f6..8c58352 100644 --- a/test/jrummikub/control/TurnControlTest.java +++ b/test/jrummikub/control/TurnControlTest.java @@ -2,10 +2,9 @@ package jrummikub.control; import static org.junit.Assert.*; -import java.util.Collections; -import java.util.List; import java.util.ArrayList; import java.util.Arrays; +import java.util.List; import jrummikub.model.MockTable; import jrummikub.model.Stone; @@ -42,6 +41,7 @@ public class TurnControlTest { } + TurnControl testControl; MockView mockView; MockTimer mockTimer; MockTable mockTable; @@ -52,14 +52,13 @@ public class TurnControlTest { mockView = new MockView(); mockTimer = new MockTimer(); mockTable = new MockTable(); + testControl = new TurnControl(null, mockTable, mockView, mockTimer); } @Test public void viewEndOfTurn() { eventFired = false; mockTimer.timerRunning = true; - TurnControl testControl = new TurnControl(null, null, mockView, - mockTimer); testControl.getEndOfTurnEvent().add(new IListener() { @@ -79,8 +78,6 @@ public class TurnControlTest { public void timerEndOfTurn() { eventFired = false; mockTimer.timerRunning = true; - TurnControl testControl = new TurnControl(null, null, mockView, - mockTimer); testControl.getEndOfTurnEvent().add(new IListener() { @@ -98,8 +95,6 @@ public class TurnControlTest { @Test public void selectStoneInHand() { - TurnControl testControl = new TurnControl(null, null, mockView, - mockTimer); Stone firstStone = new Stone(StoneColor.RED); @@ -118,8 +113,6 @@ public class TurnControlTest { @Test public void collectStoneInHand() { - TurnControl testControl = new TurnControl(null, null, mockView, - mockTimer); Stone firstStone = new Stone(StoneColor.RED); @@ -142,8 +135,6 @@ public class TurnControlTest { @Test public void deselectStoneInCollection() { - TurnControl testControl = new TurnControl(null, null, mockView, - mockTimer); Stone firstStone = new Stone(StoneColor.RED); Stone secondStone = new Stone(StoneColor.BLACK); @@ -155,12 +146,10 @@ public class TurnControlTest { assertCollection(Arrays.asList(secondStone)); } - + @Test public void reorderCollection() { - TurnControl testControl = new TurnControl(null, null, mockView, - mockTimer); Stone firstStone = new Stone(StoneColor.RED); Stone secondStone = new Stone(StoneColor.BLACK); @@ -172,28 +161,24 @@ public class TurnControlTest { assertCollection(Arrays.asList(secondStone, firstStone)); } - + @Test public void deselectWholeCollection() { - TurnControl testControl = new TurnControl(null, null, mockView, - mockTimer); Stone firstStone = new Stone(StoneColor.RED); Stone secondStone = new Stone(StoneColor.BLACK); mockView.playerPanel.handPanel.stoneClickEvent.emit(firstStone, true); mockView.playerPanel.handPanel.stoneClickEvent.emit(secondStone, true); - mockView.tablePanel.stoneCollectionPanel.setClickEvent.emit( - firstStone, true); + mockView.tablePanel.stoneCollectionPanel.setClickEvent.emit(firstStone, + true); assertCollection(new ArrayList()); } - + @Test public void selectStoneOnTable() { - TurnControl testControl = new TurnControl(null, null, mockView, - mockTimer); Stone firstStone = new Stone(StoneColor.RED); @@ -212,8 +197,6 @@ public class TurnControlTest { @Test public void collectStoneOnTable() { - TurnControl testControl = new TurnControl(null, null, mockView, - mockTimer); Stone firstStone = new Stone(StoneColor.RED); @@ -233,49 +216,130 @@ public class TurnControlTest { 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)); } + @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 expected) { ArrayList selectedStones = new ArrayList( mockView.selectedStones); -- cgit v1.2.3