From 72912be6008039ea81f875fe3be911cd4d66a8d4 Mon Sep 17 00:00:00 2001 From: Ida Massow Date: Tue, 21 Jun 2011 01:46:36 +0200 Subject: =?UTF-8?q?Tests=20f=C3=BCr=20RoundControl=20gefixt?= 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@524 72836036-5685-4462-b002-a69064685172 --- test/jrummikub/control/turn/TurnControlTest.java | 139 +++++++++++++---------- 1 file changed, 80 insertions(+), 59 deletions(-) (limited to 'test/jrummikub/control/turn') diff --git a/test/jrummikub/control/turn/TurnControlTest.java b/test/jrummikub/control/turn/TurnControlTest.java index 9e89a57..76c2159 100644 --- a/test/jrummikub/control/turn/TurnControlTest.java +++ b/test/jrummikub/control/turn/TurnControlTest.java @@ -1,7 +1,13 @@ package jrummikub.control.turn; -import static jrummikub.model.StoneColor.*; -import static org.junit.Assert.*; +import static jrummikub.model.StoneColor.BLACK; +import static jrummikub.model.StoneColor.BLUE; +import static jrummikub.model.StoneColor.ORANGE; +import static jrummikub.model.StoneColor.RED; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertSame; +import static org.junit.Assert.assertTrue; import java.util.ArrayList; import java.util.Arrays; @@ -12,11 +18,16 @@ import java.util.List; import java.util.Set; import jrummikub.control.ITurnTimer; +import jrummikub.control.RoundControl; +import jrummikub.control.RoundControl.InvalidTurnInfo; +import jrummikub.control.turn.ITurnControl.TurnInfo; import jrummikub.model.GameSettings; import jrummikub.model.IHand; +import jrummikub.model.IRoundState; import jrummikub.model.ITable; import jrummikub.model.MockHand; import jrummikub.model.MockPlayer; +import jrummikub.model.MockRoundState; import jrummikub.model.MockTable; import jrummikub.model.Position; import jrummikub.model.Stone; @@ -25,6 +36,7 @@ import jrummikub.model.StoneSet; import jrummikub.model.Table; import jrummikub.util.Event; import jrummikub.util.IEvent; +import jrummikub.util.IListener2; import jrummikub.util.IListener3; import jrummikub.util.Pair; import jrummikub.view.IView.BottomPanelType; @@ -75,6 +87,7 @@ public class TurnControlTest { MockTimer mockTimer; MockTable mockTable; MockHand mockHand; + private MockRoundState mockRoundState; boolean eventFired; Stone blueOne = new Stone(1, BLUE); Stone redOne = new Stone(1, RED); @@ -127,15 +140,15 @@ public class TurnControlTest { @Before public void setUp() { mockView = new MockView(); + mockRoundState = new MockRoundState(); mockTimer = new MockTimer(); mockTable = new MockTable(); mockHand = new MockHand(); mockPlayer = new MockPlayer(null, null); mockPlayer.hand = mockHand; testControl = new HumanTurnControl(mockTimer); - testControl.setup(new ITurnControl.TurnInfo(mockTable, - mockPlayer.getHand(), mockPlayer.getLaidOut(), TurnMode.NORMAL_TURN), - new GameSettings(), mockView); + testControl.setup(new ITurnControl.TurnInfo(mockRoundState, + TurnMode.NORMAL_TURN), new GameSettings(), mockView); } /** */ @@ -159,9 +172,8 @@ public class TurnControlTest { mockHand.iterable = stones; testControl = new HumanTurnControl(mockTimer); - testControl.setup(new ITurnControl.TurnInfo(mockTable, - mockPlayer.getHand(), mockPlayer.getLaidOut(), TurnMode.NORMAL_TURN), - new GameSettings(), mockView); + testControl.setup(new ITurnControl.TurnInfo(mockRoundState, + TurnMode.NORMAL_TURN), new GameSettings(), mockView); testControl.startTurn(); int i = 0; @@ -183,9 +195,10 @@ public class TurnControlTest { mockTimer.timerRunning = true; testControl.getEndOfTurnEvent().add( - new IListener3() { + new IListener2() { @Override - public void handle(IHand oldHand, ITable oldTable, ITable newTable) { + public void handle(IRoundState roundState, + RoundControl.InvalidTurnInfo invalidTurnInfo) { eventFired = true; } }); @@ -206,9 +219,10 @@ public class TurnControlTest { mockTimer.timerRunning = true; testControl.getEndOfTurnEvent().add( - new IListener3() { + new IListener2() { @Override - public void handle(IHand oldHand, ITable oldTable, ITable newTable) { + public void handle(IRoundState value1, + InvalidTurnInfo value2) { eventFired = true; } }); @@ -292,8 +306,8 @@ public class TurnControlTest { mockView.handPanel.stoneClickEvent.emit(redJoker, true); mockView.handPanel.stoneClickEvent.emit(blackJoker, true); - mockView.tablePanel.stoneCollectionPanel.stoneClickEvent.emit(blackJoker, - true); + mockView.tablePanel.stoneCollectionPanel.stoneClickEvent.emit( + blackJoker, true); assertCollection(Arrays.asList(redJoker, blackJoker)); } @@ -309,7 +323,8 @@ public class TurnControlTest { mockView.tablePanel.stoneCollectionPanel.stoneClickEvent.emit(redJoker, true); - mockView.tablePanel.stoneCollectionPanel.setClickEvent.emit(redJoker, true); + mockView.tablePanel.stoneCollectionPanel.setClickEvent.emit(redJoker, + true); assertCollection(new ArrayList()); } @@ -407,8 +422,8 @@ public class TurnControlTest { testControl.startTurn(); Stone stone4 = new Stone(4, StoneColor.RED); - StoneSet set1 = new StoneSet( - Arrays.asList(redOne, redTwo, redThree, stone4)); + StoneSet set1 = new StoneSet(Arrays.asList(redOne, redTwo, redThree, + stone4)); mockTable.findStoneSet.put(redOne, set1); mockTable.findStoneSet.put(redThree, set1); @@ -575,15 +590,14 @@ public class TurnControlTest { public void testAddLeft() { AccessibleTable table = new AccessibleTable(); HumanTurnControl turnControl = new HumanTurnControl(mockTimer); - turnControl.setup(new ITurnControl.TurnInfo(table, mockPlayer.getHand(), - mockPlayer.getLaidOut(), TurnMode.NORMAL_TURN), new GameSettings(), - mockView); + turnControl.setup(new ITurnControl.TurnInfo(mockRoundState, + TurnMode.NORMAL_TURN), new GameSettings(), mockView); turnControl.startTurn(); - StoneSet oldSet1 = new StoneSet(Arrays.asList(blueOne, redOne, blackOne, - redTwo, redThree, redFour, blackTwo, blackThree)); - StoneSet oldSet2 = new StoneSet( - Arrays.asList(blueTwo, blackFour, blackFive)); + StoneSet oldSet1 = new StoneSet(Arrays.asList(blueOne, redOne, + blackOne, redTwo, redThree, redFour, blackTwo, blackThree)); + StoneSet oldSet2 = new StoneSet(Arrays.asList(blueTwo, blackFour, + blackFive)); table.drop(oldSet1, new Position(0, 0)); table.drop(oldSet2, new Position(0, 0)); mockHand.drop(blueThree, new Position(0, 0)); @@ -682,14 +696,13 @@ public class TurnControlTest { public void testAddRight() { AccessibleTable table = new AccessibleTable(); HumanTurnControl turnControl = new HumanTurnControl(mockTimer); - turnControl.setup(new ITurnControl.TurnInfo(table, mockPlayer.getHand(), - mockPlayer.getLaidOut(), TurnMode.NORMAL_TURN), new GameSettings(), - mockView); + turnControl.setup(new TurnInfo(mockRoundState, TurnMode.NORMAL_TURN), + new GameSettings(), mockView); turnControl.startTurn(); - StoneSet oldSet1 = new StoneSet(Arrays.asList(blueOne, redOne, blackOne, - redTwo, redThree, redFour, blackTwo, blackThree)); - StoneSet oldSet2 = new StoneSet( - Arrays.asList(blueTwo, blackFour, blackFive)); + StoneSet oldSet1 = new StoneSet(Arrays.asList(blueOne, redOne, + blackOne, redTwo, redThree, redFour, blackTwo, blackThree)); + StoneSet oldSet2 = new StoneSet(Arrays.asList(blueTwo, blackFour, + blackFive)); table.drop(oldSet1, new Position(0, 0)); table.drop(oldSet2, new Position(0, 0)); mockHand.drop(blueThree, new Position(0, 0)); @@ -788,14 +801,13 @@ public class TurnControlTest { public void testAddNewSet() { AccessibleTable table = new AccessibleTable(); HumanTurnControl turnControl = new HumanTurnControl(mockTimer); - turnControl.setup(new ITurnControl.TurnInfo(table, mockPlayer.getHand(), - mockPlayer.getLaidOut(), TurnMode.NORMAL_TURN), new GameSettings(), - mockView); + turnControl.setup(new TurnInfo(mockRoundState, TurnMode.NORMAL_TURN), + new GameSettings(), mockView); turnControl.startTurn(); - StoneSet oldSet1 = new StoneSet(Arrays.asList(blueOne, redOne, blackOne, - redTwo, redThree, redFour, blackTwo, blackThree)); - StoneSet oldSet2 = new StoneSet( - Arrays.asList(blueTwo, blackFour, blackFive)); + StoneSet oldSet1 = new StoneSet(Arrays.asList(blueOne, redOne, + blackOne, redTwo, redThree, redFour, blackTwo, blackThree)); + StoneSet oldSet2 = new StoneSet(Arrays.asList(blueTwo, blackFour, + blackFive)); table.drop(oldSet1, new Position(0, 0)); table.drop(oldSet2, new Position(0, 0)); mockHand.drop(blueThree, new Position(0, 0)); @@ -886,8 +898,8 @@ public class TurnControlTest { List> stones = new ArrayList>( mockHand.stones); - Collections - .sort(stones, new HumanTurnControl.HandStonePositionComparator()); + Collections.sort(stones, + new HumanTurnControl.HandStonePositionComparator()); assertEquals(stones.size(), 13); @@ -935,8 +947,8 @@ public class TurnControlTest { List> stones = new ArrayList>( mockHand.stones); - Collections - .sort(stones, new HumanTurnControl.HandStonePositionComparator()); + Collections.sort(stones, + new HumanTurnControl.HandStonePositionComparator()); assertEquals(stones.size(), 13); @@ -976,8 +988,8 @@ public class TurnControlTest { assertCollection(new ArrayList()); - Set expected = new HashSet( - Arrays.asList(redJoker, blackJoker)); + Set expected = new HashSet(Arrays.asList(redJoker, + blackJoker)); assertEquals(expected, mockHand.pickups); Set handStones = new HashSet(); @@ -1004,7 +1016,8 @@ public class TurnControlTest { assertCollection(Arrays.asList(blackJoker)); - Set expected = new HashSet(Arrays.asList(redJoker, black13)); + Set expected = new HashSet(Arrays.asList(redJoker, + black13)); assertEquals(expected, mockHand.pickups); Set handStones = new HashSet(); @@ -1020,12 +1033,15 @@ public class TurnControlTest { public void testTableDifference() { MockTable oldTable = new MockTable(); MockTable newTable = new MockTable(); - StoneSet oldSet1 = new StoneSet(Arrays.asList(blueOne, redOne, blackOne)); + StoneSet oldSet1 = new StoneSet( + Arrays.asList(blueOne, redOne, blackOne)); StoneSet oldSet2 = new StoneSet(blueTwo); oldTable.drop(oldSet1, new Position(0, 0)); oldTable.drop(oldSet2, new Position(0, 0)); - StoneSet newSet1 = new StoneSet(Arrays.asList(blueOne, blueTwo, blueFour)); - StoneSet newSet2 = new StoneSet(Arrays.asList(redOne, blackOne, blueThree)); + StoneSet newSet1 = new StoneSet(Arrays.asList(blueOne, blueTwo, + blueFour)); + StoneSet newSet2 = new StoneSet(Arrays.asList(redOne, blackOne, + blueThree)); newTable.drop(newSet1, new Position(0, 0)); newTable.drop(newSet2, new Position(0, 0)); @@ -1033,7 +1049,8 @@ public class TurnControlTest { expectedStones.add(blueThree); expectedStones.add(blueFour); - Set stones = AbstractTurnControl.tableDifference(oldTable, newTable); + Set stones = AbstractTurnControl.tableDifference(oldTable, + newTable); assertTrue(expectedStones.containsAll(stones)); assertTrue(stones.containsAll(expectedStones)); @@ -1050,14 +1067,15 @@ public class TurnControlTest { Stone blueTwo = new Stone(2, BLUE); Stone blueThree = new Stone(3, BLUE); Stone blueFour = new Stone(4, BLUE); - StoneSet oldSet1 = new StoneSet(Arrays.asList(blueOne, redOne, blackOne, - orangeOne)); - StoneSet oldSet2 = new StoneSet(Arrays.asList(blueTwo, blueThree, blueFour)); + StoneSet oldSet1 = new StoneSet(Arrays.asList(blueOne, redOne, + blackOne, orangeOne)); + StoneSet oldSet2 = new StoneSet(Arrays.asList(blueTwo, blueThree, + blueFour)); oldTable.drop(oldSet1, new Position(0, 0)); oldTable.drop(oldSet2, new Position(0, 0)); ITable newTable = (Table) oldTable.clone(); - List newSets = AbstractTurnControl.tableSetDifference(oldTable, - newTable); + List newSets = AbstractTurnControl.tableSetDifference( + oldTable, newTable); List vanishedSets = AbstractTurnControl.tableSetDifference( newTable, oldTable); @@ -1065,10 +1083,11 @@ public class TurnControlTest { assertTrue(vanishedSets.isEmpty()); newTable.pickUp(oldSet2); - newTable.drop(oldSet2.join(new StoneSet(new Stone(5, BLUE))), new Position( - 0, 0)); + newTable.drop(oldSet2.join(new StoneSet(new Stone(5, BLUE))), + new Position(0, 0)); newSets = AbstractTurnControl.tableSetDifference(oldTable, newTable); - vanishedSets = AbstractTurnControl.tableSetDifference(newTable, oldTable); + vanishedSets = AbstractTurnControl.tableSetDifference(newTable, + oldTable); assertFalse(newSets.isEmpty()); assertFalse(vanishedSets.isEmpty()); @@ -1078,11 +1097,13 @@ public class TurnControlTest { Stone redTwo = new Stone(2, RED); Stone redThree = new Stone(3, RED); Stone redFour = new Stone(4, RED); - StoneSet oldSet3 = new StoneSet(Arrays.asList(redTwo, redThree, redFour)); + StoneSet oldSet3 = new StoneSet( + Arrays.asList(redTwo, redThree, redFour)); ITable newTable2 = (Table) oldTable.clone(); newTable2.drop(oldSet3, new Position(0, 0)); newSets = AbstractTurnControl.tableSetDifference(oldTable, newTable2); - vanishedSets = AbstractTurnControl.tableSetDifference(newTable2, oldTable); + vanishedSets = AbstractTurnControl.tableSetDifference(newTable2, + oldTable); assertFalse(newSets.isEmpty()); assertTrue(vanishedSets.isEmpty()); -- cgit v1.2.3