From 2a31f0d9a6aa230ea499b09c49cdbccc7fc053b2 Mon Sep 17 00:00:00 2001 From: Ida Massow Date: Tue, 21 Jun 2011 02:19:48 +0200 Subject: Fix weitere tests git-svn-id: svn://sunsvr01.isp.uni-luebeck.de/swproj13/trunk@528 72836036-5685-4462-b002-a69064685172 --- test/jrummikub/control/turn/AIControlTest.java | 71 +++++++++++++------------- 1 file changed, 35 insertions(+), 36 deletions(-) (limited to 'test/jrummikub/control') diff --git a/test/jrummikub/control/turn/AIControlTest.java b/test/jrummikub/control/turn/AIControlTest.java index f58796e..91d0b94 100644 --- a/test/jrummikub/control/turn/AIControlTest.java +++ b/test/jrummikub/control/turn/AIControlTest.java @@ -1,22 +1,24 @@ package jrummikub.control.turn; -import static org.junit.Assert.*; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; import java.awt.Color; +import jrummikub.control.RoundControl; import jrummikub.model.GameSettings; +import jrummikub.model.GameState; import jrummikub.model.IHand; -import jrummikub.model.IPlayer; -import jrummikub.model.ITable; -import jrummikub.model.Player; +import jrummikub.model.IRoundState; import jrummikub.model.PlayerSettings; import jrummikub.model.PlayerSettings.Type; import jrummikub.model.Position; +import jrummikub.model.RoundState; import jrummikub.model.Stone; import jrummikub.model.StoneColor; -import jrummikub.model.Table; import jrummikub.util.IListener; -import jrummikub.util.IListener3; +import jrummikub.util.IListener2; import jrummikub.view.MockView; import org.junit.Before; @@ -26,10 +28,9 @@ import org.junit.Test; public class AIControlTest { ITurnControl aiControl; + IRoundState roundState; GameSettings gameSettings; PlayerSettings playerSettings; - IPlayer player; - ITable table; MockView view; boolean turnEnded; @@ -39,23 +40,24 @@ public class AIControlTest { @Before public void setUp() { aiControl = TurnControlFactory.getFactory(Type.COMPUTER).create(); - ((AIControl) aiControl).useBackgroundThread = false; + AIControl.useBackgroundThread = false; gameSettings = new GameSettings(); playerSettings = new PlayerSettings("ROBOT_01", Color.GRAY); - player = new Player(playerSettings); - table = new Table(gameSettings); + gameSettings.getPlayerList().add(playerSettings); + roundState = new RoundState(gameSettings, new GameState()); view = new MockView(); turnEnded = false; redealt = false; - aiControl.getEndOfTurnEvent().add(new IListener3() { - @Override - public void handle(IHand oldHand, ITable oldTable, ITable newTable) { - turnEnded = true; - } - - }); - + aiControl.getEndOfTurnEvent().add( + new IListener2() { + @Override + public void handle(IRoundState state, + RoundControl.InvalidTurnInfo value2) { + turnEnded = true; + roundState = state; + } + }); aiControl.getRedealEvent().add(new IListener() { @Override @@ -65,7 +67,7 @@ public class AIControlTest { }); - IHand hand = player.getHand(); + IHand hand = roundState.getActivePlayer().getHand(); hand.drop(new Stone(11, StoneColor.RED), new Position(0, 0)); hand.drop(new Stone(12, StoneColor.RED), new Position(0, 0)); hand.drop(new Stone(13, StoneColor.RED), new Position(0, 0)); @@ -73,47 +75,44 @@ public class AIControlTest { /** * @throws InterruptedException - * if timeout + * if timeout */ @Test(timeout = 10000) public void testTurnZeroNoRedealing() throws InterruptedException { - aiControl.setup( - new ITurnControl.TurnInfo(table, player.getHand(), player.getLaidOut(), - TurnMode.MAY_REDEAL), gameSettings, view); + aiControl.setup(new ITurnControl.TurnInfo(roundState, + TurnMode.MAY_REDEAL), gameSettings, view); aiControl.startTurn(); assertTrue(turnEnded); assertFalse(redealt); - assertEquals(table.getSize(), 0); + assertEquals(0, roundState.getTable().getSize()); } /** * @throws InterruptedException - * if timeout + * if timeout */ @Test(timeout = 10000) public void testTurnZeroNotMelding() throws InterruptedException { - aiControl.setup( - new ITurnControl.TurnInfo(table, player.getHand(), player.getLaidOut(), - TurnMode.INSPECT_ONLY), gameSettings, view); + aiControl.setup(new ITurnControl.TurnInfo(roundState, + TurnMode.INSPECT_ONLY), gameSettings, view); aiControl.startTurn(); assertTrue(turnEnded); assertFalse(redealt); - assertEquals(table.getSize(), 0); + assertEquals(0, roundState.getTable().getSize()); } /** * @throws InterruptedException - * if timeout + * if timeout */ @Test(timeout = 10000) public void testNormalTurnMelding() throws InterruptedException { - aiControl.setup( - new ITurnControl.TurnInfo(table, player.getHand(), player.getLaidOut(), - TurnMode.NORMAL_TURN), gameSettings, view); + aiControl.setup(new ITurnControl.TurnInfo(roundState, + TurnMode.NORMAL_TURN), gameSettings, view); aiControl.startTurn(); assertTrue(turnEnded); assertFalse(redealt); - assertEquals(table.getSize(), 1); - assertEquals(player.getHand().getSize(), 0); + assertEquals(1, roundState.getTable().getSize()); + assertEquals(0, roundState.getActivePlayer().getHand().getSize()); } } -- cgit v1.2.3