diff --git a/Projekte/mdga/model/src/test/java/pp/mdga/client/clientState/ClientStateTest.java b/Projekte/mdga/model/src/test/java/pp/mdga/client/clientState/ClientStateTest.java index c5c84b68..cf4fd4e1 100644 --- a/Projekte/mdga/model/src/test/java/pp/mdga/client/clientState/ClientStateTest.java +++ b/Projekte/mdga/model/src/test/java/pp/mdga/client/clientState/ClientStateTest.java @@ -1,115 +1,100 @@ package pp.mdga.client.clientState; -import org.junit.Before; -import org.junit.Test; +import org.junit.*; import pp.mdga.client.*; -import pp.mdga.client.CeremonyState; -import pp.mdga.client.ceremonyState.PodiumState; -import pp.mdga.client.ceremonyState.StatisticsState; -import pp.mdga.client.dialogState.LobbyState; -import pp.mdga.client.dialogState.NetworkDialogState; -import pp.mdga.client.dialogState.StartDialogState; +import pp.mdga.client.dialogState.*; +import pp.mdga.client.ceremonyState.*; import pp.mdga.client.gameState.*; -import pp.mdga.client.gameState.turnState.choosePieceState.*; -import pp.mdga.client.gameState.determineStartPlayer.DetermineStartPlayerStateMachine; import pp.mdga.client.gameState.turnState.*; -import pp.mdga.client.gameState.turnState.powerCardState.ChoosePowerCardState; -import pp.mdga.client.gameState.turnState.powerCardState.ShieldState; -import pp.mdga.client.gameState.turnState.powerCardState.SwapState; -import pp.mdga.client.SettingsState; -import pp.mdga.client.settingsState.AudioSettingsState; -import pp.mdga.client.settingsState.MainSettingsState; -import pp.mdga.client.settingsState.VideoSettingsState; +import pp.mdga.client.gameState.determineStartPlayerState.*; +import pp.mdga.client.gameState.turnState.choosePieceState.*; +import pp.mdga.client.gameState.turnState.powerCardState.*; +import pp.mdga.game.Game; +import pp.mdga.message.server.*; import pp.mdga.game.BonusCard; import pp.mdga.game.Color; import pp.mdga.message.client.ClientMessage; import java.util.ArrayList; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertNotEquals; -import static org.junit.Assert.assertTrue; +import static org.junit.Assert.*; /** * this test-class tests the testcases T170-T239 */ public class ClientStateTest { - //sets the variables for the states - private AnimationState animationState; - private AudioSettingsState audioSettingsState; - private CeremonyState ceremonyState; - private CeremonyStateMachine ceremonyStateMachine; - private ChoosePieceState choosePieceState; - private ChoosePieceStateMachine choosePieceStateMachine; - private ChoosePowerCardState choosePowerCardState; - private ClientAutomaton clientAutomaton; + //declare game here + private Game game; + + //declare IP-Address + private static final String IP = "168.192.88.101"; + + //declare states here + private AnimationState animation; + private CeremonyState ceremony; + private ChoosePieceState choosePiece; + private ChoosePowerCardState choosePowerCard; private ClientGameLogic clientGameLogic; - private DetermineStartPlayerState determineStartPlayerState; - private DetermineStartPlayerStateMachine determineStartPlayerStateMachine; - private DialogsState dialogsState; - private DialogsStateMachine dialogsStateMachine; + private DetermineStartPlayerState determineStartPlayer; + private DialogsState dialogs; private GameState gameState; - private GameStateMachine gameStateMachine; - private InterruptState interruptState; - private LobbyState lobbyState; - private MainSettingsState mainSettingsState; - private MovePieceState movePieceState; - private NetworkDialogState networkDialogState; - private NoPieceState noPieceState; - private PlayPowerCardState playPowerCardState; + private InterruptState interrupt; + private LobbyState lobby; + private MovePieceState movePiece; + private NetworkDialogState networkDialog; + private NoPieceState noPiece; + private PlayPowerCardState playPowerCard; private PodiumState podium; - private PowerCardState powerCardState; - private PowerCardStateMachine powerCardStateMachine; - private RollDiceState rollDiceState; - private RollRankingDice rollRankingDice; - private SelectPieceState selectPieceState; - private SettingsState settingsState; - private SettingsStateMachine settingsStateMachine; - private ShieldState shieldState; - private SpectatorState spectatorState; - private StartDialogState startDialogState; - private StartPieceState startPieceState; + private PowerCardState powerCard; + private RollDiceState rollDice; + private RollRankingDiceState rollRankingDice; + private SelectPieceState selectPiece; + private ShieldState shield; + private SpectatorState spectator; + private StartDialogState startDialog; + private StartPieceState startPiece; private StatisticsState statistics; - private SwapState swapState; + private SwapState swap; private TurnState turnState; - private TurnStateMachine turnStateMachine; - private VideoSettingsState videoSettingsState; - private WaitingState waitingState; - private WaitingPieceState waitingPieceState; - private WaitRanking waitRanking; + private WaitingState waiting; + private WaitingPieceState waitingPiece; + private WaitRankingState waitRanking; - //sets the variables for the messages - private ActivePlayer activePlayer; - private AnyPiece anyPiece; - private Briefing briefing; + //declare server-messages here + private ActivePlayerMessage activePlayer; + private AnyPieceMessage anyPiece; + private BriefingMessage briefing; private CeremonyMessage ceremonyMessage; - private Dice dice; - private DiceAgain diceAgain; - private DiceNow diceNow; - private EndOfTurn endOfTurn; - private LobbyAccept lobbyAccept; - private LobbyDeny lobbyDeny; - private LobbyPlayerJoin lobbyPlayerJoin; - private LobbyPlayerLeave lobbyPlayerLeave; + private DieMessage die; + private DiceAgainMessage diceAgain; + private DiceNowMessage diceNow; + private EndOfTurnMessage endOfTurn; + private LobbyAcceptMessage lobbyAccept; + private LobbyDenyMessage lobbyDeny; + private LobbyPlayerJoinMessage lobbyPlayerJoin; + private LobbyPlayerLeaveMessage lobbyPlayerLeave; private MoveMessage moveMessage; - private NoTurn noTurn; - private PauseGame pauseGame; - private PossibleCard possibleCard; - private PossiblePiece possiblePiece; - private RankingResponse rankingResponce; - private RankingRollAgain rankingRollAgain; - private ReconnectBriefing reconnectBriefing; - private ResumeGame resumeGame; - private ServerStartGame startGame; - private StartPieceState startPieceStateMessage; - private UpdateReady updateReady; - private UpdateTSK updateTSK; - private WaitPiece waitPiece; - - private PlayCard playCardSwap; - private PlayCard playCardShield; - private PlayCard playCardTurbo; + private NoTurnMessage noTurn; + private PauseGameMessage interruptMessage; + private PlayCardMessage playCardSwap; + private PlayCardMessage playCardShield; + private PlayCardMessage playCardTurbo; + private PossibleCardMessage possibleCard; + private PossiblePieceMessage possiblePiece; + private PossiblePieceMessage possiblePieceSwap; + private PossiblePieceMessage possiblePieceShield; + private RankingResponseMessage rankingResponse; + private RankingRollAgainMessage rankingRollAgain; + private ReconnectBriefingMessage reconnectBriefing; + private ResumeGameMessage resumeGame; + private ServerStartGameMessage startGame; + private StartPieceMessage startPieceMessage; + private UpdateReadyMessage updateReady; + private UpdateTSKMessage updateTSK; + private WaitPieceMessage waitPiece; + private SpectatorMessage spectatorMessage; + private SelectPieceMessage selectPieceMessage; private int from; private String name; @@ -118,51 +103,10 @@ public class ClientStateTest { private BonusCard shieldCard; private BonusCard turboCard; - private pp.mdga.game.Game game; - @Before public void setUp() { //initialize the game - game = new pp.mdga.game.Game(); - - //initialize the playerID - from=1234; - name="Daniel"; - color=Color.ARMY; - swapCard = BonusCard.SWAP; - shieldCard = BonusCard.SHIELD; - turboCard = BonusCard.TURBO; - - //initialize the messages from the server - activePlayer = new ActivePlayer(color); - anyPiece = new AnyPiece(); - briefing = new Briefing(); - ceremonyMessage = new CeremonyMessage(); - dice = new Dice(6,new ArrayList<>()); - diceAgain = new DiceAgain(); - diceNow = new DiceNow(); - endOfTurn = new EndOfTurn(); - lobbyAccept = new LobbyAccept(); - lobbyDeny = new LobbyDeny(); - lobbyPlayerJoin = new LobbyPlayerJoin(name); - lobbyPlayerLeave = new LobbyPlayerLeave(name,color); - moveMessage = new MoveMessage("www");//Todo - noTurn = new NoTurn(); - pauseGame = new PauseGame(); - playCardSwap = new PlayCard(swapCard,"www");//Todo - playCardShield = new PlayCard(shieldCard,"www");//Todo - playCardTurbo = new PlayCard(turboCard,"www");//Todo - possibleCard = new PossibleCard(); - possiblePiece = new PossiblePiece(); - rankingResponce = new RankingResponse(); - rankingRollAgain = new RankingRollAgain(); - reconnectBriefing = new ReconnectBriefing(game); - resumeGame = new ResumeGame(); - startGame = new ServerStartGame(); - startPieceStateMessage = new StartPieceState(); //Todo wrong class - updateReady = new UpdateReady(color,true); - updateTSK = new UpdateTSK(name,color); - waitPiece = new WaitPiece(); + game = new Game(); //initialize the clientGameLogic clientGameLogic = new ClientGameLogic(game, new ClientSender() { @@ -171,62 +115,88 @@ public void send(ClientMessage msg) { } }); - clientAutomaton = (ClientAutomaton) clientGameLogic.getState(); - //initialize the settings - mainSettingsState = new MainSettingsState(settingsStateMachine,clientGameLogic); - videoSettingsState = new VideoSettingsState(settingsStateMachine,clientGameLogic); - audioSettingsState = new AudioSettingsState(settingsStateMachine,clientGameLogic); - settingsState = new SettingsState(clientAutomaton,clientGameLogic); + //initialize the playerID + from = 1234; + name = "Daniel"; + color = Color.ARMY; + swapCard = BonusCard.SWAP; + shieldCard = BonusCard.SHIELD; + turboCard = BonusCard.TURBO; - //initialize the stateMachines - ceremonyStateMachine = ceremonyState.getCeremonyStateMachine(); - choosePieceStateMachine = choosePieceState.getChoosePieceStateMachine(); - determineStartPlayerStateMachine = determineStartPlayerState.getDetermineStartPlayerStateMachine(); - dialogsStateMachine = dialogsState.getDialogsStateMachine(); - gameStateMachine = gameState.getGameStateMachine(); - powerCardStateMachine = powerCardState.getPowerCardStateMachine(); - settingsStateMachine = settingsState.getSettingsStateMachine(); - turnStateMachine = turnState.getTurnStateMachine(); - + //initialize the messages from the server + activePlayer = new ActivePlayerMessage(color); + anyPiece = new AnyPieceMessage(); + briefing = new BriefingMessage(); + ceremonyMessage = new CeremonyMessage(); + die = new DieMessage(6, new ArrayList<>()); + diceAgain = new DiceAgainMessage(); + diceNow = new DiceNowMessage(); + endOfTurn = new EndOfTurnMessage(); + lobbyAccept = new LobbyAcceptMessage(); + lobbyDeny = new LobbyDenyMessage(); + lobbyPlayerJoin = new LobbyPlayerJoinMessage(from,name); + lobbyPlayerLeave = new LobbyPlayerLeaveMessage(from, color); + moveMessage = new MoveMessage("www",false, 20);//Todo + noTurn = new NoTurnMessage(); + interruptMessage = new PauseGameMessage(); + playCardSwap = PlayCardMessage.swap("www", "www");//Todo + playCardShield = PlayCardMessage.shield( "www");//Todo + playCardTurbo = PlayCardMessage.turbo(1);//Todo + possibleCard = new PossibleCardMessage(); + possiblePieceShield = PossiblePieceMessage.shieldPossiblePieces(new ArrayList<>()); //TODO + possiblePieceSwap = PossiblePieceMessage.swapPossiblePieces(new ArrayList<>(),new ArrayList<>()); //TODO + possiblePiece = new PossiblePieceMessage(); + rankingResponse = new RankingResponseMessage(); + rankingRollAgain = new RankingRollAgainMessage(); + reconnectBriefing = new ReconnectBriefingMessage(game); + resumeGame = new ResumeGameMessage(); + startGame = new ServerStartGameMessage(); + startPieceMessage = new StartPieceMessage("www"); //Todo wrong class + updateReady = new UpdateReadyMessage(color, true); + updateTSK = new UpdateTSKMessage(name, color); + waitPiece = new WaitPieceMessage(); + interruptMessage = new PauseGameMessage(); + spectatorMessage = new SpectatorMessage(); + selectPieceMessage = new SelectPieceMessage(); //initialize the states - dialogsState = new DialogsState(clientAutomaton,clientGameLogic); - gameState = new GameState(clientAutomaton,clientGameLogic); - ceremonyState = new CeremonyState(clientAutomaton,clientGameLogic); - interruptState = new InterruptState(clientAutomaton,clientGameLogic,gameState); + dialogs = clientGameLogic.getDialogs(); + gameState = clientGameLogic.getGameState(); + ceremony = clientGameLogic.getCeremony(); + interrupt = clientGameLogic.getInterrupt(); - startDialogState = new StartDialogState(dialogsStateMachine,clientGameLogic); - networkDialogState = new NetworkDialogState(dialogsStateMachine,clientGameLogic); - lobbyState = new LobbyState(dialogsStateMachine,clientGameLogic); + startDialog = dialogs.getStartDialog(); + networkDialog = dialogs.getNetworkDialog(); + lobby = dialogs.getLobby(); - podium = new PodiumState(ceremonyStateMachine,clientGameLogic); - statistics = new StatisticsState(ceremonyStateMachine,clientGameLogic); + podium = ceremony.getPodiumState(); + statistics = ceremony.getStatisticsState(); - determineStartPlayerState = new DetermineStartPlayerState(gameStateMachine,clientGameLogic); - waitingState = new WaitingState(gameStateMachine,clientGameLogic); - animationState = new AnimationState(gameStateMachine,clientGameLogic); - turnState = new TurnState(gameStateMachine,clientGameLogic); - spectatorState = new SpectatorState(gameStateMachine,clientGameLogic); + determineStartPlayer = gameState.getDetermineStartPlayer(); + waiting = gameState.getWaiting(); + animation = gameState.getAnimation(); + turnState = gameState.getTurn(); + spectator = gameState.getSpectator(); - rollRankingDice = new RollRankingDice(determineStartPlayerStateMachine,clientGameLogic); - waitRanking = new WaitRanking(determineStartPlayerStateMachine,clientGameLogic); + rollRankingDice = determineStartPlayer.getRollRankingDice(); + waitRanking = determineStartPlayer.getWaitRanking(); - powerCardState = new PowerCardState(turnStateMachine,clientGameLogic); - playPowerCardState = new PlayPowerCardState(turnStateMachine,clientGameLogic); - rollDiceState = new RollDiceState(turnStateMachine,clientGameLogic); - choosePieceState = new ChoosePieceState(turnStateMachine,clientGameLogic); - movePieceState = new MovePieceState(turnStateMachine,clientGameLogic); + powerCard = turnState.getPowerCard(); + playPowerCard = turnState.getPlayPowerCard(); + rollDice = turnState.getRollDice(); + choosePiece = turnState.getChoosePiece(); + movePiece = turnState.getMovePiece(); - choosePowerCardState = new ChoosePowerCardState(powerCardStateMachine,clientGameLogic); - shieldState =new ShieldState(powerCardStateMachine,clientGameLogic); - swapState = new SwapState(powerCardStateMachine,clientGameLogic); + choosePowerCard = powerCard.getChoosePowerCard(); + shield = powerCard.getShield(); + swap = powerCard.getSwap(); - noPieceState = new NoPieceState(choosePieceStateMachine,clientGameLogic); - waitingPieceState = new WaitingPieceState(choosePieceStateMachine,clientGameLogic); - selectPieceState = new SelectPieceState(choosePieceStateMachine,clientGameLogic); - startPieceState = new StartPieceState(choosePieceStateMachine,clientGameLogic); + noPiece = choosePiece.getNoPiece(); + waitingPiece = choosePiece.getWaitingPiece(); + selectPiece = choosePiece.getSelectPiece(); + startPiece = choosePiece.getStartPiece(); } /** @@ -234,14 +204,10 @@ public void send(ClientMessage msg) { */ @Test public void testInitialStateClientState() { - //tests if the clientAutomaton is in Dialogs - assertNotEquals(clientAutomaton.getState() , null); - assertTrue(clientAutomaton.getState() instanceof DialogsState); - DialogsState dialogsState = (DialogsState) clientAutomaton.getState(); - DialogsStateMachine dialogsStateMachine1 = dialogsState.getDialogsStateMachine(); + //tests if the clientGameLogic is in Dialogs + assertEquals(clientGameLogic.getState(), dialogs); //tests if the statemachine is in StartDialog - assertNotEquals(dialogsStateMachine1.getState(), null); - assertTrue(dialogsStateMachine1.getState() instanceof StartDialogState); + assertEquals(dialogs.getState(), startDialog); } /** @@ -250,24 +216,57 @@ public void testInitialStateClientState() { @Test public void testDialogsToGame() { //tests if the client is in Dialogs - clientAutomaton.gotoState(dialogsState); - assertTrue(clientAutomaton.getState() instanceof DialogsState); + clientGameLogic.setState(dialogs); + assertEquals(clientGameLogic.getState(), dialogs); + + //sends all messages, which don't indicate a statechange + clientGameLogic.received(activePlayer); + clientGameLogic.received(anyPiece); + clientGameLogic.received(briefing); + clientGameLogic.received(ceremonyMessage); + clientGameLogic.received(die); + clientGameLogic.received(diceAgain); + clientGameLogic.received(diceNow); + clientGameLogic.received(endOfTurn); + clientGameLogic.received(lobbyAccept); + clientGameLogic.received(lobbyDeny); + clientGameLogic.received(lobbyPlayerJoin); + clientGameLogic.received(lobbyPlayerLeave); + clientGameLogic.received(moveMessage); + clientGameLogic.received(noTurn); + clientGameLogic.received(interruptMessage); + clientGameLogic.received(playCardSwap); + clientGameLogic.received(playCardShield); + clientGameLogic.received(playCardTurbo); + clientGameLogic.received(possibleCard); + clientGameLogic.received(possiblePiece); + clientGameLogic.received(rankingResponse); + clientGameLogic.received(rankingRollAgain); + clientGameLogic.received(reconnectBriefing); + clientGameLogic.received(resumeGame); + //clientGameLogic.received(startGame); + clientGameLogic.received(startPieceMessage); + clientGameLogic.received(updateReady); + clientGameLogic.received(updateTSK); + clientGameLogic.received(waitPiece); + clientGameLogic.received(spectatorMessage); + clientGameLogic.received(selectPieceMessage); + + //tests if the client is still in lobby + assertEquals(clientGameLogic.getState(), dialogs); + assertEquals(dialogs.getState(), lobby); //sends the startGame-Message to the client - clientGameLogic.receive(startGame); + clientGameLogic.received(startGame); //tests if the client is in the gameState after receiving the message - assertTrue(clientAutomaton.getState() instanceof GameState); + assertEquals(clientGameLogic.getState(), gameState); //tests if the new State of the GameStateMachine is in DetermineStartPlayer - GameState gameState1 = (GameState) clientAutomaton.getState(); - GameStateMachine gameStateMachine1 = gameState1.getGameStateMachine(); - assertTrue(gameStateMachine1.getState() instanceof DetermineStartPlayerState); + assertEquals(gameState.getState(), determineStartPlayer); //tests if the new State of DetermineStartPlayer is RollRankingDice - DetermineStartPlayerState determineStartPlayerState1 =(DetermineStartPlayerState) gameStateMachine1.getState(); - DetermineStartPlayerStateMachine determineStartPlayerStateMachine1 = determineStartPlayerState1.getDetermineStartPlayerStateMachine(); - assertTrue(determineStartPlayerStateMachine1.getState() instanceof RollRankingDice); + assertEquals(determineStartPlayer.getState(), rollRankingDice); } /** @@ -275,7 +274,14 @@ public void testDialogsToGame() { */ @Test public void testDialogsToClientStateEndState() { - //Todo Implementation goes here + //sends the client in dialogs + clientGameLogic.setState(dialogs); + assertEquals(clientGameLogic.getState(), dialogs); + + //sends dialogs in startDialog-state + dialogs.setState(startDialog); + assertEquals(dialogs.getState(), startDialog); + //TODO how????????? } @@ -284,38 +290,69 @@ public void testDialogsToClientStateEndState() { */ @Test public void testClientGameToCeremony() { - //sends the ClientAutomaton in GameState - clientAutomaton.gotoState(gameState); - assertTrue(clientAutomaton.getState() instanceof GameState); + //sends the ClientGameLogic in GameState + clientGameLogic.setState(gameState); + assertEquals(clientGameLogic.getState(), gameState); + + clientGameLogic.received(activePlayer); + clientGameLogic.received(anyPiece); + clientGameLogic.received(briefing); + //clientGameLogic.received(ceremonyMessage); + clientGameLogic.received(die); + clientGameLogic.received(diceAgain); + clientGameLogic.received(diceNow); + clientGameLogic.received(endOfTurn); + clientGameLogic.received(lobbyAccept); + clientGameLogic.received(lobbyDeny); + clientGameLogic.received(lobbyPlayerJoin); + clientGameLogic.received(lobbyPlayerLeave); + clientGameLogic.received(moveMessage); + clientGameLogic.received(noTurn); + //clientGameLogic.received(interruptMessage); + clientGameLogic.received(playCardSwap); + clientGameLogic.received(playCardShield); + clientGameLogic.received(playCardTurbo); + clientGameLogic.received(possibleCard); + clientGameLogic.received(possiblePiece); + clientGameLogic.received(rankingResponse); + clientGameLogic.received(rankingRollAgain); + clientGameLogic.received(reconnectBriefing); + clientGameLogic.received(resumeGame); + clientGameLogic.received(startGame); + clientGameLogic.received(startPieceMessage); + clientGameLogic.received(updateReady); + clientGameLogic.received(updateTSK); + clientGameLogic.received(waitPiece); + clientGameLogic.received(spectatorMessage); + clientGameLogic.received(selectPieceMessage); + + //tests if the client is still in game-state + assertEquals(clientGameLogic.getState(), gameState); //sends the Ceremony-Message to the client - clientGameLogic.receive(ceremonyMessage); + clientGameLogic.received(ceremonyMessage); //tests if the client is in the ceremony after receiving the message - assertTrue(clientAutomaton.getState() instanceof CeremonyState); + assertEquals(clientGameLogic.getState(), ceremony); //tests if the state of ceremony is Podium - CeremonyState ceremonyState1 = (CeremonyState) clientAutomaton.getState(); - CeremonyStateMachine ceremonyStateMachine1 = ceremonyState1.getCeremonyStateMachine(); - assertTrue(ceremonyStateMachine1.getState() instanceof PodiumState); + assertEquals(ceremony.getState(), podium); } /** - * UC-ClientState-05: Test the transition from ClientGame substates to Interrupt. + * UC-ClientState-05: Test the transition from ClientGame sub-states to Interrupt. */ @Test public void testClientGameSubStatesToInterrupt() { - //sends the ClientAutomaton in GameState - clientAutomaton.gotoState(gameState); - - //tests if the client is in GameState - assertTrue(clientAutomaton.getState() instanceof GameState); + //sends the ClientGameLogic in GameState + clientGameLogic.setState(gameState); + assertEquals(clientGameLogic.getState(), gameState); //sends the Ceremony-Message to the client - clientGameLogic.receive(interruptState); + clientGameLogic.received(interruptMessage); //tests if the client-automaton is in the interrupt state - assertTrue(clientAutomaton.getState() instanceof InterruptState); + assertEquals(clientGameLogic.getState(), interrupt); } /** @@ -323,7 +360,15 @@ public void testClientGameSubStatesToInterrupt() { */ @Test public void testGameToDialogs() { - // Todo Implementation goes here + //sends the client into the GameState + clientGameLogic.setState(gameState); + assertEquals(clientGameLogic.getState(), gameState); + + //receives a GameClosedMessage + clientGameLogic.received();//TODO + + assertEquals(clientGameLogic.getState(), dialogs); + assertEquals(dialogs.getState(), startDialog); } /** @@ -331,13 +376,45 @@ public void testGameToDialogs() { */ @Test public void testStayInInterrupt() { - //sends the ClientAutomaton in Interrupt - clientAutomaton.gotoState(interruptState); - assertTrue(clientAutomaton.getState() instanceof InterruptState); + //sends the ClientGameLogic in Interrupt + clientGameLogic.setState(interrupt); + assertEquals(clientGameLogic.getState(), interrupt); - //Todo send all messages except the continue-message + //sends all messages, which don't indicate a statechange + clientGameLogic.received(activePlayer); + clientGameLogic.received(anyPiece); + clientGameLogic.received(briefing); + clientGameLogic.received(ceremonyMessage); + clientGameLogic.received(die); + clientGameLogic.received(diceAgain); + clientGameLogic.received(diceNow); + clientGameLogic.received(endOfTurn); + clientGameLogic.received(lobbyAccept); + clientGameLogic.received(lobbyDeny); + clientGameLogic.received(lobbyPlayerJoin); + clientGameLogic.received(lobbyPlayerLeave); + clientGameLogic.received(moveMessage); + clientGameLogic.received(noTurn); + clientGameLogic.received(interruptMessage); + clientGameLogic.received(playCardSwap); + clientGameLogic.received(playCardShield); + clientGameLogic.received(playCardTurbo); + clientGameLogic.received(possibleCard); + clientGameLogic.received(possiblePiece); + clientGameLogic.received(rankingResponse); + clientGameLogic.received(rankingRollAgain); + clientGameLogic.received(reconnectBriefing); + //clientGameLogic.received(resumeGame); commented out, because it indicates a state-change to gameState + clientGameLogic.received(startGame); + clientGameLogic.received(startPieceMessage); + clientGameLogic.received(updateReady); + clientGameLogic.received(updateTSK); + clientGameLogic.received(waitPiece); + clientGameLogic.received(spectatorMessage); + clientGameLogic.received(selectPieceMessage); - assertTrue(clientAutomaton.getState() instanceof InterruptState); + //tests if the client is in the interrupt + assertEquals(clientGameLogic.getState(), interrupt); } /** @@ -345,14 +422,15 @@ public void testStayInInterrupt() { */ @Test public void testClientInterruptToGame() { - //sends the ClientAutomaton in Interrupt - clientAutomaton.gotoState(interruptState); - assertTrue(clientAutomaton.getState() instanceof InterruptState); + //sends the ClientGameLogic in Interrupt + clientGameLogic.setState(interrupt); + assertEquals(clientGameLogic.getState(), interrupt); - //Todo sends the continue-message + //sends the continue message + clientGameLogic.received(resumeGame); //tests if the client is in the game - assertTrue(clientAutomaton.getState() instanceof GameState); + assertEquals(clientGameLogic.getState(), gameState); } /** @@ -360,16 +438,16 @@ public void testClientInterruptToGame() { */ @Test public void testInterruptToDialogs() { - //sends the ClientAutomaton in Interrupt - clientAutomaton.gotoState(interruptState); - assertTrue(clientAutomaton.getState() instanceof InterruptState); + //sends the ClientGameLogic in Interrupt + clientGameLogic.setState(interrupt); + assertEquals(clientGameLogic.getState(), interrupt); - //Todo send the server-closed message and the leave option + //Todo send the server-closed + clientGameLogic.received(); - assertTrue(clientAutomaton.getState() instanceof DialogsState); - DialogsState dialogsState1 = (DialogsState) clientAutomaton.getState(); - DialogsStateMachine dialogsStateMachine1 = dialogsState1.getDialogsStateMachine(); - assertTrue(dialogsStateMachine1.getState() instanceof StartDialogState); + //tests if the client is in the startDialog + assertEquals(clientGameLogic.getState(), dialogs); + assertEquals(dialogs.getState(), startDialog); } /** @@ -378,19 +456,18 @@ public void testInterruptToDialogs() { @Test public void testCeremonyToDialogs() { //send the client in the ceremony - clientAutomaton.gotoState(ceremonyState); - assertTrue(clientAutomaton.getState() instanceof CeremonyState); + clientGameLogic.setState(ceremony); + assertEquals(clientGameLogic.getState(), ceremony); //sends the ceremony machine in the statistics - ceremonyStateMachine.gotoState(statistics); - assertTrue(ceremonyStateMachine.getState() instanceof StatisticsState); + ceremony.setState(statistics); + assertEquals(ceremony.getState(), statistics); - //Todo simulate the button next + //simulate the button next + clientGameLogic.selectNext(); - assertTrue(clientAutomaton.getState() instanceof DialogsState); - DialogsState dialogsState1 = (DialogsState) clientAutomaton.getState(); - DialogsStateMachine dialogsStateMachine1 = dialogsState1.getDialogsStateMachine(); - assertTrue(dialogsStateMachine1.getState() instanceof StartDialogState); + assertEquals(clientGameLogic.getState(), dialogs); + assertEquals(dialogs.getState(), startDialog); } /** @@ -398,18 +475,24 @@ public void testCeremonyToDialogs() { */ @Test public void testStartDialogToNetworkDialog1() { - // sends the clientAutomaton in StartDialog - clientAutomaton.gotoState(dialogsState); - assertTrue(clientAutomaton.getState() instanceof DialogsState); - //sends the DialogsStateMachine in StartDialog - dialogsStateMachine.gotoState(startDialogState); - assertTrue(dialogsStateMachine.getState() instanceof StartDialogState); + // sends the clientGameLogic in StartDialog + clientGameLogic.setState(dialogs); + assertEquals(clientGameLogic.getState(), dialogs); - //todo simulate pushBtn as client or host + //sends the DialogsState in StartDialog + dialogs.setState(startDialog); + assertEquals(dialogs.getState(), startDialog); - assertTrue(clientAutomaton.getState() instanceof DialogsState); - assertTrue(dialogsStateMachine.getState() instanceof NetworkDialogState); + //simulate the button-push for the join-Button + clientGameLogic.selectJoin(name); + + //tests if the client is in the network-dialog + assertEquals(clientGameLogic.getState(), dialogs); + assertEquals(dialogs.getState(), networkDialog); + + //tests if the client is not host + assertFalse(clientGameLogic.isHost()); } /** @@ -417,18 +500,24 @@ public void testStartDialogToNetworkDialog1() { */ @Test public void testStartDialogToNetworkDialog2() { - // sends the clientAutomaton in StartDialog - clientAutomaton.gotoState(dialogsState); - assertTrue(clientAutomaton.getState() instanceof DialogsState); - //sends the DialogsStateMachine in StartDialog - dialogsStateMachine.gotoState(startDialogState); - assertTrue(dialogsStateMachine.getState() instanceof StartDialogState); + // sends the clientGameLogic in StartDialog + clientGameLogic.setState(dialogs); + assertEquals(clientGameLogic.getState(), dialogs); - //todo simulate pushBtn as client or host + //sends the DialogsState in StartDialog + dialogs.setState(startDialog); + assertEquals(dialogs.getState(), startDialog); - assertTrue(clientAutomaton.getState() instanceof DialogsState); - assertTrue(dialogsStateMachine.getState() instanceof NetworkDialogState); + //simulate the button-push for the host-Button + clientGameLogic.selectHost(name); + + //tests if the client is in the network-dialog + assertEquals(clientGameLogic.getState(), dialogs); + assertEquals(dialogs.getState(), networkDialog); + + //tests if the client is host + assertTrue(clientGameLogic.isHost()); } /** @@ -436,8 +525,20 @@ public void testStartDialogToNetworkDialog2() { */ @Test public void testStartDialogToDialogsEndState() { - // Implementation goes here - //TODO how to test? + + // sends the clientGameLogic in StartDialog + clientGameLogic.setState(dialogs); + assertEquals(clientGameLogic.getState(), dialogs); + + //sends the DialogsState in StartDialog + dialogs.setState(startDialog); + assertEquals(dialogs.getState(), startDialog); + + //simulate the button-push for the host-Button + clientGameLogic.selectLeave(); + + //tests if the client is closed + //TODO } /** @@ -445,18 +546,20 @@ public void testStartDialogToDialogsEndState() { */ @Test public void testNetworkDialogToStartDialog() { - // sends the clientAutomaton in StartDialog - clientAutomaton.gotoState(dialogsState); - assertTrue(clientAutomaton.getState() instanceof DialogsState); + // sends the clientGameLogic in StartDialog + clientGameLogic.setState(dialogs); + assertEquals(clientGameLogic.getState(), dialogs); - //sends the DialogsStateMachine in NetworkDialog - dialogsStateMachine.gotoState(networkDialogState); - assertTrue(dialogsStateMachine.getState() instanceof NetworkDialogState); + //sends the DialogsState in NetworkDialog + dialogs.setState(networkDialog); + assertEquals(dialogs.getState(), networkDialog); - //todo simulate pushBtn + //simulate the leave-Btn push + clientGameLogic.selectLeave(); - assertTrue(clientAutomaton.getState() instanceof DialogsState); - assertTrue(dialogsStateMachine.getState() instanceof StartDialogState); + //tests if the client is in startDialog + assertEquals(clientGameLogic.getState(), dialogs); + assertEquals(dialogs.getState(), startDialog); } /** @@ -464,18 +567,30 @@ public void testNetworkDialogToStartDialog() { */ @Test public void testNetworkDialogToNetworkDialog1() { - // sends the clientAutomaton in StartDialog - clientAutomaton.gotoState(dialogsState); - assertTrue(clientAutomaton.getState() instanceof DialogsState); + // sends the clientGameLogic in StartDialog + clientGameLogic.setState(dialogs); + assertEquals(clientGameLogic.getState(), dialogs); - //sends the DialogsStateMachine in NetworkDialog - dialogsStateMachine.gotoState(networkDialogState); - assertTrue(dialogsStateMachine.getState() instanceof NetworkDialogState); + //sends the DialogsState in NetworkDialog + dialogs.setState(networkDialog); + assertEquals(dialogs.getState(), networkDialog); - //todo test receiving all messages and making input + //simulate all input, that don't indicate a state-change + clientGameLogic.selectPiece(null); //TODO + clientGameLogic.selectCard(null); + clientGameLogic.selectTsk(color); + clientGameLogic.selectDice(); + clientGameLogic.selectName(name); + clientGameLogic.selectReady(true); + clientGameLogic.selectHost(name); + //clientGameLogic.selectLeave(); commented because it indicate a state-change to start-dialog + //clientGameLogic.selectJoin(name); commented because it indicate a state-change to lobby + clientGameLogic.selectAnimationEnd(); + clientGameLogic.selectStart(); - assertTrue(clientAutomaton.getState() instanceof DialogsState); - assertTrue(dialogsStateMachine.getState() instanceof NetworkDialogState); + //tests if the client is still in the network-dialog + assertEquals(clientGameLogic.getState(), dialogs); + assertEquals(dialogs.getState(), networkDialog); } /** @@ -483,23 +598,23 @@ public void testNetworkDialogToNetworkDialog1() { */ @Test public void testNetworkDialogToNetworkDialog2() { - // sends the clientAutomaton in StartDialog - clientAutomaton.gotoState(dialogsState); - assertTrue(clientAutomaton.getState() instanceof DialogsState); + // sends the clientGameLogic in StartDialog + clientGameLogic.setState(dialogs); + assertEquals(clientGameLogic.getState(), dialogs); - //sends the DialogsStateMachine in NetworkDialog - dialogsStateMachine.gotoState(networkDialogState); - assertTrue(dialogsStateMachine.getState() instanceof NetworkDialogState); + //sends the DialogsState in NetworkDialog + dialogs.setState(networkDialog); + assertEquals(dialogs.getState(), networkDialog); //todo simulate try connect to server ith wrong variables - assertTrue(clientAutomaton.getState() instanceof DialogsState); - assertTrue(dialogsStateMachine.getState() instanceof NetworkDialogState); + assertEquals(clientGameLogic.getState(), dialogs); + assertEquals(dialogs.getState(), networkDialog); - //todo simulate try connect to server with send: join-lobby and receive lobby-refuse-message + //todo simulate try connect to server with send: join-lobby and received lobby-refuse-message - assertTrue(clientAutomaton.getState() instanceof DialogsState); - assertTrue(dialogsStateMachine.getState() instanceof NetworkDialogState); + assertEquals(clientGameLogic.getState(), dialogs); + assertEquals(dialogs.getState(), networkDialog); } /** @@ -507,18 +622,18 @@ public void testNetworkDialogToNetworkDialog2() { */ @Test public void testNetworkDialogToLobby() { - // sends the clientAutomaton in StartDialog - clientAutomaton.gotoState(dialogsState); - assertTrue(clientAutomaton.getState() instanceof DialogsState); + // sends the clientGameLogic in StartDialog + clientGameLogic.setState(dialogs); + assertEquals(clientGameLogic.getState(), dialogs); - //sends the DialogsStateMachine in NetworkDialog - dialogsStateMachine.gotoState(networkDialogState); - assertTrue(dialogsStateMachine.getState() instanceof NetworkDialogState); + //sends the DialogsState in NetworkDialog + dialogs.setState(networkDialog); + assertEquals(dialogs.getState(), networkDialog); //todo simulate connect to server with send lobby request - assertTrue(clientAutomaton.getState() instanceof DialogsState); - assertTrue(dialogsStateMachine.getState() instanceof LobbyState); + assertEquals(clientGameLogic.getState(), dialogs); + assertEquals(dialogs.getState(), lobby); } /** @@ -526,18 +641,20 @@ public void testNetworkDialogToLobby() { */ @Test public void testLobbyToStartDialog() { - // sends the clientAutomaton in StartDialog - clientAutomaton.gotoState(dialogsState); - assertTrue(clientAutomaton.getState() instanceof DialogsState); + // sends the clientGameLogic in StartDialog + clientGameLogic.setState(dialogs); + assertEquals(clientGameLogic.getState(), dialogs); - //sends the DialogsStateMachine in Lobby - dialogsStateMachine.gotoState(lobbyState); - assertTrue(dialogsStateMachine.getState() instanceof LobbyState); + //sends the DialogsState in Lobby + dialogs.setState(lobby); + assertEquals(dialogs.getState(), lobby); - //todo simulate leave the lobby + //simulate the leave-Btn + clientGameLogic.selectLeave(); - assertTrue(clientAutomaton.getState() instanceof DialogsState); - assertTrue(dialogsStateMachine.getState() instanceof StartDialogState); + //tests if the client is in the Start-Dialog + assertEquals(clientGameLogic.getState(), dialogs); + assertEquals(dialogs.getState(), startDialog); } /** @@ -545,18 +662,62 @@ public void testLobbyToStartDialog() { */ @Test public void testStayInLobby() { - // sends the clientAutomaton in StartDialog - clientAutomaton.gotoState(dialogsState); - assertTrue(clientAutomaton.getState() instanceof DialogsState); + // sends the clientGameLogic in StartDialog + clientGameLogic.setState(dialogs); + assertEquals(clientGameLogic.getState(), dialogs); - //sends the DialogsStateMachine in Lobby - dialogsStateMachine.gotoState(lobbyState); - assertTrue(dialogsStateMachine.getState() instanceof LobbyState); + //sends the DialogsState in Lobby + dialogs.setState(lobby); + assertEquals(dialogs.getState(), lobby); - //todo send all messages that dont indicate a change-state + //simulate all input that don't indicate a state-change + clientGameLogic.selectPiece(null); //TODO + clientGameLogic.selectCard(null); + clientGameLogic.selectTsk(color); + clientGameLogic.selectDice(); + clientGameLogic.selectName(name); + clientGameLogic.selectReady(true); + clientGameLogic.selectHost(name); + //clientGameLogic.selectLeave(); commented because it indicate a state-change to start-dialog + clientGameLogic.selectJoin(name); + clientGameLogic.selectAnimationEnd(); + //clientGameLogic.selectStart(); commented because it indicate a state-change to determineStartPlayer if host - assertTrue(clientAutomaton.getState() instanceof DialogsState); - assertTrue(dialogsStateMachine.getState() instanceof LobbyState); + //sends all messages, which don't indicate a statechange + clientGameLogic.received(activePlayer); + clientGameLogic.received(anyPiece); + clientGameLogic.received(briefing); + clientGameLogic.received(ceremonyMessage); + clientGameLogic.received(die); + clientGameLogic.received(diceAgain); + clientGameLogic.received(diceNow); + clientGameLogic.received(endOfTurn); + clientGameLogic.received(lobbyAccept); + clientGameLogic.received(lobbyDeny); + clientGameLogic.received(lobbyPlayerJoin); + clientGameLogic.received(lobbyPlayerLeave); + clientGameLogic.received(moveMessage); + clientGameLogic.received(noTurn); + clientGameLogic.received(interruptMessage); + clientGameLogic.received(playCardSwap); + clientGameLogic.received(playCardShield); + clientGameLogic.received(playCardTurbo); + clientGameLogic.received(possibleCard); + clientGameLogic.received(possiblePiece); + clientGameLogic.received(rankingResponse); + clientGameLogic.received(rankingRollAgain); + clientGameLogic.received(reconnectBriefing); + clientGameLogic.received(resumeGame); + //clientGameLogic.received(startGame); commented because it indicate a state-change to determineStartPlayer + clientGameLogic.received(startPieceMessage); + clientGameLogic.received(updateReady); + clientGameLogic.received(updateTSK); + clientGameLogic.received(waitPiece); + clientGameLogic.received(spectatorMessage); + clientGameLogic.received(selectPieceMessage); + + assertEquals(clientGameLogic.getState(), dialogs); + assertEquals(dialogs.getState(), lobby); } /** @@ -565,28 +726,24 @@ public void testStayInLobby() { @Test public void testLobbyToRollRankingDice() { //sends the clientStatemachine in Dialogs - clientAutomaton.gotoState(dialogsState); - assertTrue(clientAutomaton.getState() instanceof DialogsState); + clientGameLogic.setState(dialogs); + assertEquals(clientGameLogic.getState(), dialogs); //sends the clientStatemachine in Lobby - dialogsStateMachine.gotoState(lobbyState); - assertTrue(dialogsStateMachine.getState() instanceof LobbyState); + dialogs.setState(lobby); + assertEquals(dialogs.getState(), lobby); //sends the message to start the game - clientGameLogic.receive();//TODO message + clientGameLogic.received(startGame); //tests if the clientStateMachine is in the GameState - assertTrue(clientAutomaton.getState() instanceof GameState); + assertEquals(clientGameLogic.getState(), gameState); //tests if the clientStateMachine is in the DetermineStartPlayer - GameState gameState1 = (GameState) clientAutomaton.getState(); - GameStateMachine gameStateMachine1 = gameState1.getGameStateMachine(); - assertTrue(gameStateMachine1.getState() instanceof DetermineStartPlayerState); + assertEquals(gameState.getState(), determineStartPlayer); //tests if the clientStateMachine is in the RollRankingDice - DetermineStartPlayerState determineStartPlayerState1 = (DetermineStartPlayerState) gameStateMachine1.getState(); - DetermineStartPlayerStateMachine determineStartPlayerStateMachine1 = determineStartPlayerState1.getDetermineStartPlayerStateMachine(); - assertTrue(determineStartPlayerStateMachine1.getState() instanceof RollRankingDice); + assertEquals(determineStartPlayer.getState(), rollRankingDice); } /** @@ -594,7 +751,20 @@ public void testLobbyToRollRankingDice() { */ @Test public void testDetermineStartPlayerToWait() { - // Todo Implementation goes here + //sends the clientGameLogic into the gameState + clientGameLogic.setState(gameState); + assertEquals(clientGameLogic.getState(), gameState); + + //sends the gameState into the DetermineStartPlayer-state + gameState.setState(determineStartPlayer); + assertEquals(gameState.getState(), determineStartPlayer); + + //sends the message, that indicate a statechange to wait + clientGameLogic.received(noTurn); + + //tests if the client is in the Wait-State + assertEquals(clientGameLogic.getState(), gameState); + assertEquals(gameState.getState(), waiting); } /** @@ -602,36 +772,53 @@ public void testDetermineStartPlayerToWait() { */ @Test public void testWaitToAnimation() { - //sends the ClientAutomaton in GameState - clientAutomaton.gotoState(gameState); - assertTrue(clientAutomaton.getState() instanceof GameState); + //sends the ClientGameLogic in GameState + clientGameLogic.setState(gameState); + assertEquals(clientGameLogic.getState(), gameState); //sends the client in WaitState - gameStateMachine.gotoState(waitingState); - assertTrue(gameStateMachine.getState() instanceof WaitingState); + gameState.setState(waiting); + assertEquals(gameState.getState(), waiting); + + //sends the moveMessage + clientGameLogic.received(moveMessage); //tests if a piece is moved,that the client goes into Animation - clientGameLogic.receive(moveMessage); //Todo ??? richtige message - assertTrue(clientAutomaton.getState() instanceof GameState); - assertTrue(gameStateMachine.getState() instanceof AnimationState); + assertEquals(clientGameLogic.getState(), gameState); + assertEquals(gameState.getState(), animation); //sends the client in WaitState - gameStateMachine.gotoState(waitingState); - assertTrue(gameStateMachine.getState() instanceof WaitingState); + gameState.setState(waiting); + assertEquals(gameState.getState(), waiting); + + //sends the playTurboCard-message + clientGameLogic.received(playCardTurbo); //tests if a powerCard is played,that the client goes into Animation - clientGameLogic.receive(playCardTurbo); //Todo ??? richtige message - assertTrue(clientAutomaton.getState() instanceof GameState); - assertTrue(gameStateMachine.getState() instanceof AnimationState); + assertEquals(clientGameLogic.getState(), gameState); + assertEquals(gameState.getState(), animation); //sends the client in WaitState - gameStateMachine.gotoState(waitingState); - assertTrue(gameStateMachine.getState() instanceof WaitingState); + gameState.setState(waiting); + assertEquals(gameState.getState(), waiting); + + //sends the playTurboCard-message + clientGameLogic.received(die); //tests if a die is rolled,that the client goes into Animation - clientGameLogic.receive(dice); //Todo ??? richtige message - assertTrue(clientAutomaton.getState() instanceof GameState); - assertTrue(gameStateMachine.getState() instanceof AnimationState); + assertEquals(clientGameLogic.getState(), gameState); + assertEquals(gameState.getState(), animation); + + //sends the client in WaitState + gameState.setState(waiting); + assertEquals(gameState.getState(), waiting); + + //sends the activePlayer-message + clientGameLogic.received(activePlayer); + + //tests if a die is rolled,that the client goes into Animation + assertEquals(clientGameLogic.getState(), gameState); + assertEquals(gameState.getState(), animation); } /** @@ -640,29 +827,27 @@ public void testWaitToAnimation() { @Test public void testWaitToTurn() { //sends client in gameState - clientAutomaton.gotoState(gameState); - assertTrue(clientAutomaton.getState() instanceof GameState); + clientGameLogic.setState(gameState); + assertEquals(clientGameLogic.getState(), gameState); - //sends the gameStateMachine in the Waiting - gameStateMachine.gotoState(waitingState); - assertTrue(gameStateMachine.getState() instanceof WaitingState); + //sends the gameState in the Waiting + gameState.setState(waiting); + assertEquals(gameState.getState(), waiting); //the client receives the message ActivePlayer - clientGameLogic.receive(activePlayer); + clientGameLogic.received(activePlayer); //tests if the client is in GameState - assertTrue(clientAutomaton.getState() instanceof GameState); + assertEquals(clientGameLogic.getState(), gameState); //tests if Client is in Turn - assertTrue(gameStateMachine.getState() instanceof TurnState); + assertEquals(gameState.getState(), turnState); //tests if Client is in PowerCard - TurnStateMachine turnStateMachine1 = turnState.getTurnStateMachine(); - assertTrue(turnStateMachine1.getState() instanceof PowerCardState); + assertEquals(turnState.getState(), powerCard); //tests if Client is in ChoosePowerCard - PowerCardStateMachine powerCardStateMachine1 = powerCardState.getPowerCardStateMachine(); - assertTrue(powerCardStateMachine1.getState() instanceof ChoosePowerCardState); + assertEquals(powerCard.getState(), choosePowerCard); } /** @@ -670,15 +855,83 @@ public void testWaitToTurn() { */ @Test public void testWaitToGameEndState() { - // Implementation goes here + //sends client in gameState + clientGameLogic.setState(gameState); + assertEquals(clientGameLogic.getState(), gameState); + + //sends the gameState in the Waiting + gameState.setState(waiting); + assertEquals(gameState.getState(), waiting); + + //send the ceremony-Message + clientGameLogic.received(ceremonyMessage); + + //tests if the client is in the ceremony + assertEquals(clientGameLogic.getState(), ceremony); + assertEquals(ceremony.getState(), podium); } /** - * UC-ClientState-25: Test the transition from Turn substates to GameEndState. + * UC-ClientState-25: Test the transition from Turn sub-states to GameEndState. */ @Test public void testTurnSubStatesToGameEndState() { - // Implementation goes here + //sends the clientGameLogic in gameState + clientGameLogic.setState(gameState); + assertEquals(clientGameLogic.getState(), gameState); + + //sends the gameState in turnState + gameState.setState(turnState); + assertEquals(gameState.getState(), turnState); + + //sends the turnState in movePiece + turnState.setState(movePiece); + assertEquals(turnState.getState(), movePiece); + + //tests all messages, that don't indicate a state-change + clientGameLogic.received(activePlayer); + clientGameLogic.received(anyPiece); + clientGameLogic.received(briefing); + //clientGameLogic.received(ceremonyMessage); commented because it indicate a state-change to ceremony-state + clientGameLogic.received(die); + clientGameLogic.received(diceAgain); + //clientGameLogic.received(diceNow); commented because it indicate a state-change to rollDice-state + //clientGameLogic.received(endOfTurn); commented because it indicate a state-change to wait-state + clientGameLogic.received(lobbyAccept); + clientGameLogic.received(lobbyDeny); + clientGameLogic.received(lobbyPlayerJoin); + clientGameLogic.received(lobbyPlayerLeave); + clientGameLogic.received(moveMessage); + clientGameLogic.received(noTurn); + //clientGameLogic.received(interruptMessage); commented because it indicate a state-change to interrupt-state + clientGameLogic.received(playCardSwap); + clientGameLogic.received(playCardShield); + clientGameLogic.received(playCardTurbo); + clientGameLogic.received(possibleCard); + clientGameLogic.received(possiblePiece); + clientGameLogic.received(rankingResponse); + clientGameLogic.received(rankingRollAgain); + clientGameLogic.received(reconnectBriefing); + clientGameLogic.received(resumeGame); + clientGameLogic.received(startGame); + clientGameLogic.received(startPieceMessage); + clientGameLogic.received(updateReady); + clientGameLogic.received(updateTSK); + clientGameLogic.received(waitPiece); + //clientGameLogic.received(spectatorMessage); commented because it indicate a state-change to spectator-state + clientGameLogic.received(selectPieceMessage); + + //tests if the client is still in MovePiece + assertEquals(clientGameLogic.getState(), gameState); + assertEquals(gameState.getState(), turnState); + assertEquals(turnState.getState(), movePiece); + + //sends the spectator message + clientGameLogic.received(ceremonyMessage); + + //tests if the client is in spectator-state + assertEquals(clientGameLogic.getState(), ceremony); + assertEquals(ceremony.getState(), podium); } /** @@ -686,7 +939,189 @@ public void testTurnSubStatesToGameEndState() { */ @Test public void testTurnSubStatesToWait() { - // Implementation goes here + //sends the clientGameLogic in gameState + clientGameLogic.setState(gameState); + assertEquals(clientGameLogic.getState(), gameState); + + //sends the gameState in turnState + gameState.setState(turnState); + assertEquals(gameState.getState(), turnState); + + //sends the turnState in movePiece + turnState.setState(movePiece); + assertEquals(turnState.getState(), movePiece); + + //tests all messages, that don't indicate a state-change + clientGameLogic.received(activePlayer); + clientGameLogic.received(anyPiece); + clientGameLogic.received(briefing); + //clientGameLogic.received(ceremonyMessage); commented because it indicate a state-change to ceremony-state + clientGameLogic.received(die); + clientGameLogic.received(diceAgain); + //clientGameLogic.received(diceNow); commented because it indicate a state-change to rollDice-state + //clientGameLogic.received(endOfTurn); commented because it indicate a state-change to wait-state + clientGameLogic.received(lobbyAccept); + clientGameLogic.received(lobbyDeny); + clientGameLogic.received(lobbyPlayerJoin); + clientGameLogic.received(lobbyPlayerLeave); + clientGameLogic.received(moveMessage); + clientGameLogic.received(noTurn); + //clientGameLogic.received(interruptMessage); commented because it indicate a state-change to interrupt-state + clientGameLogic.received(playCardSwap); + clientGameLogic.received(playCardShield); + clientGameLogic.received(playCardTurbo); + clientGameLogic.received(possibleCard); + clientGameLogic.received(possiblePiece); + clientGameLogic.received(rankingResponse); + clientGameLogic.received(rankingRollAgain); + clientGameLogic.received(reconnectBriefing); + clientGameLogic.received(resumeGame); + clientGameLogic.received(startGame); + clientGameLogic.received(startPieceMessage); + clientGameLogic.received(updateReady); + clientGameLogic.received(updateTSK); + clientGameLogic.received(waitPiece); + //clientGameLogic.received(spectatorMessage); commented because it indicate a state-change to spectator-state + clientGameLogic.received(selectPieceMessage); + + //tests if the client is still in MovePiece + assertEquals(clientGameLogic.getState(), gameState); + assertEquals(gameState.getState(), turnState); + assertEquals(turnState.getState(), movePiece); + + //sends the endOfTurn message + clientGameLogic.received(endOfTurn); + + //tests if the client is in waiting-state + assertEquals(clientGameLogic.getState(), gameState); + assertEquals(gameState.getState(), waiting); + + /* + * tests thr transition from choosePiece to Wait + */ + + //sends the clientGameLogic in gameState + clientGameLogic.setState(gameState); + assertEquals(clientGameLogic.getState(), gameState); + + //sends the gameState in turnState + gameState.setState(turnState); + assertEquals(gameState.getState(), turnState); + + //sends the turnState in choosePiece + turnState.setState(movePiece); + assertEquals(turnState.getState(), choosePiece); + + //sends the choosePiece in NoPiece + choosePiece.setState(noPiece); + assertEquals(choosePiece.getState(), noPiece); + + //tests all messages, that don't indicate a state-change + clientGameLogic.received(activePlayer); + clientGameLogic.received(anyPiece); + clientGameLogic.received(briefing); + clientGameLogic.received(ceremonyMessage); + clientGameLogic.received(die); + clientGameLogic.received(diceAgain); + clientGameLogic.received(diceNow); + //clientGameLogic.received(endOfTurn); commented because it indicate a state-change to wait-state + clientGameLogic.received(lobbyAccept); + clientGameLogic.received(lobbyDeny); + clientGameLogic.received(lobbyPlayerJoin); + clientGameLogic.received(lobbyPlayerLeave); + clientGameLogic.received(moveMessage); + clientGameLogic.received(noTurn); + //clientGameLogic.received(interruptMessage); commented because it indicate a state-change to interrupt-state + clientGameLogic.received(playCardSwap); + clientGameLogic.received(playCardShield); + clientGameLogic.received(playCardTurbo); + clientGameLogic.received(possibleCard); + clientGameLogic.received(possiblePiece); + clientGameLogic.received(rankingResponse); + clientGameLogic.received(rankingRollAgain); + clientGameLogic.received(reconnectBriefing); + clientGameLogic.received(resumeGame); + clientGameLogic.received(startGame); + //clientGameLogic.received(startPieceMessage); + clientGameLogic.received(updateReady); + clientGameLogic.received(updateTSK); + //clientGameLogic.received(waitPiece); + clientGameLogic.received(spectatorMessage); + //clientGameLogic.received(selectPieceMessage); + + //tests if the client is still in MovePiece + assertEquals(clientGameLogic.getState(), gameState); + assertEquals(gameState.getState(), turnState); + assertEquals(turnState.getState(), choosePiece); + assertEquals(choosePiece.getState(), noPiece); + + //sends the endOfTurn message + clientGameLogic.received(endOfTurn); + + //tests if the client is in waiting-state + assertEquals(clientGameLogic.getState(), gameState); + assertEquals(gameState.getState(), waiting); + + /* + * tests the transition from RollDice to Wait + */ + + //sends the clientGameLogic in gameState + clientGameLogic.setState(gameState); + assertEquals(clientGameLogic.getState(), gameState); + + //sends the gameState in turnState + gameState.setState(turnState); + assertEquals(gameState.getState(), turnState); + + //sends the turnState in movePiece + turnState.setState(movePiece); + assertEquals(turnState.getState(), rollDice); + + //tests all messages, that don't indicate a state-change + clientGameLogic.received(activePlayer); + clientGameLogic.received(anyPiece); + clientGameLogic.received(briefing); + clientGameLogic.received(ceremonyMessage); + //clientGameLogic.received(die); + clientGameLogic.received(diceAgain); + clientGameLogic.received(diceNow); + //clientGameLogic.received(endOfTurn); commented because it indicate a state-change to wait-state + clientGameLogic.received(lobbyAccept); + clientGameLogic.received(lobbyDeny); + clientGameLogic.received(lobbyPlayerJoin); + clientGameLogic.received(lobbyPlayerLeave); + clientGameLogic.received(moveMessage); + clientGameLogic.received(noTurn); + //clientGameLogic.received(interruptMessage); commented because it indicate a state-change to interrupt-state + clientGameLogic.received(playCardSwap); + clientGameLogic.received(playCardShield); + clientGameLogic.received(playCardTurbo); + clientGameLogic.received(possibleCard); + clientGameLogic.received(possiblePiece); + clientGameLogic.received(rankingResponse); + clientGameLogic.received(rankingRollAgain); + clientGameLogic.received(reconnectBriefing); + clientGameLogic.received(resumeGame); + clientGameLogic.received(startGame); + clientGameLogic.received(startPieceMessage); + clientGameLogic.received(updateReady); + clientGameLogic.received(updateTSK); + clientGameLogic.received(waitPiece); + clientGameLogic.received(spectatorMessage); + clientGameLogic.received(selectPieceMessage); + + //tests if the client is still in MovePiece + assertEquals(clientGameLogic.getState(), gameState); + assertEquals(gameState.getState(), turnState); + assertEquals(turnState.getState(), rollDice); + + //sends the endOfTurn message + clientGameLogic.received(endOfTurn); + + //tests if the client is in waiting-state + assertEquals(clientGameLogic.getState(), gameState); + assertEquals(gameState.getState(), waiting); } /** @@ -694,7 +1129,62 @@ public void testTurnSubStatesToWait() { */ @Test public void testTurnSubStatesToSpectator() { - // Implementation goes here + //sends the clientGameLogic in gameState + clientGameLogic.setState(gameState); + assertEquals(clientGameLogic.getState(), gameState); + + //sends the gameState in turnState + gameState.setState(turnState); + assertEquals(gameState.getState(), turnState); + + //sends the turnState in movePiece + turnState.setState(movePiece); + assertEquals(turnState.getState(), movePiece); + + //tests all messages, that don't indicate a state-change + clientGameLogic.received(activePlayer); + clientGameLogic.received(anyPiece); + clientGameLogic.received(briefing); + //clientGameLogic.received(ceremonyMessage); commented because it indicate a state-change to ceremony-state + clientGameLogic.received(die); + clientGameLogic.received(diceAgain); + //clientGameLogic.received(diceNow); commented because it indicate a state-change to rollDice-state + //clientGameLogic.received(endOfTurn); commented because it indicate a state-change to wait-state + clientGameLogic.received(lobbyAccept); + clientGameLogic.received(lobbyDeny); + clientGameLogic.received(lobbyPlayerJoin); + clientGameLogic.received(lobbyPlayerLeave); + clientGameLogic.received(moveMessage); + clientGameLogic.received(noTurn); + //clientGameLogic.received(interruptMessage); commented because it indicate a state-change to interrupt-state + clientGameLogic.received(playCardSwap); + clientGameLogic.received(playCardShield); + clientGameLogic.received(playCardTurbo); + clientGameLogic.received(possibleCard); + clientGameLogic.received(possiblePiece); + clientGameLogic.received(rankingResponse); + clientGameLogic.received(rankingRollAgain); + clientGameLogic.received(reconnectBriefing); + clientGameLogic.received(resumeGame); + clientGameLogic.received(startGame); + clientGameLogic.received(startPieceMessage); + clientGameLogic.received(updateReady); + clientGameLogic.received(updateTSK); + clientGameLogic.received(waitPiece); + //clientGameLogic.received(spectatorMessage); commented because it indicate a state-change to spectator-state + clientGameLogic.received(selectPieceMessage); + + //tests if the client is still in MovePiece + assertEquals(clientGameLogic.getState(), gameState); + assertEquals(gameState.getState(), turnState); + assertEquals(turnState.getState(), movePiece); + + //sends the spectator message + clientGameLogic.received(spectatorMessage); + + //tests if the client is in spectator-state + assertEquals(clientGameLogic.getState(), gameState); + assertEquals(gameState.getState(), spectator); } /** @@ -702,7 +1192,57 @@ public void testTurnSubStatesToSpectator() { */ @Test public void testSpectatorToGameEndState() { - // Implementation goes here + //sends the client in the gameState + clientGameLogic.setState(gameState); + assertEquals(clientGameLogic.getState(), gameState); + + //sends the client in the spectator-state + gameState.setState(spectator); + assertEquals(gameState.getState(), spectator); + + //sends all messages that indicate no state-change + clientGameLogic.received(activePlayer); + clientGameLogic.received(anyPiece); + clientGameLogic.received(briefing); + //clientGameLogic.received(ceremonyMessage); commented out, because it indicates a statechange to podium-state + clientGameLogic.received(die); + clientGameLogic.received(diceAgain); + clientGameLogic.received(diceNow); + clientGameLogic.received(endOfTurn); + clientGameLogic.received(lobbyAccept); + clientGameLogic.received(lobbyDeny); + clientGameLogic.received(lobbyPlayerJoin); + clientGameLogic.received(lobbyPlayerLeave); + clientGameLogic.received(moveMessage); + clientGameLogic.received(noTurn); + //clientGameLogic.received(interruptMessage); commented out, because message indicates statechange to interrupt + clientGameLogic.received(playCardSwap); + clientGameLogic.received(playCardShield); + clientGameLogic.received(playCardTurbo); + clientGameLogic.received(possibleCard); + clientGameLogic.received(possiblePiece); + clientGameLogic.received(rankingResponse); + clientGameLogic.received(rankingRollAgain); + clientGameLogic.received(reconnectBriefing); + clientGameLogic.received(resumeGame); + clientGameLogic.received(startGame); + clientGameLogic.received(startPieceMessage); + clientGameLogic.received(updateReady); + clientGameLogic.received(updateTSK); + clientGameLogic.received(waitPiece); + clientGameLogic.received(spectatorMessage); + clientGameLogic.received(selectPieceMessage); + + //tests if the client is still in spectator + assertEquals(clientGameLogic.getState(), gameState); + assertEquals(gameState.getState(), spectator); + + //sends the gameEnd-Message + clientGameLogic.received(ceremonyMessage); + + //tests if the client is in the podium-state + assertEquals(clientGameLogic.getState(), ceremony); + assertEquals(ceremony.getState(), podium); } /** @@ -710,15 +1250,91 @@ public void testSpectatorToGameEndState() { */ @Test public void testPowerCardSubStatesToPlayPowerCard() { - // Implementation goes here + /* + * sends the client in the swap-state + */ + //sends the ClientGameLogic in GameState + clientGameLogic.setState(gameState); + assertEquals(clientGameLogic.getState(), gameState); + + //sends the gameState in the Turn + gameState.setState(turnState); + assertEquals(gameState.getState(), turnState); + + //sends the turnState in PlayPowerCard + turnState.setState(powerCard); + assertEquals(turnState.getState(), powerCard); + + //sends the client in the ChoosePowerCard + powerCard.setState(choosePowerCard); + assertEquals(powerCard.getState(), swap); + + //sends the playCardMessage + clientGameLogic.received(playCardShield); + + //tests if the client is in playPowerCard + assertEquals(clientGameLogic.getState(), gameState); + assertEquals(gameState.getState(), turnState); + assertEquals(turnState.getState(), playPowerCard); + + /* + * send the client in the shield-state + */ + //sends the ClientGameLogic in GameState + clientGameLogic.setState(gameState); + assertEquals(clientGameLogic.getState(), gameState); + + //sends the gameState in the Turn + gameState.setState(turnState); + assertEquals(gameState.getState(), turnState); + + //sends the turnState in PlayPowerCard + turnState.setState(powerCard); + assertEquals(turnState.getState(), powerCard); + + //sends the client in the ChoosePowerCard + powerCard.setState(choosePowerCard); + assertEquals(powerCard.getState(), shield); + + //sends the playCardMessage + clientGameLogic.received(playCardShield); + + //tests if the client is in playPowerCard + assertEquals(clientGameLogic.getState(), gameState); + assertEquals(gameState.getState(), turnState); + assertEquals(turnState.getState(), playPowerCard); } /** * UC-ClientState-30: Test the transition from PowerCard sub-states to RollDice. + *
+ * tests the transition from ChoosePowerCard from PowerCard to RollDice */ @Test public void testPowerCardSubStatesToRollDice() { - // Implementation goes here + //sends the ClientGameLogic in GameState + clientGameLogic.setState(gameState); + assertEquals(clientGameLogic.getState(), gameState); + + //sends the gameState in the Turn + gameState.setState(turnState); + assertEquals(gameState.getState(), turnState); + + //sends the turnState in PlayPowerCard + turnState.setState(powerCard); + assertEquals(turnState.getState(), powerCard); + + //sends the client in the ChoosePowerCard + powerCard.setState(choosePowerCard); + assertEquals(powerCard.getState(), choosePowerCard); + + //sends RollDiceMessage + clientGameLogic.received(diceNow); + + //tests if the client is in rollDice + assertEquals(clientGameLogic.getState(), gameState); + assertEquals(gameState.getState(), turnState); + assertEquals(turnState.getState(), rollDice); } /** @@ -726,24 +1342,55 @@ public void testPowerCardSubStatesToRollDice() { */ @Test public void testStayInPlayPowerCard() { - //sends the ClientAutomaton in GameState - clientAutomaton.gotoState(gameState); - assertTrue(clientAutomaton.getState() instanceof GameState); + //sends the ClientGameLogic in GameState + clientGameLogic.setState(gameState); + assertEquals(clientGameLogic.getState(), gameState); - //sends the gameStateMachine in the Turn - gameStateMachine.gotoState(turnState); - assertTrue(gameStateMachine.getState() instanceof TurnState); + //sends the gameState in the Turn + gameState.setState(turnState); + assertEquals(gameState.getState(), turnState); - //sends the turnStatemachine in PlayPowerCard - turnStateMachine.gotoState(playPowerCardState); - assertTrue(turnStateMachine.getState() instanceof PlayPowerCardState); + //sends the turnState in PlayPowerCard + turnState.setState(playPowerCard); + assertEquals(turnState.getState(), playPowerCard); - //Todo send messages to test to stay in playPowerCard + //sends all messages that don't indicate a state-change + clientGameLogic.received(activePlayer); + clientGameLogic.received(anyPiece); + clientGameLogic.received(briefing); + clientGameLogic.received(ceremonyMessage); + clientGameLogic.received(die); + clientGameLogic.received(diceAgain); + //clientGameLogic.received(diceNow); + clientGameLogic.received(endOfTurn); + clientGameLogic.received(lobbyAccept); + clientGameLogic.received(lobbyDeny); + clientGameLogic.received(lobbyPlayerJoin); + clientGameLogic.received(lobbyPlayerLeave); + clientGameLogic.received(moveMessage); + clientGameLogic.received(noTurn); + //clientGameLogic.received(interruptMessage); + clientGameLogic.received(playCardSwap); + clientGameLogic.received(playCardShield); + clientGameLogic.received(playCardTurbo); + clientGameLogic.received(possibleCard); + clientGameLogic.received(possiblePiece); + clientGameLogic.received(rankingResponse); + clientGameLogic.received(rankingRollAgain); + clientGameLogic.received(reconnectBriefing); + clientGameLogic.received(resumeGame); + clientGameLogic.received(startGame); + clientGameLogic.received(startPieceMessage); + clientGameLogic.received(updateReady); + clientGameLogic.received(updateTSK); + clientGameLogic.received(waitPiece); + clientGameLogic.received(spectatorMessage); + clientGameLogic.received(selectPieceMessage); //tests if the client is in PlayPowerCard - assertTrue(clientAutomaton.getState() instanceof GameState); - assertTrue(gameStateMachine.getState() instanceof TurnState); - assertTrue(turnStateMachine.getState() instanceof PlayPowerCardState); + assertEquals(clientGameLogic.getState(), gameState); + assertEquals(gameState.getState(), turnState); + assertEquals(turnState.getState(), playPowerCard); } /** @@ -751,25 +1398,63 @@ public void testStayInPlayPowerCard() { */ @Test public void testPlayPowerCardToRollDice() { - //sends the ClientAutomaton in GameState - clientAutomaton.gotoState(gameState); - assertTrue(clientAutomaton.getState() instanceof GameState); + //sends the ClientGameLogic in GameState + clientGameLogic.setState(gameState); + assertEquals(clientGameLogic.getState(), gameState); - //sends the gameStateMachine in the Turn - gameStateMachine.gotoState(turnState); - assertTrue(gameStateMachine.getState() instanceof TurnState); + //sends the gameState in the Turn + gameState.setState(turnState); + assertEquals(gameState.getState(), turnState); - //sends the turnStatemachine in PlayPowerCard - turnStateMachine.gotoState(playPowerCardState); - assertTrue(turnStateMachine.getState() instanceof PlayPowerCardState); + //sends the turnState in PlayPowerCard + turnState.setState(playPowerCard); + assertEquals(turnState.getState(), playPowerCard); - //Todo send messages to test the transition in rollDice - //Todo test other messages, that there is no state change + //sends all messages that don't indicate a state-change + clientGameLogic.received(activePlayer); + clientGameLogic.received(anyPiece); + clientGameLogic.received(briefing); + clientGameLogic.received(ceremonyMessage); + clientGameLogic.received(die); + clientGameLogic.received(diceAgain); + //clientGameLogic.received(diceNow); + clientGameLogic.received(endOfTurn); + clientGameLogic.received(lobbyAccept); + clientGameLogic.received(lobbyDeny); + clientGameLogic.received(lobbyPlayerJoin); + clientGameLogic.received(lobbyPlayerLeave); + clientGameLogic.received(moveMessage); + clientGameLogic.received(noTurn); + //clientGameLogic.received(interruptMessage); + clientGameLogic.received(playCardSwap); + clientGameLogic.received(playCardShield); + clientGameLogic.received(playCardTurbo); + clientGameLogic.received(possibleCard); + clientGameLogic.received(possiblePiece); + clientGameLogic.received(rankingResponse); + clientGameLogic.received(rankingRollAgain); + clientGameLogic.received(reconnectBriefing); + clientGameLogic.received(resumeGame); + clientGameLogic.received(startGame); + clientGameLogic.received(startPieceMessage); + clientGameLogic.received(updateReady); + clientGameLogic.received(updateTSK); + clientGameLogic.received(waitPiece); + clientGameLogic.received(spectatorMessage); + clientGameLogic.received(selectPieceMessage); //tests if the client is in RollDice - assertTrue(clientAutomaton.getState() instanceof GameState); - assertTrue(gameStateMachine.getState() instanceof TurnState); - assertTrue(turnStateMachine.getState() instanceof RollDiceState); + assertEquals(clientGameLogic.getState(), gameState); + assertEquals(gameState.getState(), turnState); + assertEquals(turnState.getState(), playPowerCard); + + //sends the die-message + clientGameLogic.received(diceNow); + + //tests if the client is in RollDice + assertEquals(clientGameLogic.getState(), gameState); + assertEquals(gameState.getState(), turnState); + assertEquals(turnState.getState(), rollDice); } /** @@ -777,7 +1462,55 @@ public void testPlayPowerCardToRollDice() { */ @Test public void testStayInRollDice() { - // Implementation goes here + //sends the ClientGameLogic in GameState + clientGameLogic.setState(gameState); + assertEquals(clientGameLogic.getState(), gameState); + + //sends the gameState in the Turn + gameState.setState(turnState); + assertEquals(gameState.getState(), turnState); + + //sends the turn-state into the rollDice-state + turnState.setState(rollDice); + assertEquals(turnState.getState(), rollDice); + + //sends all messages, that don't indicate a state-change + clientGameLogic.received(activePlayer); + clientGameLogic.received(anyPiece); + clientGameLogic.received(briefing); + clientGameLogic.received(ceremonyMessage); + //clientGameLogic.received(die); + clientGameLogic.received(diceAgain); + clientGameLogic.received(diceNow); + clientGameLogic.received(endOfTurn); + clientGameLogic.received(lobbyAccept); + clientGameLogic.received(lobbyDeny); + clientGameLogic.received(lobbyPlayerJoin); + clientGameLogic.received(lobbyPlayerLeave); + clientGameLogic.received(moveMessage); + //clientGameLogic.received(noTurn); + //clientGameLogic.received(interruptMessage); + clientGameLogic.received(playCardSwap); + clientGameLogic.received(playCardShield); + clientGameLogic.received(playCardTurbo); + clientGameLogic.received(possibleCard); + clientGameLogic.received(possiblePiece); + clientGameLogic.received(rankingResponse); + clientGameLogic.received(rankingRollAgain); + clientGameLogic.received(reconnectBriefing); + clientGameLogic.received(resumeGame); + clientGameLogic.received(startGame); + clientGameLogic.received(startPieceMessage); + clientGameLogic.received(updateReady); + clientGameLogic.received(updateTSK); + clientGameLogic.received(waitPiece); + clientGameLogic.received(spectatorMessage); + clientGameLogic.received(selectPieceMessage); + + //tests if the client is in RollDice + assertEquals(clientGameLogic.getState(), gameState); + assertEquals(gameState.getState(), turnState); + assertEquals(turnState.getState(), rollDice); } /** @@ -785,7 +1518,25 @@ public void testStayInRollDice() { */ @Test public void testRollDiceToChoosePiece() { - // Implementation goes here + //sends the ClientGameLogic in GameState + clientGameLogic.setState(gameState); + assertEquals(clientGameLogic.getState(), gameState); + + //sends the gameState in the Turn + gameState.setState(turnState); + assertEquals(gameState.getState(), turnState); + + //sends the turn-state into the rollDice-state + turnState.setState(rollDice); + assertEquals(turnState.getState(), rollDice); + + //sends the die-message + clientGameLogic.received(die); + + //tests if the client is in ChoosePiece-state + assertEquals(clientGameLogic.getState(), gameState); + assertEquals(gameState.getState(), choosePiece); + assertEquals(choosePiece.getState(), noPiece); } /** @@ -793,23 +1544,144 @@ public void testRollDiceToChoosePiece() { */ @Test public void testRollDiceToWait() { - // Implementation goes here + //sends the ClientGameLogic in GameState + clientGameLogic.setState(gameState); + assertEquals(clientGameLogic.getState(), gameState); + + //sends the gameState in the Turn + gameState.setState(turnState); + assertEquals(gameState.getState(), turnState); + + //sends the turn-state into the rollDice-state + turnState.setState(rollDice); + assertEquals(turnState.getState(), rollDice); + + //sends the noTurn-message + clientGameLogic.received(noTurn); + + //tests if the client is in wait + assertEquals(clientGameLogic.getState(), gameState); + assertEquals(gameState.getState(), waiting); } /** * UC-ClientState-36: Test the transition from ChoosePiece to Wait. + *
+ * this method tests the transition from noPiece to Wait */ @Test public void testChoosePieceToWait() { - // Implementation goes here + //sends the client into noPiece + clientGameLogic.setState(gameState); + assertEquals(clientGameLogic.getState(), gameState); + + //sends the gameState into Turn + gameState.setState(turnState); + assertEquals(gameState.getState(), turnState); + + //sends the turnState into choosePiece + turnState.setState(choosePiece); + assertEquals(turnState.getState(), choosePiece); + + //sends the choosePiece into noTurn + choosePiece.setState(noPiece); + assertEquals(choosePiece.getState(), noPiece); + + //send the noTurnMessage + clientGameLogic.received(noTurn); + + //tests if the client is in the wait-state + assertEquals(clientGameLogic.getState(), gameState); + assertEquals(gameState.getState(), waiting); } /** * UC-ClientState-37: Test the transition from ChoosePiece to MovePiece. + *
+ * this method tests the transition from noPiece to Wait */ @Test public void testChoosePieceToMovePiece() { - // Implementation goes here + /* + * tests the transition from waitingPiece to MovePiece + */ + //sends the client into noPiece + clientGameLogic.setState(gameState); + assertEquals(clientGameLogic.getState(), gameState); + + //sends the gameState into Turn + gameState.setState(turnState); + assertEquals(gameState.getState(), turnState); + + //sends the turnState into choosePiece + turnState.setState(choosePiece); + assertEquals(turnState.getState(), choosePiece); + + //sends the choosePiece into waitingPiece + choosePiece.setState(waitingPiece); + assertEquals(choosePiece.getState(), waitingPiece); + + //sends the movePieceMessage + clientGameLogic.received(moveMessage); + + //tests if the client is in the movePiece-state + assertEquals(clientGameLogic.getState(), gameState); + assertEquals(gameState.getState(), turnState); + assertEquals(turnState.getState(), movePiece); + + /* + * tests the transition from startPiece to MovePiece + */ + //sends the client into noPiece + clientGameLogic.setState(gameState); + assertEquals(clientGameLogic.getState(), gameState); + + //sends the gameState into Turn + gameState.setState(turnState); + assertEquals(gameState.getState(), turnState); + + //sends the turnState into choosePiece + turnState.setState(choosePiece); + assertEquals(turnState.getState(), choosePiece); + + //sends the choosePiece into startPiece + choosePiece.setState(startPiece); + assertEquals(choosePiece.getState(), startPiece); + + //sends the movePieceMessage + clientGameLogic.received(moveMessage); + + //tests if the client is in the movePiece-state + assertEquals(clientGameLogic.getState(), gameState); + assertEquals(gameState.getState(), turnState); + assertEquals(turnState.getState(), movePiece); + + /* + * tests the transition from selectPiece to MovePiece + */ + //sends the client into noPiece + clientGameLogic.setState(gameState); + assertEquals(clientGameLogic.getState(), gameState); + + //sends the gameState into Turn + gameState.setState(turnState); + assertEquals(gameState.getState(), turnState); + + //sends the turnState into choosePiece + turnState.setState(choosePiece); + assertEquals(turnState.getState(), choosePiece); + + //sends the choosePiece into selectPiece + choosePiece.setState(selectPiece); + assertEquals(choosePiece.getState(), selectPiece); + + //sends the movePieceMessage + clientGameLogic.received(moveMessage); + + //tests if the client is in the movePiece-state + assertEquals(clientGameLogic.getState(), gameState); + assertEquals(gameState.getState(), turnState); + assertEquals(turnState.getState(), movePiece); } /** @@ -817,7 +1689,25 @@ public void testChoosePieceToMovePiece() { */ @Test public void testMovePieceToWait() { - // Implementation goes here + //sends the client into noPiece + clientGameLogic.setState(gameState); + assertEquals(clientGameLogic.getState(), gameState); + + //sends the gameState into Turn + gameState.setState(turnState); + assertEquals(gameState.getState(), turnState); + + //sends the turnState into movePiece + turnState.setState(choosePiece); + assertEquals(turnState.getState(), movePiece); + + //sends the endOfTurnMessage + clientGameLogic.received(endOfTurn); + + //tests if the client is in the movePiece-state + assertEquals(clientGameLogic.getState(), gameState); + assertEquals(gameState.getState(), turnState); + assertEquals(turnState.getState(), movePiece); } /** @@ -825,7 +1715,24 @@ public void testMovePieceToWait() { */ @Test public void testMovePieceToSpectator() { - // Implementation goes here + //sends the client into noPiece + clientGameLogic.setState(gameState); + assertEquals(clientGameLogic.getState(), gameState); + + //sends the gameState into Turn + gameState.setState(turnState); + assertEquals(gameState.getState(), turnState); + + //sends the turnState into movePiece + turnState.setState(choosePiece); + assertEquals(turnState.getState(), movePiece); + + //sends the spectator-message + clientGameLogic.received(spectatorMessage); + + //tests if the client is in Spectator + assertEquals(clientGameLogic.getState(), gameState); + assertEquals(gameState.getState(), spectator); } /** @@ -833,7 +1740,24 @@ public void testMovePieceToSpectator() { */ @Test public void testMovePieceToCeremony() { - // Implementation goes here + //sends the client into noPiece + clientGameLogic.setState(gameState); + assertEquals(clientGameLogic.getState(), gameState); + + //sends the gameState into Turn + gameState.setState(turnState); + assertEquals(gameState.getState(), turnState); + + //sends the turnState into movePiece + turnState.setState(choosePiece); + assertEquals(turnState.getState(), movePiece); + + //sends the spectator-message + clientGameLogic.received(ceremonyMessage); + + //tests if the client is in Spectator + assertEquals(clientGameLogic.getState(), gameState); + assertEquals(gameState.getState(), spectator); } /** @@ -841,7 +1765,55 @@ public void testMovePieceToCeremony() { */ @Test public void testStayInChoosePowerCard() { - // Implementation goes here + //sends the client into noPiece + clientGameLogic.setState(gameState); + assertEquals(clientGameLogic.getState(), gameState); + + //sends the gameState into Turn + gameState.setState(turnState); + assertEquals(gameState.getState(), turnState); + + //sends the turnState into choosePowerCardPiece + turnState.setState(choosePiece); + assertEquals(turnState.getState(), choosePowerCard); + + //send all messages, that don't indicate a state-change + clientGameLogic.received(activePlayer); + clientGameLogic.received(anyPiece); + clientGameLogic.received(briefing); + clientGameLogic.received(ceremonyMessage); + clientGameLogic.received(die); + clientGameLogic.received(diceAgain); + //clientGameLogic.received(diceNow); + clientGameLogic.received(endOfTurn); + clientGameLogic.received(lobbyAccept); + clientGameLogic.received(lobbyDeny); + clientGameLogic.received(lobbyPlayerJoin); + clientGameLogic.received(lobbyPlayerLeave); + clientGameLogic.received(moveMessage); + clientGameLogic.received(noTurn); + //clientGameLogic.received(interruptMessage); + clientGameLogic.received(playCardSwap); + clientGameLogic.received(playCardShield); + clientGameLogic.received(playCardTurbo); + clientGameLogic.received(possibleCard); + clientGameLogic.received(possiblePiece); + clientGameLogic.received(rankingResponse); + clientGameLogic.received(rankingRollAgain); + clientGameLogic.received(reconnectBriefing); + clientGameLogic.received(resumeGame); + clientGameLogic.received(startGame); + clientGameLogic.received(startPieceMessage); + clientGameLogic.received(updateReady); + clientGameLogic.received(updateTSK); + clientGameLogic.received(waitPiece); + clientGameLogic.received(spectatorMessage); + clientGameLogic.received(selectPieceMessage); + + //tests if the client is still in the choosePowerCard-State + assertEquals(clientGameLogic.getState(), gameState); + assertEquals(gameState.getState(), turnState); + assertEquals(turnState.getState(), choosePowerCard); } /** @@ -849,30 +1821,29 @@ public void testStayInChoosePowerCard() { */ @Test public void testChoosePowerCardToRollDice() { + //sends the ClientGameLogic in GameState + clientGameLogic.setState(gameState); + assertEquals(clientGameLogic.getState(), gameState); - //TODO - //sends the ClientAutomaton in GameState - clientAutomaton.gotoState(gameState); - assertTrue(clientAutomaton.getState() instanceof GameState); + //sends the gameState in the Turn + gameState.setState(turnState); + assertEquals(gameState.getState(), turnState); - //sends the gameStateMachine in the Turn - gameStateMachine.gotoState(turnState); - assertTrue(gameStateMachine.getState() instanceof TurnState); + //sends the turnState in PowerCard + turnState.setState(powerCard); + assertEquals(turnState.getState(), powerCard); - //sends the turnStatemachine in PowerCard - turnStateMachine.gotoState(powerCardState); - assertTrue(turnStateMachine.getState() instanceof PowerCardState); + //sends the turnState in ChoosePiece + powerCard.setState(choosePowerCard); + assertEquals(powerCard.getState(), choosePowerCard); - //sends the turnStatemachine in ChoosePiece - powerCardStateMachine.gotoState(choosePowerCardState); - assertTrue(powerCardStateMachine.getState() instanceof ChoosePowerCardState); + //sends the rollDice-Message + clientGameLogic.received(diceNow); - //todo send the messages, to force a state change to rollDice - - //tests if the turnStateMachine is in RollDice - assertTrue(clientAutomaton.getState() instanceof GameState); - assertTrue(gameStateMachine.getState() instanceof TurnState); - assertTrue(turnStateMachine.getState() instanceof RollDiceState); + //tests if the turnState is in RollDice + assertEquals(clientGameLogic.getState(), gameState); + assertEquals(gameState.getState(), turnState); + assertEquals(turnState.getState(), rollDice); } /** @@ -880,29 +1851,30 @@ public void testChoosePowerCardToRollDice() { */ @Test public void testChoosePowerCardToSwap() { - //sends the ClientAutomaton in GameState - clientAutomaton.gotoState(gameState); - assertTrue(clientAutomaton.getState() instanceof GameState); + //sends the ClientGameLogic in GameState + clientGameLogic.setState(gameState); + assertEquals(clientGameLogic.getState(), gameState); - //sends the gameStateMachine in the Turn - gameStateMachine.gotoState(turnState); - assertTrue(gameStateMachine.getState() instanceof TurnState); + //sends the gameState in the Turn + gameState.setState(turnState); + assertEquals(gameState.getState(), turnState); - //sends the turnStatemachine in PowerCard - turnStateMachine.gotoState(powerCardState); - assertTrue(turnStateMachine.getState() instanceof PowerCardState); + //sends the turnState in PowerCard + turnState.setState(powerCard); + assertEquals(turnState.getState(), powerCard); - //sends the turnStatemachine in ChoosePiece - powerCardStateMachine.gotoState(choosePowerCardState); - assertTrue(powerCardStateMachine.getState() instanceof ChoosePowerCardState); + //sends the turnState in ChoosePiece + powerCard.setState(choosePowerCard); + assertEquals(powerCard.getState(), choosePowerCard); - //todo send the messages, to force a state change to swap + //sends the possiblePieces-Message + clientGameLogic.received(possiblePieceSwap); //tests if the client is in Swap - assertTrue(clientAutomaton.getState() instanceof GameState); - assertTrue(gameStateMachine.getState() instanceof TurnState); - assertTrue(turnStateMachine.getState() instanceof PowerCardState); - assertTrue(powerCardStateMachine.getState() instanceof SwapState); + assertEquals(clientGameLogic.getState(), gameState); + assertEquals(gameState.getState(), turnState); + assertEquals(turnState.getState(), powerCard); + assertEquals(powerCard.getState(), swap); } /** @@ -910,29 +1882,30 @@ public void testChoosePowerCardToSwap() { */ @Test public void testChoosePowerCardToShield() { - //sends the ClientAutomaton in GameState - clientAutomaton.gotoState(gameState); - assertTrue(clientAutomaton.getState() instanceof GameState); + //sends the ClientGameLogic in GameState + clientGameLogic.setState(gameState); + assertEquals(clientGameLogic.getState(), gameState); - //sends the gameStateMachine in the Turn - gameStateMachine.gotoState(turnState); - assertTrue(gameStateMachine.getState() instanceof TurnState); + //sends the gameState in the Turn + gameState.setState(turnState); + assertEquals(gameState.getState(), turnState); - //sends the turnStatemachine in PowerCard - turnStateMachine.gotoState(powerCardState); - assertTrue(turnStateMachine.getState() instanceof PowerCardState); + //sends the turnState in PowerCard + turnState.setState(powerCard); + assertEquals(turnState.getState(), powerCard); - //sends the turnStatemachine in ChoosePiece - powerCardStateMachine.gotoState(choosePowerCardState); - assertTrue(powerCardStateMachine.getState() instanceof ChoosePowerCardState); + //sends the turnState in ChoosePiece + powerCard.setState(choosePowerCard); + assertEquals(powerCard.getState(), choosePowerCard); - //todo send the messages, to force a state change to shield + //sends the possiblePiece-Message + clientGameLogic.received(possiblePieceShield); //tests if the client is in Shield - assertTrue(clientAutomaton.getState() instanceof GameState); - assertTrue(gameStateMachine.getState() instanceof TurnState); - assertTrue(turnStateMachine.getState() instanceof PowerCardState); - assertTrue(powerCardStateMachine.getState() instanceof ShieldState); + assertEquals(clientGameLogic.getState(), gameState); + assertEquals(gameState.getState(), turnState); + assertEquals(turnState.getState(), powerCard); + assertEquals(powerCard.getState(), shield); } /** @@ -940,29 +1913,60 @@ public void testChoosePowerCardToShield() { */ @Test public void testStayInShield() { - //sends the ClientAutomaton in GameState - clientAutomaton.gotoState(gameState); - assertTrue(clientAutomaton.getState() instanceof GameState); + //sends the ClientGameLogic in GameState + clientGameLogic.setState(gameState); + assertEquals(clientGameLogic.getState(), gameState); - //sends the gameStateMachine in the Turn - gameStateMachine.gotoState(turnState); - assertTrue(gameStateMachine.getState() instanceof TurnState); + //sends the gameState in the Turn + gameState.setState(turnState); + assertEquals(gameState.getState(), turnState); - //sends the turnStatemachine in PowerCard - turnStateMachine.gotoState(powerCardState); - assertTrue(turnStateMachine.getState() instanceof PowerCardState); + //sends the turnState in PowerCard + turnState.setState(powerCard); + assertEquals(turnState.getState(), powerCard); - //sends the turnStatemachine in Shield - powerCardStateMachine.gotoState(shieldState); - assertTrue(powerCardStateMachine.getState() instanceof ShieldState); + //sends the turnState in Shield + powerCard.setState(shield); + assertEquals(powerCard.getState(), shield); - //todo send the messages, which dont force a statechange + //send the messages, which don't force a statechange + clientGameLogic.received(activePlayer); + clientGameLogic.received(anyPiece); + clientGameLogic.received(briefing); + clientGameLogic.received(ceremonyMessage); + clientGameLogic.received(die); + clientGameLogic.received(diceAgain); + clientGameLogic.received(diceNow); + clientGameLogic.received(endOfTurn); + clientGameLogic.received(lobbyAccept); + clientGameLogic.received(lobbyDeny); + clientGameLogic.received(lobbyPlayerJoin); + clientGameLogic.received(lobbyPlayerLeave); + clientGameLogic.received(moveMessage); + clientGameLogic.received(noTurn); + //clientGameLogic.received(interruptMessage); commented out, because it indicates a state-change to interrupt + //clientGameLogic.received(playCardSwap); + //clientGameLogic.received(playCardShield); + //clientGameLogic.received(playCardTurbo); + clientGameLogic.received(possibleCard); + clientGameLogic.received(possiblePiece); + clientGameLogic.received(rankingResponse); + clientGameLogic.received(rankingRollAgain); + clientGameLogic.received(reconnectBriefing); + clientGameLogic.received(resumeGame); + clientGameLogic.received(startGame); + clientGameLogic.received(startPieceMessage); + clientGameLogic.received(updateReady); + clientGameLogic.received(updateTSK); + clientGameLogic.received(waitPiece); + clientGameLogic.received(spectatorMessage); + clientGameLogic.received(selectPieceMessage); //tests if the client is in PlayPowerCard - assertTrue(clientAutomaton.getState() instanceof GameState); - assertTrue(gameStateMachine.getState() instanceof TurnState); - assertTrue(turnStateMachine.getState() instanceof PowerCardState); - assertTrue(powerCardStateMachine.getState() instanceof PlayPowerCardState); + assertEquals(clientGameLogic.getState(), gameState); + assertEquals(gameState.getState(), turnState); + assertEquals(turnState.getState(), powerCard); + assertEquals(powerCard.getState(), shield); } /** @@ -970,29 +1974,68 @@ public void testStayInShield() { */ @Test public void testShieldToPowerCardEndState() { - //sends the ClientAutomaton in GameState - clientAutomaton.gotoState(gameState); - assertTrue(clientAutomaton.getState() instanceof GameState); + //sends the ClientGameLogic in GameState + clientGameLogic.setState(gameState); + assertEquals(clientGameLogic.getState(), gameState); - //sends the gameStateMachine in the Turn - gameStateMachine.gotoState(turnState); - assertTrue(gameStateMachine.getState() instanceof TurnState); + //sends the gameState in the Turn + gameState.setState(turnState); + assertEquals(gameState.getState(), turnState); - //sends the turnStatemachine in PowerCard - turnStateMachine.gotoState(powerCardState); - assertTrue(turnStateMachine.getState() instanceof PowerCardState); + //sends the turnState in PowerCard + turnState.setState(powerCard); + assertEquals(turnState.getState(), powerCard); - //sends the turnStatemachine in Shield - PowerCardStateMachine powerCardStateMachine1 = powerCardState.getPowerCardStateMachine(); - powerCardStateMachine1.gotoState(shieldState); - assertTrue(powerCardStateMachine1.getState() instanceof ShieldState); + //sends the turnState in Shield + powerCard.setState(shield); + assertEquals(powerCard.getState(), shield); - //todo send the message to force the statechange + //sends all messages that don't indicate a state-change + clientGameLogic.received(activePlayer); + clientGameLogic.received(anyPiece); + clientGameLogic.received(briefing); + clientGameLogic.received(ceremonyMessage); + clientGameLogic.received(die); + clientGameLogic.received(diceAgain); + clientGameLogic.received(diceNow); + clientGameLogic.received(endOfTurn); + clientGameLogic.received(lobbyAccept); + clientGameLogic.received(lobbyDeny); + clientGameLogic.received(lobbyPlayerJoin); + clientGameLogic.received(lobbyPlayerLeave); + clientGameLogic.received(moveMessage); + clientGameLogic.received(noTurn); + //clientGameLogic.received(interruptMessage); + //clientGameLogic.received(playCardSwap); + //clientGameLogic.received(playCardShield); + //clientGameLogic.received(playCardTurbo); + clientGameLogic.received(possibleCard); + clientGameLogic.received(possiblePiece); + clientGameLogic.received(rankingResponse); + clientGameLogic.received(rankingRollAgain); + clientGameLogic.received(reconnectBriefing); + clientGameLogic.received(resumeGame); + clientGameLogic.received(startGame); + clientGameLogic.received(startPieceMessage); + clientGameLogic.received(updateReady); + clientGameLogic.received(updateTSK); + clientGameLogic.received(waitPiece); + clientGameLogic.received(spectatorMessage); + clientGameLogic.received(selectPieceMessage); + + //tests if the client is still in shield + assertEquals(clientGameLogic.getState(), gameState); + assertEquals(gameState.getState(), turnState); + assertEquals(turnState.getState(), powerCard); + assertEquals(powerCard.getState(), shield); + + //sends the playPowerCardMessage + clientGameLogic.received(playCardShield); //tests if the client is in PlayPowerCard - assertTrue(clientAutomaton.getState() instanceof GameState); - assertTrue(gameStateMachine.getState() instanceof TurnState); - assertTrue(turnStateMachine.getState() instanceof PlayPowerCardState); + assertEquals(clientGameLogic.getState(), gameState); + assertEquals(gameState.getState(), turnState); + assertEquals(turnState.getState(), playPowerCard); } /** @@ -1000,28 +2043,29 @@ public void testShieldToPowerCardEndState() { */ @Test public void testSwapToPowerCardEndState() { - //sends the ClientAutomaton in GameState - clientAutomaton.gotoState(gameState); - assertTrue(clientAutomaton.getState() instanceof GameState); + //sends the ClientGameLogic in GameState + clientGameLogic.setState(gameState); + assertEquals(clientGameLogic.getState(), gameState); - //sends the gameStateMachine in the Turn - gameStateMachine.gotoState(turnState); - assertTrue(gameStateMachine.getState() instanceof TurnState); + //sends the gameState in the Turn + gameState.setState(turnState); + assertEquals(gameState.getState(), turnState); - //sends the turnStatemachine in PowerCard - turnStateMachine.gotoState(powerCardState); - assertTrue(turnStateMachine.getState() instanceof PowerCardState); + //sends the turnState in PowerCard + turnState.setState(powerCard); + assertEquals(turnState.getState(), powerCard); - //sends the turnStatemachine in Swap - powerCardStateMachine.gotoState(swapState); - assertTrue(powerCardStateMachine.getState() instanceof SwapState); + //sends the turnState in Swap + powerCard.setState(swap); + assertEquals(powerCard.getState(), swap); - //todo send the message to force the statechange + //sends the playCardMessage + clientGameLogic.received(playCardSwap); //tests if the client is in PlayPowerCard - assertTrue(clientAutomaton.getState() instanceof GameState); - assertTrue(gameStateMachine.getState() instanceof TurnState); - assertTrue(turnStateMachine.getState() instanceof PlayPowerCardState); + assertEquals(clientGameLogic.getState(), gameState); + assertEquals(gameState.getState(), turnState); + assertEquals(turnState.getState(), playPowerCard); } /** @@ -1029,31 +2073,62 @@ public void testSwapToPowerCardEndState() { */ @Test public void testNoPieceInWaitingPiece() { - //sends the ClientAutomaton in GameState - clientAutomaton.gotoState(gameState); - assertTrue(clientAutomaton.getState() instanceof GameState); + //sends the ClientGameLogic in GameState + clientGameLogic.setState(gameState); + assertEquals(clientGameLogic.getState(), gameState); - //sends the gameStateMachine in the Turn - gameStateMachine.gotoState(turnState); - assertTrue(gameStateMachine.getState() instanceof TurnState); + //sends the gameState in the Turn + gameState.setState(turnState); + assertEquals(gameState.getState(), turnState); - //sends the turnStatemachine in ChoosePiece - turnStateMachine.gotoState(choosePieceState); - assertTrue(turnStateMachine.getState() instanceof ChoosePieceState); + //sends the turnState in ChoosePiece + turnState.setState(choosePiece); + assertEquals(turnState.getState(), choosePiece); - //sends the choosePieceStatemachine in NoPiece - turnStateMachine.gotoState(noPieceState); - assertTrue(choosePieceStateMachine.getState() instanceof NoPieceState); + //sends the choosePiece in NoPiece + turnState.setState(noPiece); + assertEquals(choosePiece.getState(), noPiece); - //Todo test other messages, that there is no state change + //send other messages, that there is no state change + clientGameLogic.received(activePlayer); + clientGameLogic.received(anyPiece); + clientGameLogic.received(briefing); + clientGameLogic.received(ceremonyMessage); + clientGameLogic.received(die); + clientGameLogic.received(diceAgain); + clientGameLogic.received(diceNow); + clientGameLogic.received(endOfTurn); + clientGameLogic.received(lobbyAccept); + clientGameLogic.received(lobbyDeny); + clientGameLogic.received(lobbyPlayerJoin); + clientGameLogic.received(lobbyPlayerLeave); + clientGameLogic.received(moveMessage); + //clientGameLogic.received(noTurn); + //clientGameLogic.received(interruptMessage); commented out, because it indicates a statechange to interrupt + clientGameLogic.received(playCardSwap); + clientGameLogic.received(playCardShield); + clientGameLogic.received(playCardTurbo); + clientGameLogic.received(possibleCard); + clientGameLogic.received(possiblePiece); + clientGameLogic.received(rankingResponse); + clientGameLogic.received(rankingRollAgain); + clientGameLogic.received(reconnectBriefing); + clientGameLogic.received(resumeGame); + clientGameLogic.received(startGame); + clientGameLogic.received(startPieceMessage); + clientGameLogic.received(updateReady); + clientGameLogic.received(updateTSK); + //clientGameLogic.received(waitPiece); + clientGameLogic.received(spectatorMessage); + //clientGameLogic.received(selectPieceMessage); //sends to the clientGameLogic the message WaitPiece - clientGameLogic.receive(waitPiece); + clientGameLogic.received(waitPiece); - assertTrue(clientAutomaton.getState() instanceof GameState); - assertTrue(gameStateMachine.getState() instanceof TurnState); - assertTrue(turnStateMachine.getState() instanceof ChoosePieceState); - assertTrue(choosePieceStateMachine.getState() instanceof WaitingPieceState); + assertEquals(clientGameLogic.getState(), gameState); + assertEquals(gameState.getState(), turnState); + assertEquals(turnState.getState(), choosePiece); + assertEquals(choosePiece.getState(), waitingPiece); } /** @@ -1061,31 +2136,62 @@ public void testNoPieceInWaitingPiece() { */ @Test public void testNoPieceInSelectedPiece() { - //sends the ClientAutomaton in GameState - clientAutomaton.gotoState(gameState); - assertTrue(clientAutomaton.getState() instanceof GameState); + //sends the ClientGameLogic in GameState + clientGameLogic.setState(gameState); + assertEquals(clientGameLogic.getState(), gameState); - //sends the gameStateMachine in the Turn - gameStateMachine.gotoState(turnState); - assertTrue(gameStateMachine.getState() instanceof TurnState); + //sends the gameState in the Turn + gameState.setState(turnState); + assertEquals(gameState.getState(), turnState); - //sends the turnStatemachine in ChoosePiece - turnStateMachine.gotoState(choosePieceState); - assertTrue(turnStateMachine.getState() instanceof ChoosePieceState); + //sends the turnState in ChoosePiece + turnState.setState(choosePiece); + assertEquals(turnState.getState(), choosePiece); - //sends the choosePieceStatemachine in NoPiece - choosePieceStateMachine.gotoState(noPieceState); - assertTrue(choosePieceStateMachine.getState() instanceof NoPieceState); + //sends the choosePiece in NoPiece + choosePiece.setState(noPiece); + assertEquals(choosePiece.getState(), noPiece); - //Todo test other messages, that there is no state change + //send other messages, to test that there is no state change + clientGameLogic.received(activePlayer); + clientGameLogic.received(anyPiece); + clientGameLogic.received(briefing); + clientGameLogic.received(ceremonyMessage); + clientGameLogic.received(die); + clientGameLogic.received(diceAgain); + clientGameLogic.received(diceNow); + clientGameLogic.received(endOfTurn); + clientGameLogic.received(lobbyAccept); + clientGameLogic.received(lobbyDeny); + clientGameLogic.received(lobbyPlayerJoin); + clientGameLogic.received(lobbyPlayerLeave); + clientGameLogic.received(moveMessage); + //clientGameLogic.received(noTurn); + //clientGameLogic.received(interruptMessage); + clientGameLogic.received(playCardSwap); + clientGameLogic.received(playCardShield); + clientGameLogic.received(playCardTurbo); + clientGameLogic.received(possibleCard); + clientGameLogic.received(possiblePiece); + clientGameLogic.received(rankingResponse); + clientGameLogic.received(rankingRollAgain); + clientGameLogic.received(reconnectBriefing); + clientGameLogic.received(resumeGame); + clientGameLogic.received(startGame); + //clientGameLogic.received(startPieceMessage); + clientGameLogic.received(updateReady); + clientGameLogic.received(updateTSK); + //clientGameLogic.received(waitPiece); + clientGameLogic.received(spectatorMessage); + //clientGameLogic.received(selectPieceMessage); //sends to the clientGameLogic the message SelectPiece - clientGameLogic.receive(selectPieceState); + clientGameLogic.received(selectPieceMessage); - assertTrue(clientAutomaton.getState() instanceof GameState); - assertTrue(gameStateMachine.getState() instanceof TurnState); - assertTrue(turnStateMachine.getState() instanceof ChoosePieceState); - assertTrue(choosePieceStateMachine.getState() instanceof SelectPieceState); + assertEquals(clientGameLogic.getState(), gameState); + assertEquals(gameState.getState(), turnState); + assertEquals(turnState.getState(), choosePiece); + assertEquals(choosePiece.getState(), selectPiece); } /** @@ -1093,31 +2199,62 @@ public void testNoPieceInSelectedPiece() { */ @Test public void testNoPieceInStartPiece() { - //sends the ClientAutomaton in GameState - clientAutomaton.gotoState(gameState); - assertTrue(clientAutomaton.getState() instanceof GameState); + //sends the ClientGameLogic in GameState + clientGameLogic.setState(gameState); + assertEquals(clientGameLogic.getState(), gameState); - //sends the gameStateMachine in the Turn - gameStateMachine.gotoState(turnState); - assertTrue(gameStateMachine.getState() instanceof TurnState); + //sends the gameState in the Turn + gameState.setState(turnState); + assertEquals(gameState.getState(), turnState); - //sends the turnStatemachine in ChoosePiece - turnStateMachine.gotoState(choosePieceState); - assertTrue(turnStateMachine.getState() instanceof ChoosePieceState); + //sends the turnState in ChoosePiece + turnState.setState(choosePiece); + assertEquals(turnState.getState(), choosePiece); - //sends the choosePieceStatemachine in NoPiece - choosePieceStateMachine.gotoState(noPieceState); - assertTrue(choosePieceStateMachine.getState() instanceof NoPieceState); + //sends the choosePiece in NoPiece + choosePiece.setState(noPiece); + assertEquals(choosePiece.getState(), noPiece); - //Todo test other messages, that there is no state change + //sends other messages, that there is no state change + clientGameLogic.received(activePlayer); + clientGameLogic.received(anyPiece); + clientGameLogic.received(briefing); + clientGameLogic.received(ceremonyMessage); + clientGameLogic.received(die); + clientGameLogic.received(diceAgain); + clientGameLogic.received(diceNow); + clientGameLogic.received(endOfTurn); + clientGameLogic.received(lobbyAccept); + clientGameLogic.received(lobbyDeny); + clientGameLogic.received(lobbyPlayerJoin); + clientGameLogic.received(lobbyPlayerLeave); + clientGameLogic.received(moveMessage); + //clientGameLogic.received(noTurn); + //clientGameLogic.received(interruptMessage); + clientGameLogic.received(playCardSwap); + clientGameLogic.received(playCardShield); + clientGameLogic.received(playCardTurbo); + clientGameLogic.received(possibleCard); + clientGameLogic.received(possiblePiece); + clientGameLogic.received(rankingResponse); + clientGameLogic.received(rankingRollAgain); + clientGameLogic.received(reconnectBriefing); + clientGameLogic.received(resumeGame); + clientGameLogic.received(startGame); + //clientGameLogic.received(startPieceMessage); + clientGameLogic.received(updateReady); + clientGameLogic.received(updateTSK); + //clientGameLogic.received(waitPiece); + clientGameLogic.received(spectatorMessage); + //clientGameLogic.received(selectPieceMessage); //sends to the clientGameLogic the message StartPiece - clientGameLogic.receive(startPieceState); + clientGameLogic.received(startPieceMessage); - assertTrue(clientAutomaton.getState() instanceof GameState); - assertTrue(gameStateMachine.getState() instanceof TurnState); - assertTrue(turnStateMachine.getState() instanceof ChoosePieceState); - assertTrue(choosePieceStateMachine.getState() instanceof StartPieceState); + assertEquals(clientGameLogic.getState(), gameState); + assertEquals(gameState.getState(), turnState); + assertEquals(turnState.getState(), choosePiece); + assertEquals(choosePiece.getState(), startPiece); } /** @@ -1125,30 +2262,66 @@ public void testNoPieceInStartPiece() { */ @Test public void testNoPieceInWait() { - //sends the ClientAutomaton in GameState - clientAutomaton.gotoState(gameState); - assertTrue(clientAutomaton.getState() instanceof GameState); + //sends the ClientGameLogic in GameState + clientGameLogic.setState(gameState); + assertEquals(clientGameLogic.getState(), gameState); - //sends the gameStateMachine in the Turn - gameStateMachine.gotoState(turnState); - assertTrue(gameStateMachine.getState() instanceof TurnState); + //sends the gameState in the Turn + gameState.setState(turnState); + assertEquals(gameState.getState(), turnState); - //sends the turnStatemachine in ChoosePiece - turnStateMachine.gotoState(choosePieceState); - assertTrue(turnStateMachine.getState() instanceof ChoosePieceState); + //sends the turnState in ChoosePiece + turnState.setState(choosePiece); + assertEquals(turnState.getState(), choosePiece); - //sends the choosePieceStatemachine in NoPiece - choosePieceStateMachine.gotoState(noPieceState); - assertTrue(choosePieceStateMachine.getState() instanceof NoPieceState); + //sends the choosePieceState in NoPiece + choosePiece.setState(noPiece); + assertEquals(choosePiece.getState(), noPiece); - //Todo test other messages, that there is no state change + //test other messages, that there is no state change + clientGameLogic.received(activePlayer); + clientGameLogic.received(anyPiece); + clientGameLogic.received(briefing); + clientGameLogic.received(ceremonyMessage); + clientGameLogic.received(die); + clientGameLogic.received(diceAgain); + clientGameLogic.received(diceNow); + clientGameLogic.received(endOfTurn); + clientGameLogic.received(lobbyAccept); + clientGameLogic.received(lobbyDeny); + clientGameLogic.received(lobbyPlayerJoin); + clientGameLogic.received(lobbyPlayerLeave); + clientGameLogic.received(moveMessage); + //clientGameLogic.received(noTurn); + //clientGameLogic.received(interruptMessage); + clientGameLogic.received(playCardSwap); + clientGameLogic.received(playCardShield); + clientGameLogic.received(playCardTurbo); + clientGameLogic.received(possibleCard); + clientGameLogic.received(possiblePiece); + clientGameLogic.received(rankingResponse); + clientGameLogic.received(rankingRollAgain); + clientGameLogic.received(reconnectBriefing); + clientGameLogic.received(resumeGame); + clientGameLogic.received(startGame); + //clientGameLogic.received(startPieceMessage); + clientGameLogic.received(updateReady); + clientGameLogic.received(updateTSK); + //clientGameLogic.received(waitPiece); + clientGameLogic.received(spectatorMessage); + //clientGameLogic.received(selectPieceMessage); + + //tests if the client is still in noPiece + assertEquals(clientGameLogic.getState(), gameState); + assertEquals(gameState.getState(), turnState); + assertEquals(turnState.getState(), choosePiece); + assertEquals(choosePiece.getState(), noPiece); //sends to the clientGameLogic the message NoTurn - clientGameLogic.receive(noTurn); + clientGameLogic.received(noTurn); - assertTrue(clientAutomaton.getState() instanceof GameState); - assertTrue(gameStateMachine.getState() instanceof TurnState); - assertTrue(turnStateMachine.getState() instanceof WaitingState); + assertEquals(clientGameLogic.getState(), gameState); + assertEquals(gameState.getState(), waiting); } /** @@ -1156,28 +2329,60 @@ public void testNoPieceInWait() { */ @Test public void testStayInWaitingPiece() { - //sends the ClientAutomaton in GameState - clientAutomaton.gotoState(gameState); - assertTrue(clientAutomaton.getState() instanceof GameState); + //sends the ClientGameLogic in GameState + clientGameLogic.setState(gameState); + assertEquals(clientGameLogic.getState(), gameState); - //sends the gameStateMachine in the Turn - gameStateMachine.gotoState(turnState); - assertTrue(gameStateMachine.getState() instanceof TurnState); + //sends the gameState in the Turn + gameState.setState(turnState); + assertEquals(gameState.getState(), turnState); - //sends the turnStatemachine in ChoosePiece - turnStateMachine.gotoState(choosePieceState); - assertTrue(turnStateMachine.getState() instanceof ChoosePieceState); + //sends the turnState in ChoosePiece + turnState.setState(choosePiece); + assertEquals(turnState.getState(), choosePiece); - //sends the choosePieceStatemachine in WaitingPiece - choosePieceStateMachine.gotoState(waitingPieceState); - assertTrue(choosePieceStateMachine.getState() instanceof WaitingPieceState); + //sends the choosePieceState in WaitingPiece + choosePiece.setState(waitingPiece); + assertEquals(choosePiece.getState(), waitingPiece); - //TODO send all sever-messages except ... to the clientGameLogic to test there are no state change + //send all sever-messages except interrupt and moveMessage to test, if there are no state change + clientGameLogic.received(activePlayer); + clientGameLogic.received(anyPiece); + clientGameLogic.received(briefing); + clientGameLogic.received(ceremonyMessage); + clientGameLogic.received(die); + clientGameLogic.received(diceAgain); + clientGameLogic.received(diceNow); + clientGameLogic.received(endOfTurn); + clientGameLogic.received(lobbyAccept); + clientGameLogic.received(lobbyDeny); + clientGameLogic.received(lobbyPlayerJoin); + clientGameLogic.received(lobbyPlayerLeave); + //clientGameLogic.received(moveMessage); + clientGameLogic.received(noTurn); + //clientGameLogic.received(interruptMessage); + clientGameLogic.received(playCardSwap); + clientGameLogic.received(playCardShield); + clientGameLogic.received(playCardTurbo); + clientGameLogic.received(possibleCard); + clientGameLogic.received(possiblePiece); + clientGameLogic.received(rankingResponse); + clientGameLogic.received(rankingRollAgain); + clientGameLogic.received(reconnectBriefing); + clientGameLogic.received(resumeGame); + clientGameLogic.received(startGame); + clientGameLogic.received(startPieceMessage); + clientGameLogic.received(updateReady); + clientGameLogic.received(updateTSK); + clientGameLogic.received(waitPiece); + clientGameLogic.received(spectatorMessage); + clientGameLogic.received(selectPieceMessage); - assertTrue(clientAutomaton.getState() instanceof GameState); - assertTrue(gameStateMachine.getState() instanceof TurnState); - assertTrue(turnStateMachine.getState() instanceof ChoosePieceState); - assertTrue(choosePieceStateMachine.getState() instanceof WaitingPieceState); + //tests, if the client is still in WaitingPiece + assertEquals(clientGameLogic.getState(), gameState); + assertEquals(gameState.getState(), turnState); + assertEquals(turnState.getState(), choosePiece); + assertEquals(choosePiece.getState(), waitingPiece); } /** @@ -1185,27 +2390,28 @@ public void testStayInWaitingPiece() { */ @Test public void testWaitingPieceInChoosePieceEndState() { - //sends the ClientAutomaton in GameState - clientAutomaton.gotoState(gameState); - assertTrue(clientAutomaton.getState() instanceof GameState); + //sends the ClientGameLogic in GameState + clientGameLogic.setState(gameState); + assertEquals(clientGameLogic.getState(), gameState); - //sends the gameStateMachine in the Turn - gameStateMachine.gotoState(turnState); - assertTrue(gameStateMachine.getState() instanceof TurnState); + //sends the gameState in the Turn + gameState.setState(turnState); + assertEquals(gameState.getState(), turnState); - //sends the turnStatemachine in ChoosePiece - turnStateMachine.gotoState(choosePieceState); - assertTrue(turnStateMachine.getState() instanceof ChoosePieceState); + //sends the turnState in ChoosePiece + turnState.setState(choosePiece); + assertEquals(turnState.getState(), choosePiece); - //sends the choosePieceStatemachine in WaitingPiece - choosePieceStateMachine.gotoState(waitingPieceState); - assertTrue(choosePieceStateMachine.getState() instanceof WaitingPieceState); + //sends the choosePieceState in WaitingPiece + choosePiece.setState(waitingPiece); + assertEquals(choosePiece.getState(), waitingPiece); - //Todo send the message to the clientGameLogic to force a state change + //send the move-message to the clientGameLogic to force a state change + clientGameLogic.received(moveMessage); - assertTrue(clientAutomaton.getState() instanceof GameState); - assertTrue(gameStateMachine.getState() instanceof TurnState); - assertTrue(turnStateMachine.getState() instanceof MovePieceState); + assertEquals(clientGameLogic.getState(), gameState); + assertEquals(gameState.getState(), turnState); + assertEquals(turnState.getState(), movePiece); } /** @@ -1213,28 +2419,59 @@ public void testWaitingPieceInChoosePieceEndState() { */ @Test public void testStayInSelectedPiece() { - //sends the ClientAutomaton in GameState - clientAutomaton.gotoState(gameState); - assertTrue(clientAutomaton.getState() instanceof GameState); + //sends the ClientGameLogic in GameState + clientGameLogic.setState(gameState); + assertEquals(clientGameLogic.getState(), gameState); - //sends the gameStateMachine in the Turn - gameStateMachine.gotoState(turnState); - assertTrue(gameStateMachine.getState() instanceof TurnState); + //sends the gameState in the Turn + gameState.setState(turnState); + assertEquals(gameState.getState(), turnState); - //sends the turnStatemachine in ChoosePiece - turnStateMachine.gotoState(choosePieceState); - assertTrue(turnStateMachine.getState() instanceof ChoosePieceState); + //sends the turnState in ChoosePiece + turnState.setState(choosePiece); + assertEquals(turnState.getState(), choosePiece); - //sends the choosePieceStatemachine in SelectPiece; - choosePieceStateMachine.gotoState(selectPieceState); - assertTrue(choosePieceStateMachine.getState() instanceof SelectPieceState); + //sends the choosePieceState in SelectPiece; + choosePiece.setState(selectPiece); + assertEquals(choosePiece.getState(), selectPiece); - //Todo send all server messages which dont force a state change here + //send all server messages which don't force a state change here + clientGameLogic.received(activePlayer); + clientGameLogic.received(anyPiece); + clientGameLogic.received(briefing); + clientGameLogic.received(ceremonyMessage); + clientGameLogic.received(die); + clientGameLogic.received(diceAgain); + clientGameLogic.received(diceNow); + clientGameLogic.received(endOfTurn); + clientGameLogic.received(lobbyAccept); + clientGameLogic.received(lobbyDeny); + clientGameLogic.received(lobbyPlayerJoin); + clientGameLogic.received(lobbyPlayerLeave); + //clientGameLogic.received(moveMessage); + clientGameLogic.received(noTurn); + //clientGameLogic.received(interruptMessage); + clientGameLogic.received(playCardSwap); + clientGameLogic.received(playCardShield); + clientGameLogic.received(playCardTurbo); + clientGameLogic.received(possibleCard); + clientGameLogic.received(possiblePiece); + clientGameLogic.received(rankingResponse); + clientGameLogic.received(rankingRollAgain); + clientGameLogic.received(reconnectBriefing); + clientGameLogic.received(resumeGame); + clientGameLogic.received(startGame); + clientGameLogic.received(startPieceMessage); + clientGameLogic.received(updateReady); + clientGameLogic.received(updateTSK); + clientGameLogic.received(waitPiece); + clientGameLogic.received(spectatorMessage); + clientGameLogic.received(selectPieceMessage); - assertTrue(clientAutomaton.getState() instanceof GameState); - assertTrue(gameStateMachine.getState() instanceof TurnState); - assertTrue(turnStateMachine.getState() instanceof ChoosePieceState); - assertTrue(choosePieceStateMachine.getState() instanceof SelectPieceState); + assertEquals(clientGameLogic.getState(), gameState); + assertEquals(gameState.getState(), turnState); + assertEquals(turnState.getState(), choosePiece); + assertEquals(choosePiece.getState(), selectPiece); } /** @@ -1242,27 +2479,28 @@ public void testStayInSelectedPiece() { */ @Test public void testSelectedPieceInChoosePieceEndState() { - //sends the ClientAutomaton in GameState - clientAutomaton.gotoState(gameState); - assertTrue(clientAutomaton.getState() instanceof GameState); + //sends the ClientGameLogic in GameState + clientGameLogic.setState(gameState); + assertEquals(clientGameLogic.getState(), gameState); - //sends the gameStateMachine in the Turn - gameStateMachine.gotoState(turnState); - assertTrue(gameStateMachine.getState() instanceof TurnState); + //sends the gameState in the Turn + gameState.setState(turnState); + assertEquals(gameState.getState(), turnState); - //sends the turnStatemachine in ChoosePiece - turnStateMachine.gotoState(choosePieceState); - assertTrue(turnStateMachine.getState() instanceof ChoosePieceState); + //sends the turnState in ChoosePiece + turnState.setState(choosePiece); + assertEquals(turnState.getState(), choosePiece); - //sends the choosePieceStatemachine in SelectPiece - choosePieceStateMachine.gotoState(selectPieceState); - assertTrue(choosePieceStateMachine.getState() instanceof SelectPieceState); + //sends the choosePieceState in SelectPiece + choosePiece.setState(selectPiece); + assertEquals(choosePiece.getState(), selectPiece); - //Todo send the message which force a state change + //sends the move-message + clientGameLogic.received(moveMessage); - assertTrue(clientAutomaton.getState() instanceof GameState); - assertTrue(gameStateMachine.getState() instanceof TurnState); - assertTrue(turnStateMachine.getState() instanceof MovePieceState); + assertEquals(clientGameLogic.getState(), gameState); + assertEquals(gameState.getState(), turnState); + assertEquals(turnState.getState(), movePiece); } /** @@ -1270,56 +2508,128 @@ public void testSelectedPieceInChoosePieceEndState() { */ @Test public void testStayInStartPiece() { - //sends the ClientAutomaton in GameState - clientAutomaton.gotoState(gameState); - assertTrue(clientAutomaton.getState() instanceof GameState); + //sends the ClientGameLogic in GameState + clientGameLogic.setState(gameState); + assertEquals(clientGameLogic.getState(), gameState); - //sends the gameStateMachine in the Turn - gameStateMachine.gotoState(turnState); - assertTrue(gameStateMachine.getState() instanceof TurnState); + //sends the gameState in the Turn + gameState.setState(turnState); + assertEquals(gameState.getState(), turnState); - //sends the turnStatemachine in ChoosePiece - turnStateMachine.gotoState(choosePieceState); - assertTrue(turnStateMachine.getState() instanceof ChoosePieceState); + //sends the turnState in ChoosePiece + turnState.setState(choosePiece); + assertEquals(turnState.getState(), choosePiece); - //sends the choosePieceStatemachine in StartPiece - choosePieceStateMachine.gotoState(startPieceState); - assertTrue(choosePieceStateMachine.getState() instanceof StartPieceState); + //sends the choosePieceState in StartPiece + choosePiece.setState(startPiece); + assertEquals(choosePiece.getState(), startPiece); - //todo send all messages which dont force a state change + //send all messages which don't force a state change + clientGameLogic.received(activePlayer); + clientGameLogic.received(anyPiece); + clientGameLogic.received(briefing); + clientGameLogic.received(ceremonyMessage); + clientGameLogic.received(die); + clientGameLogic.received(diceAgain); + clientGameLogic.received(diceNow); + clientGameLogic.received(endOfTurn); + clientGameLogic.received(lobbyAccept); + clientGameLogic.received(lobbyDeny); + clientGameLogic.received(lobbyPlayerJoin); + clientGameLogic.received(lobbyPlayerLeave); + //clientGameLogic.received(moveMessage); + clientGameLogic.received(noTurn); + //clientGameLogic.received(interruptMessage); + clientGameLogic.received(playCardSwap); + clientGameLogic.received(playCardShield); + clientGameLogic.received(playCardTurbo); + clientGameLogic.received(possibleCard); + clientGameLogic.received(possiblePiece); + clientGameLogic.received(rankingResponse); + clientGameLogic.received(rankingRollAgain); + clientGameLogic.received(reconnectBriefing); + clientGameLogic.received(resumeGame); + clientGameLogic.received(startGame); + clientGameLogic.received(startPieceMessage); + clientGameLogic.received(updateReady); + clientGameLogic.received(updateTSK); + clientGameLogic.received(waitPiece); + clientGameLogic.received(spectatorMessage); + clientGameLogic.received(selectPieceMessage); - assertTrue(clientAutomaton.getState() instanceof GameState); - assertTrue(gameStateMachine.getState() instanceof TurnState); - assertTrue(turnStateMachine.getState() instanceof ChoosePieceState); - assertTrue(choosePieceStateMachine.getState() instanceof StartPieceState); + assertEquals(clientGameLogic.getState(), gameState); + assertEquals(gameState.getState(), turnState); + assertEquals(turnState.getState(), choosePiece); + assertEquals(choosePiece.getState(), startPiece); } /** - * UC-ClientState-57: Test the StartPiece to ChoosePiece end state. + * UC-ClientState-57: Test the StartPiece to ChoosePiece-end-state. */ @Test public void testStartPieceToChoosePieceEndState() { - //sends the ClientAutomaton in GameState - clientAutomaton.gotoState(gameState); - assertTrue(clientAutomaton.getState() instanceof GameState); + //sends the ClientGameLogic in GameState + clientGameLogic.setState(gameState); + assertEquals(clientGameLogic.getState(), gameState); - //sends the gameStateMachine in the Turn - gameStateMachine.gotoState(turnState); - assertTrue(gameStateMachine.getState() instanceof TurnState); + //sends the gameState in the Turn + gameState.setState(turnState); + assertEquals(gameState.getState(), turnState); - //sends the turnStatemachine in ChoosePiece - turnStateMachine.gotoState(choosePieceState); - assertTrue(turnStateMachine.getState() instanceof ChoosePieceState); + //sends the turnState in ChoosePiece + turnState.setState(choosePiece); + assertEquals(turnState.getState(), choosePiece); - //sends the choosePieceStatemachine in StartPiece - choosePieceStateMachine.gotoState(startPieceState); - assertTrue(choosePieceStateMachine.getState() instanceof StartPieceState); + //sends the choosePieceState in StartPiece + choosePiece.setState(startPiece); + assertEquals(choosePiece.getState(), startPiece); - //Todo send the message which force a state change + //send the message that don't indicate a statechange + clientGameLogic.received(activePlayer); + clientGameLogic.received(anyPiece); + clientGameLogic.received(briefing); + clientGameLogic.received(ceremonyMessage); + clientGameLogic.received(die); + clientGameLogic.received(diceAgain); + clientGameLogic.received(diceNow); + clientGameLogic.received(endOfTurn); + clientGameLogic.received(lobbyAccept); + clientGameLogic.received(lobbyDeny); + clientGameLogic.received(lobbyPlayerJoin); + clientGameLogic.received(lobbyPlayerLeave); + //clientGameLogic.received(moveMessage); + clientGameLogic.received(noTurn); + //clientGameLogic.received(interruptMessage); + clientGameLogic.received(playCardSwap); + clientGameLogic.received(playCardShield); + clientGameLogic.received(playCardTurbo); + clientGameLogic.received(possibleCard); + clientGameLogic.received(possiblePiece); + clientGameLogic.received(rankingResponse); + clientGameLogic.received(rankingRollAgain); + clientGameLogic.received(reconnectBriefing); + clientGameLogic.received(resumeGame); + clientGameLogic.received(startGame); + clientGameLogic.received(startPieceMessage); + clientGameLogic.received(updateReady); + clientGameLogic.received(updateTSK); + clientGameLogic.received(waitPiece); + clientGameLogic.received(spectatorMessage); + clientGameLogic.received(selectPieceMessage); - assertTrue(clientAutomaton.getState() instanceof GameState); - assertTrue(gameStateMachine.getState() instanceof TurnState); - assertTrue(turnStateMachine.getState() instanceof MovePieceState); + //tests if the client ist still in StartPiece + assertEquals(clientGameLogic.getState(), gameState); + assertEquals(gameState.getState(), turnState); + assertEquals(turnState.getState(), choosePiece); + assertEquals(choosePiece.getState(), startPiece); + + //send MovePieceMessage + clientGameLogic.received(moveMessage); + + //tests if the client is in the movePiece-state + assertEquals(clientGameLogic.getState(), gameState); + assertEquals(gameState.getState(), turnState); + assertEquals(turnState.getState(), movePiece); } /** @@ -1327,7 +2637,63 @@ public void testStartPieceToChoosePieceEndState() { */ @Test public void testRollRankingDiceToWaitRanking() { - // Implementation goes here + //sends the ClientGameLogic in GameState + clientGameLogic.setState(gameState); + assertEquals(clientGameLogic.getState(), gameState); + + //sends the gameState in the determineStartPlayer + gameState.setState(determineStartPlayer); + assertEquals(gameState.getState(), determineStartPlayer); + + //sends the turnState in ChoosePiece + determineStartPlayer.setState(rollRankingDice); + assertEquals(determineStartPlayer.getState(), rollRankingDice); + + //sends all messages that don't indicate a state-change + clientGameLogic.received(activePlayer); + clientGameLogic.received(anyPiece); + clientGameLogic.received(briefing); + clientGameLogic.received(ceremonyMessage); + //clientGameLogic.received(die); + clientGameLogic.received(diceAgain); + clientGameLogic.received(diceNow); + clientGameLogic.received(endOfTurn); + clientGameLogic.received(lobbyAccept); + clientGameLogic.received(lobbyDeny); + clientGameLogic.received(lobbyPlayerJoin); + clientGameLogic.received(lobbyPlayerLeave); + clientGameLogic.received(moveMessage); + clientGameLogic.received(noTurn); + //clientGameLogic.received(interruptMessage); + clientGameLogic.received(playCardSwap); + clientGameLogic.received(playCardShield); + clientGameLogic.received(playCardTurbo); + clientGameLogic.received(possibleCard); + clientGameLogic.received(possiblePiece); + clientGameLogic.received(rankingResponse); + clientGameLogic.received(rankingRollAgain); + clientGameLogic.received(reconnectBriefing); + clientGameLogic.received(resumeGame); + clientGameLogic.received(startGame); + clientGameLogic.received(startPieceMessage); + clientGameLogic.received(updateReady); + clientGameLogic.received(updateTSK); + clientGameLogic.received(waitPiece); + clientGameLogic.received(spectatorMessage); + clientGameLogic.received(selectPieceMessage); + + //test if the client is still in rollRankingDice + assertEquals(clientGameLogic.getState(), gameState); + assertEquals(gameState.getState(), determineStartPlayer); + assertEquals(determineStartPlayer.getState(), rollRankingDice); + + //sends die-message + clientGameLogic.received(die); + + //test if the client is in waitRanking + assertEquals(clientGameLogic.getState(), gameState); + assertEquals(gameState.getState(), determineStartPlayer); + assertEquals(determineStartPlayer.getState(), waitRanking); } /** @@ -1335,7 +2701,63 @@ public void testRollRankingDiceToWaitRanking() { */ @Test public void testWaitRankingToRollRankingDice() { - // Implementation goes here + //sends the ClientGameLogic in GameState + clientGameLogic.setState(gameState); + assertEquals(clientGameLogic.getState(), gameState); + + //sends the gameState in the determineStartPlayer + gameState.setState(determineStartPlayer); + assertEquals(gameState.getState(), determineStartPlayer); + + //sends the turnState in ChoosePiece + determineStartPlayer.setState(waitRanking); + assertEquals(determineStartPlayer.getState(), waitRanking); + + //sends all messages that don't indicate a state-change + clientGameLogic.received(activePlayer); + clientGameLogic.received(anyPiece); + clientGameLogic.received(briefing); + clientGameLogic.received(ceremonyMessage); + clientGameLogic.received(die); + clientGameLogic.received(diceAgain); + clientGameLogic.received(diceNow); + //clientGameLogic.received(endOfTurn); + clientGameLogic.received(lobbyAccept); + clientGameLogic.received(lobbyDeny); + clientGameLogic.received(lobbyPlayerJoin); + clientGameLogic.received(lobbyPlayerLeave); + clientGameLogic.received(moveMessage); + clientGameLogic.received(noTurn); + //clientGameLogic.received(interruptMessage); + clientGameLogic.received(playCardSwap); + clientGameLogic.received(playCardShield); + clientGameLogic.received(playCardTurbo); + clientGameLogic.received(possibleCard); + clientGameLogic.received(possiblePiece); + clientGameLogic.received(rankingResponse); + //clientGameLogic.received(rankingRollAgain); + clientGameLogic.received(reconnectBriefing); + clientGameLogic.received(resumeGame); + clientGameLogic.received(startGame); + clientGameLogic.received(startPieceMessage); + clientGameLogic.received(updateReady); + clientGameLogic.received(updateTSK); + clientGameLogic.received(waitPiece); + clientGameLogic.received(spectatorMessage); + clientGameLogic.received(selectPieceMessage); + + //test if the client is still in waitRanking + assertEquals(clientGameLogic.getState(), gameState); + assertEquals(gameState.getState(), determineStartPlayer); + assertEquals(determineStartPlayer.getState(), waitRanking); + + //sends rankingRollAgain-message + clientGameLogic.received(rankingRollAgain); + + //test if the client is in rollRankingDice + assertEquals(clientGameLogic.getState(), gameState); + assertEquals(gameState.getState(), determineStartPlayer); + assertEquals(determineStartPlayer.getState(), rollRankingDice); } /** @@ -1343,7 +2765,62 @@ public void testWaitRankingToRollRankingDice() { */ @Test public void testWaitRankingToEndStateDetermineStartingPlayer() { - // Implementation goes here + //sends the ClientGameLogic in GameState + clientGameLogic.setState(gameState); + assertEquals(clientGameLogic.getState(), gameState); + + //sends the gameState in the determineStartPlayer + gameState.setState(determineStartPlayer); + assertEquals(gameState.getState(), determineStartPlayer); + + //sends the turnState in ChoosePiece + determineStartPlayer.setState(waitRanking); + assertEquals(determineStartPlayer.getState(), waitRanking); + + //sends all messages that don't indicate a state-change + clientGameLogic.received(activePlayer); + clientGameLogic.received(anyPiece); + clientGameLogic.received(briefing); + clientGameLogic.received(ceremonyMessage); + clientGameLogic.received(die); + clientGameLogic.received(diceAgain); + clientGameLogic.received(diceNow); + //clientGameLogic.received(endOfTurn); + clientGameLogic.received(lobbyAccept); + clientGameLogic.received(lobbyDeny); + clientGameLogic.received(lobbyPlayerJoin); + clientGameLogic.received(lobbyPlayerLeave); + clientGameLogic.received(moveMessage); + clientGameLogic.received(noTurn); + //clientGameLogic.received(interruptMessage); + clientGameLogic.received(playCardSwap); + clientGameLogic.received(playCardShield); + clientGameLogic.received(playCardTurbo); + clientGameLogic.received(possibleCard); + clientGameLogic.received(possiblePiece); + clientGameLogic.received(rankingResponse); + //clientGameLogic.received(rankingRollAgain); + clientGameLogic.received(reconnectBriefing); + clientGameLogic.received(resumeGame); + clientGameLogic.received(startGame); + clientGameLogic.received(startPieceMessage); + clientGameLogic.received(updateReady); + clientGameLogic.received(updateTSK); + clientGameLogic.received(waitPiece); + clientGameLogic.received(spectatorMessage); + clientGameLogic.received(selectPieceMessage); + + //test if the client is still in waitRanking + assertEquals(clientGameLogic.getState(), gameState); + assertEquals(gameState.getState(), determineStartPlayer); + assertEquals(determineStartPlayer.getState(), waitRanking); + + //sends endOfTurn-message + clientGameLogic.received(endOfTurn); + + //test if the client is in wait + assertEquals(clientGameLogic.getState(), gameState); + assertEquals(gameState.getState(), waiting); } /** @@ -1351,7 +2828,20 @@ public void testWaitRankingToEndStateDetermineStartingPlayer() { */ @Test public void testPodiumToStatistics() { - // Implementation goes here + //sends the clientGameLogic into Ceremony + clientGameLogic.setState(ceremony); + assertEquals(clientGameLogic.getState(), ceremony); + + //sends the ceremony into podium + ceremony.setState(podium); + assertEquals(ceremony.getState(), podium); + + //simulate button-push + clientGameLogic.selectNext(); + + //tests if the client is in statistics + assertEquals(clientGameLogic.getState(), ceremony); + assertEquals(ceremony.getState(), statistics); } /** @@ -1359,71 +2849,19 @@ public void testPodiumToStatistics() { */ @Test public void testStatisticsToCeremonyEndState() { - // Implementation goes here - } + //sends the client in ceremony + clientGameLogic.setState(ceremony); + assertEquals(clientGameLogic.getState(), ceremony); - /** - * UC-ClientState-63: Test the transition from MainSettings to VideoSettings. - */ - @Test - public void testMainSettingsToVideoSettings() { - // Implementation goes here - } + //sends the ceremony in statistics + ceremony.setState(statistics); + assertEquals(ceremony.getState(), statistics); - /** - * UC-ClientState-64: Test the transition from MainSettings to AudioSettings. - */ - @Test - public void testMainSettingsToAudioSettings() { - // Implementation goes here - } + //simulate button-push + clientGameLogic.selectNext(); - /** - * UC-ClientState-65: Test the transition from MainSettings to ClientState. - */ - @Test - public void testMainSettingsToClientState() { - // Implementation goes here + //tests if client is in startDialog + assertEquals(clientGameLogic.getState(), dialogs); + assertEquals(dialogs.getState(), startDialog); } - - /** - * UC-ClientState-66: Test staying in the VideoSettings state. - */ - @Test - public void testStayInVideoSettings() { - // Implementation goes here - } - - /** - * UC-ClientState-67: Test the transition from VideoSettings to MainSettings. - */ - @Test - public void testVideoSettingsToMainSettings() { - // Implementation goes here - } - - /** - * UC-ClientState-68: Test staying in the AudioSettings state. - */ - @Test - public void testStayInAudioSettings() { - // Implementation goes here - } - - /** - * UC-ClientState-69: Test the transition from AudioSettings to MainSettings. - */ - @Test - public void testAudioSettingsToMainSettings() { - // Implementation goes here - } - - /** - * UC-ClientState-70: Test the transition from ClientState substates to MainSettings. - */ - @Test - public void testClientStateSubStatesToMainSettings() { - // Implementation goes here - } - } diff --git a/Projekte/mdga/model/src/test/java/pp/mdga/game/PieceTest.java b/Projekte/mdga/model/src/test/java/pp/mdga/game/PieceTest.java index 30c770c1..776b1036 100644 --- a/Projekte/mdga/model/src/test/java/pp/mdga/game/PieceTest.java +++ b/Projekte/mdga/model/src/test/java/pp/mdga/game/PieceTest.java @@ -2,144 +2,355 @@ import org.junit.Before; import org.junit.Test; +import pp.mdga.message.server.ServerMessage; +import pp.mdga.server.ServerGameLogic; +import pp.mdga.server.ServerSender; /** * this test-class tests the testcases T035-T058 */ public class PieceTest { + //declare game here + private Game game; + + //declare server here + private ServerGameLogic serverGameLogic; + + //declare player-Client here + private Player playerClient; + private String nameClient = "Client"; + private Color clientColor; + + //declare pieces of client here + private Piece pieceClient0; + private Piece pieceClient1; + private Piece pieceClient2; + private Piece pieceClient3; + + //declare player-host here + private Player playerHost; + private String nameHost = "Host"; + private Color hostColor; + + //declare pieces of host here + private Piece pieceHost0; + private Piece pieceHost1; + private Piece pieceHost2; + private Piece pieceHost3; + + //declare messages here + @Before public void Setup() { + //initialize game here + game = new Game(); + + //initialize server here + serverGameLogic = new ServerGameLogic(new ServerSender() { + @Override + public void send(int id, ServerMessage message) { + + } + + @Override + public void broadcast(ServerMessage message) { + + } + },game); + + //declare player-Client here + playerClient = new Player(nameClient); + clientColor = Color.ARMY; + game.addPlayer(2,playerClient); + + //declare pieces of client here + pieceClient0 = new Piece(clientColor,PieceState.ACTIVE,3); + pieceClient1 = new Piece(clientColor,PieceState.ACTIVE,4); + pieceClient2 = new Piece(clientColor,PieceState.ACTIVE,5); + pieceClient3 = new Piece(clientColor,PieceState.ACTIVE,6); + + //declare player-host here + playerHost = new Player(nameHost); + hostColor = Color.NAVY; + game.addPlayer(1,playerHost); + + //declare pieces of host here + pieceHost0 = new Piece(hostColor,PieceState.ACTIVE,7); + pieceHost1 = new Piece(hostColor,PieceState.ACTIVE,8); + pieceHost2 = new Piece(hostColor,PieceState.ACTIVE,9); + pieceHost3 = new Piece(hostColor,PieceState.ACTIVE,10); + + //set the Client-pieces here + game.getBoard().setPieceOnBoard(25,pieceClient0); //for UC 02, 03.01, 14,4 + game.getBoard().setPieceOnBoard(); //TODo set piece in Home at 2 slot for UC 18,12,13,11 + game.getBoard().setPieceOnBoard(19,pieceClient2); //for UC 13, 15 + game.getBoard().setPieceOnBoard(); + + //set the host-pieces here + game.getBoard().setPieceOnBoard(28,pieceHost0); //for UC 02,14 ,15, 03.01,4 + game.getBoard().setPieceOnBoard(18,pieceHost1); //for UC 1, 10, 17, 16 + game.getBoard().setPieceOnBoard();//Todo set in home fur uc 5 + game.getBoard().setPieceOnBoard(0,pieceHost3); //for uc 9 + + + //declare messages here + + //send the serverGameTurn + + //set the active color + game.setActiveColor(clientColor); } - // UC-Piece-01 + /** + * Tests the logic for when a piece moves. + *
+ * Use Case UC-Piece-01: Ensure that a piece moves in the right direction + *
+ */ @Test public void testMove() { - // TODO: Implement test logic for moving a piece + // TODO: Implement test logic for when a piece can't move } - // UC-Piece-02 + /** + * Tests the logic for when a piece can't move. + *+ * Use Case UC-Piece-02: Ensure that a piece cannot move if blocked by others. + *
+ */ @Test public void testCantMove() { // TODO: Implement test logic for when a piece can't move } - // UC-Piece-03 + /** + * Tests the logic for when no possible moves are available. + *+ * Use Case UC-Piece-03: Check game behavior when a player has no valid moves. + *
+ */ @Test public void testNoPossibleMove() { // TODO: Implement test logic for when no possible moves are available } + /** + * Tests the logic for throwing a piece off the board. + *+ * Use Case UC-Piece-03: Verify conditions under which a piece can be thrown off. + *
+ */ @Test public void testThrow() { // TODO: Implement test logic for throwing a piece off the board } - // UC-Piece-04 + /** + * Tests the logic for when a piece gets thrown. + *+ * Use Case UC-Piece-04: Confirm that a thrown piece is removed from play. + *
+ */ @Test public void testGetThrown() { // TODO: Implement test logic for when a piece gets thrown } - // UC-Piece-05 + /** + * Tests the logic for a piece leaving the waiting area. + *+ * Use Case UC-Piece-05: Ensure a piece can transition from waiting to active play. + *
+ */ @Test public void testLeaveWaitingArea() { // TODO: Implement test logic for a piece leaving the waiting area } - // UC-Piece-06 + /** + * Tests the logic for a piece that must leave the starting field. + *+ * Use Case UC-Piece-06: Verify conditions requiring a piece to leave its starting position. + *
+ */ @Test public void testMustLeaveStartingField() { // TODO: Implement test logic for a piece that must leave the starting field } - // UC-Piece-07 + /** + * Tests the logic for when a piece doesn't have to leave the starting field. + *+ * Use Case UC-Piece-07: Check scenarios where a piece can stay on its starting field. + *
+ */ @Test public void testDontHaveToLeaveStartingField() { // TODO: Implement test logic for when a piece doesn't have to leave the starting field } - // UC-Piece-08 + /** + * Tests the logic for when a piece can't leave the starting field. + *+ * Use Case UC-Piece-08: Verify conditions preventing a piece from leaving its starting field. + *
+ */ @Test public void testCantLeaveStartingField() { // TODO: Implement test logic for when a piece can't leave the starting field } - // UC-Piece-09 + /** + * Tests the logic for when a piece reaches a bonus field. + *+ * Use Case UC-Piece-09: Verify the benefits applied when landing on a bonus field. + *
+ */ @Test public void testReachBonusField() { // TODO: Implement test logic for when a piece reaches a bonus field } + /** + * Tests the logic for when there are no power cards available. + *+ * Use Case UC-Piece-09: Ensure the game handles the situation with no available power cards. + *
+ */ @Test public void testNoPowerCards() { // TODO: Implement test logic for when there are no power cards available } + /** + * Tests the logic for shuffling the pile of power cards. + *+ * Use Case UC-Piece-09: Confirm that the power card deck can be shuffled correctly. + *
+ */ @Test public void testShufflePile() { // TODO: Implement test logic for shuffling the pile of power cards } - // UC-Piece-10 + /** + * Tests the logic for entering the house area. + *+ * Use Case UC-Piece-10: Verify that a piece can enter the house area according to the rules. + *
+ */ @Test public void testEnterHouse() { // TODO: Implement test logic for entering the house area } + /** + * Tests the logic to ensure a piece can only enter its own house. + *+ * Use Case UC-Piece-10: Check that a piece can only enter its designated house. + *
+ */ @Test public void testOnlyEnterOwnHouse() { // TODO: Implement test logic to ensure a piece can only enter its own house } - // UC-Piece-11 + /** + * Tests the logic for activating a piece in the home area. + *+ * Use Case UC-Piece-11: Confirm that a piece can be activated correctly in the home area. + *
+ */ @Test public void testActiveHomePiece() { // TODO: Implement test logic for activating a piece in the home area } + /** + * Tests the logic to prevent jumping over another piece in the house. + *+ * Use Case UC-Piece-11: Ensure that a piece cannot jump over another piece in the house area. + *
+ */ @Test public void testCantJumpOverFigureInHouse() { // TODO: Implement test logic to prevent jumping over another piece in the house } - // UC-Piece-12 + /** + * Tests the logic for when an active home piece is blocked. + *+ * Use Case UC-Piece-12: Verify that an active piece cannot move if blocked by another piece. + *
+ */ @Test public void testActiveHomePieceBlocked() { // TODO: Implement test logic for when an active home piece is blocked } + /** + * Tests the logic for a piece on the starting field with a shield. + *+ * Use Case UC-Piece-13: Ensure that a piece with a shield behaves correctly on the starting field. + *
+ */ @Test public void testOnStartingFieldWithShield() { // TODO: Implement test logic for a piece on the starting field with a shield } - // UC-Piece-13 + /** + * Tests the logic for attempting to throw a figure with a shield. + *+ * Use Case UC-Piece-14: Verify that a piece with a shield cannot be thrown by opponents. + *
+ */ @Test public void testThrowFigureWithShield() { // TODO: Implement test logic for attempting to throw a figure with a shield } - // UC-Piece-14 + /** + * Tests the logic for using a swap power-up. + *+ * Use Case UC-Piece-15: Confirm that a player can use a swap power-up to exchange positions. + *
+ */ @Test public void testUseSwap() { // TODO: Implement test logic for using a swap power-up } - // UC-Piece-15 + /** + * Tests the logic for using a shield power-up. + *+ * Use Case UC-Piece-16: Ensure that a player can activate a shield power-up correctly. + *
+ */ @Test public void testUseShield() { // TODO: Implement test logic for using a shield power-up } - // UC-Piece-16 + /** + * Tests the logic for when a piece loses its shield. + *+ * Use Case UC-Piece-17: Verify that the game correctly updates the status when a piece loses its shield. + *
+ */ @Test public void testLoseShield() { // TODO: Implement test logic for when a piece loses its shield } - // UC-Piece-17 + /** + * Tests the logic for a piece that has finished the game. + *+ * Use Case UC-Piece-18: Confirm that the game recognizes a piece that has completed its journey. + *
+ */ @Test public void testFinishedPiece() { // TODO: Implement test logic for a piece that has finished the game diff --git a/Projekte/mdga/model/src/test/java/pp/mdga/server/serverState/ServerStateTest.java b/Projekte/mdga/model/src/test/java/pp/mdga/server/serverState/ServerStateTest.java index f410785c..0d145dc8 100644 --- a/Projekte/mdga/model/src/test/java/pp/mdga/server/serverState/ServerStateTest.java +++ b/Projekte/mdga/model/src/test/java/pp/mdga/server/serverState/ServerStateTest.java @@ -1,14 +1,20 @@ package pp.mdga.server.serverState; -import org.junit.Before; -import org.junit.Test; +import org.junit.*; +import pp.mdga.client.gameState.AnimationState; +import pp.mdga.client.gameState.turnState.PlayPowerCardState; +import pp.mdga.game.BonusCard; +import pp.mdga.game.Color; import pp.mdga.game.Game; +import pp.mdga.game.Piece; +import pp.mdga.game.PieceState; +import pp.mdga.game.Player; import pp.mdga.message.server.ServerMessage; +import pp.mdga.message.client.*; import pp.mdga.server.*; -import pp.mdga.server.automaton.CeremonyState; -import pp.mdga.server.automaton.InterruptState; -import pp.mdga.server.automaton.LobbyState; -import pp.mdga.server.automaton.ServerAutomaton; +import pp.mdga.server.automaton.*; + +import java.util.ArrayList; import static org.junit.Assert.*; @@ -17,40 +23,62 @@ */ public class ServerStateTest { - //Todo - private ServerGameLogic logic; - private AnimationEnd animationEnd; - private ClientStartGame clientStartGame; - private DeselectTSK deselectTSK; - private ForceContinueGame forceContinueGame; - private ForceStartGame forceStartGame; - private JoinServer joinServer; - private LeaveGame leaveGame; - private LobbyNotReady lobbyNotReady; - private LobbyReady lobbyReady; - private NoPowerCard noPowerCard; - private RequestBriefing requestBriefing; - private RequestDice requestDice; - private RequestMove requestMove; - private RequestPlayCard requestPlayCard; - private SelectCard selectCard; - private SelectedPieces selectedPieces; - private SelectTSK selectTSK; - private ClientMessage[] clientMessages; + //declare game here + private Game game; - //Todo - private int from; - private int fromHost; + //declare serverGameLogic here + private ServerGameLogic serverGameLogic; - //Todo - private GameStateMachine gameStateMachine; - private TurnStateMachine turnStateMachine; - private RollDiceMachine rollDiceMachine; - private ChoosePieceStateMachine choosePieceStateMachine; - private ServerAutomaton serverAutomaton; + //declare client-messages here + private AnimationEndMessage animationEnd; + private DeselectTSKMessage deselectTSK; + private DisconnectedMessage disconnected; + private ForceContinueGameMessage forceContinueGame; + private JoinServerMessage joinServer; + private LeaveGameMessage leaveGame; + private LobbyNotReadyMessage lobbyNotReady; + private LobbyReadyMessage lobbyReady; + private NoPowerCardMessage noPowerCard; + private RequestBriefingMessage requestBriefing; + private RequestDieMessage requestDie; + private RequestMoveMessage requestMove; + private RequestPlayCardMessage requestPlayCard; + private SelectCardMessage selectCard; + private SelectedPiecesMessage selectedPieces; + private SelectTSKMessage selectTSK; + private StartGameMessage startGame; - //TODO - private Animation animation; + + //TODO declare two players + + private Player playerHost; + private int IDPlayerHost; + private Color playerHostColor; + + private Player playerClient; + private int IDPlayerClient; + private Color playerClientColor; + + //declare a movable piece for client + + private Piece piece; + private PieceState pieceState; + private int IDPiece; + + //declare 3 pieces in home from client + private Piece pieceHome1; + private int IDPiece1; + private Piece pieceHome2; + private int IDPiece2; + private Piece pieceHome3; + private int IDPiece3; + + //todo declare a card for client + private BonusCard bonusCardClient; + + + //TODO declare the states here + private AnimationState animation; private CeremonyState ceremonyState; private ChoosePieceState choosePieceState; private DetermineStartPlayerState determineStartPlayerState; @@ -61,95 +89,116 @@ public class ServerStateTest { private MovePieceState movePieceState; private NoPieceState noPiece; private NoTurnState noTurnState; - private PlayPowerCard playPowerCard; + private PlayPowerCardState playPowerCard; private PowerCardState powerCardState; private RollDiceState rollDiceState; private SecondRollState secondRoll; private SelectPieceState selectPiece; - private StartPieceState startPiece; + private StartPieceState startPieceState; private ThirdRollState thirdRoll; private TurnState turnState; private WaitingPieceState waitingPiece; /** - * TODO + * this method is used to initialize the attributes of this test-class */ @Before public void setUp() { - logic = new ServerGameLogic(new Game(), new ServerSender() { + game = new Game(); + game.setActiveColor(playerClientColor); + + serverGameLogic = new ServerGameLogic(new ServerSender() { @Override - public void send(int id, ServerMessage msg) { + public void send(int id, ServerMessage message) { } - }); - animationEnd = new AnimationEnd(); - clientStartGame = new ClientStartGame(); - deselectTSK = new DeselectTSK(); - forceContinueGame = new ForceContinueGame(); - forceStartGame = new ForceStartGame(); - joinServer = new JoinServer(); - leaveGame = new LeaveGame(); - lobbyReady = new LobbyReady(); - noPowerCard = new NoPowerCard(); - requestBriefing = new RequestBriefing(); - requestDice = new RequestDice(); - requestMove = new RequestMove(); - requestPlayCard = new RequestPlayCard(); - selectCard = new SelectCard(); - selectedPieces = new SelectedPieces(); - selectTSK = new SelectTSK(); - clientMessages = new ClientMessage[]{ - animationEnd, - clientStartGame, - deselectTSK, - forceContinueGame, - forceStartGame, - joinServer, - leaveGame, - lobbyReady, - noPowerCard, - requestBriefing, - requestDice, - requestMove, - requestPlayCard, - selectCard, - selectedPieces, - selectTSK - }; - from = 1234; - fromHost = 2345; - choosePieceStateMachine = choosePieceState.getChoosePieceMachine(); - rollDiceMachine = rollDiceState.getRollDicemachine(); - turnStateMachine = turnState.getTurnStatemachine(); - serverAutomaton = logic.getServerAutomaton(); - gameStateMachine = gameState.getGameStatemachine(); + @Override + public void broadcast(ServerMessage message) { - thirdRoll = new ThirdRollState(rollDiceMachine, logic); - secondRoll = new SecondRollState(rollDiceMachine, logic); - firstRollState = new FirstRollStateState(rollDiceMachine, logic); + } + }, game); - noPiece = new NoPieceState(choosePieceStateMachine, logic); - noTurnState = new NoTurnState(choosePieceStateMachine, logic); - waitingPiece = new WaitingPieceState(choosePieceStateMachine, logic); - startPiece = new StartPieceState(choosePieceStateMachine, logic); - selectPiece = new SelectPieceState(choosePieceStateMachine, logic); + animationEnd = new AnimationEndMessage(); + deselectTSK = new DeselectTSKMessage(playerClientColor); + disconnected = new DisconnectedMessage(); + forceContinueGame = new ForceContinueGameMessage(); + joinServer = new JoinServerMessage(); + leaveGame = new LeaveGameMessage(); + lobbyNotReady = new LobbyNotReadyMessage(); + lobbyReady = new LobbyReadyMessage(); + noPowerCard = new NoPowerCardMessage(); + requestBriefing = new RequestBriefingMessage(); + requestDie = new RequestDieMessage(); + requestMove = new RequestMoveMessage(IDPiece); + requestPlayCard = RequestPlayCardMessage.requestPlayShield(bonusCardClient); //TODO + selectCard = new SelectCardMessage(); //TODO + selectedPieces = new SelectedPiecesMessage(); + selectTSK = new SelectTSKMessage(); + startGame = new StartGameMessage(); - powerCardState = new PowerCardState(turnStateMachine, logic); - playPowerCard = new PlayPowerCard(turnStateMachine, logic); - rollDiceState = new RollDiceState(turnStateMachine, logic); - choosePieceState = new ChoosePieceState(turnStateMachine, logic); - movePieceState = new MovePieceState(turnStateMachine, logic); - determineStartPlayerState = new DetermineStartPlayerState(gameStateMachine, logic); - turnState = new TurnState(gameStateMachine, logic); - animation = new Animation(gameStateMachine, logic); + //initialize the states here + thirdRoll = rollDiceState.getThirdRollState(); + secondRoll = rollDiceState.getSecondRollState(); + firstRollState = rollDiceState.getThirdRollState(); + + noPiece = choosePieceState.getNoPieceState(); + noTurnState = choosePieceState.getNoTurnState(); + waitingPiece = choosePieceState.getWaitingPieceState(); + startPieceState = choosePieceState.getStartPieceState(); + selectPiece =choosePieceState.getSelectPieceState(); + + powerCardState = turnState.getPowerCardState(); + playPowerCard = turnState.getPlayPowerCardState(); + rollDiceState = turnState.getRollDiceState(); + choosePieceState = turnState.getChoosePieceState(); + movePieceState = turnState.getMovePieceState(); + + determineStartPlayerState = gameState.getDetermineStartPlayerState(); + turnState = gameState.getTurnState(); + animation = gameState.getAnimationState(); + + lobbyState = (LobbyState) serverGameLogic.getLobbyState(); + gameState = (GameState) serverGameLogic.getGameState(); + ceremonyState = (CeremonyState) serverGameLogic.getCeremonyState(); + interruptState = (InterruptState) serverGameLogic.getInterruptState(); + + //initialize two players + playerHost = new Player("Host"); + IDPlayerHost = 1; + playerHostColor = Color.CYBER; + playerHost.setColor(playerHostColor); + game.addPlayer(IDPlayerHost,playerHost); + + playerClient = new Player("Client"); + IDPlayerClient = 2; + playerClientColor = Color.ARMY; + playerClient.setColor(playerClientColor); + playerClient.addHandCards(bonusCardClient); + game.addPlayer(IDPlayerClient,playerClient); //TODO random uuid + + //initialize a piece for client + IDPiece = 3; + pieceState = PieceState.ACTIVE; + piece = new Piece(playerClientColor,pieceState,IDPiece); + game.getBoard().setPieceOnBoard(15,piece); //sets the piece at inx 12, bc the home begins after inx 19 + + //initialize the other 3 House-Pieces + IDPiece1 =4; + IDPiece2 =5; + IDPiece3 =6; + pieceHome1 = new Piece(playerClientColor,PieceState.HOMEFINISHED,IDPiece1); + pieceHome2 = new Piece(playerClientColor,PieceState.HOMEFINISHED,IDPiece2); + pieceHome3 = new Piece(playerClientColor,PieceState.HOMEFINISHED,IDPiece3); + game.getBoard().getPlayerData().get(playerClientColor).setPieceInHome(1,pieceHome1); + game.getBoard().getPlayerData().get(playerClientColor).setPieceInHome(2,pieceHome2); + game.getBoard().getPlayerData().get(playerClientColor).setPieceInHome(3,pieceHome3); + + //initialize the powerCard + bonusCardClient = BonusCard.SHIELD; - lobbyState = new LobbyState(serverAutomaton, logic); - gameState = new GameState(serverAutomaton, logic); - ceremonyState = new CeremonyState(serverAutomaton, logic); - interruptState = new InterruptState(serverAutomaton, logic, gameState); } /** @@ -157,7 +206,8 @@ public void send(int id, ServerMessage msg) { */ @Test public void testInitialStateServerState() { - assertTrue(serverAutomaton.getState() instanceof LobbyState); + //tests if the server is in lobbyState + assertEquals(serverGameLogic.getCurrentState(),lobbyState); } /** @@ -167,17 +217,47 @@ public void testInitialStateServerState() { @Test public void testLobbyToDetermineStartPlayer() { //sends the server in the lobby-state - serverAutomaton.gotoState(lobbyState); - assertTrue(serverAutomaton.getState() instanceof LobbyState); + serverGameLogic.setCurrentState(lobbyState); + assertEquals(serverGameLogic.getCurrentState(),lobbyState); - //sends the startGame message from the Host to the server - logic.received(clientStartGame, from); + //send all other messages, which dont indicate a state change + serverGameLogic.received(animationEnd, IDPlayerClient); + serverGameLogic.received(deselectTSK, IDPlayerClient); + serverGameLogic.received(disconnected, IDPlayerClient); + serverGameLogic.received(forceContinueGame, IDPlayerClient); + serverGameLogic.received(joinServer, IDPlayerClient); + //serverGameLogic.received(leaveGame, IDPlayerClient); + serverGameLogic.received(lobbyNotReady, IDPlayerClient); + serverGameLogic.received(lobbyReady, IDPlayerClient); + serverGameLogic.received(noPowerCard, IDPlayerClient); + serverGameLogic.received(requestBriefing, IDPlayerClient); + serverGameLogic.received(requestDie, IDPlayerClient); + serverGameLogic.received(requestMove, IDPlayerClient); + serverGameLogic.received(requestPlayCard, IDPlayerClient); + serverGameLogic.received(selectCard, IDPlayerClient); + serverGameLogic.received(selectedPieces, IDPlayerClient); + serverGameLogic.received(selectTSK, IDPlayerClient); + //serverGameLogic.received(startGame, IDPlayerClient); - //tests if the server iss in DSP-state - assertTrue(serverAutomaton.getState() instanceof GameState); - GameState gameState1 = (GameState) serverAutomaton.getState();//Todo erzeuge state - GameStateMachine gameStateMachine1 = gameState.getGameStateMachine(); - assertTrue(gameStateMachine1.getState() instanceof DetermineStartPlayerState); + + //tests if the server is still in the lobby-state + assertEquals(serverGameLogic.getLobbyState(),lobbyState); + + //sets both players ready + game.setAllReady(false); + + //tests if the server is still in the lobby-state + assertEquals(serverGameLogic.getLobbyState(),lobbyState); + + //sets both players ready + game.setAllReady(true); + + //sends the startGame-message IDPlayerClient the Host to the server + serverGameLogic.received(startGame, IDPlayerHost); + + //tests if the server is in DSP-state + assertEquals(serverGameLogic.getCurrentState(),gameState); + assertEquals(gameState.getCurrentState(),determineStartPlayerState); } /** @@ -186,29 +266,30 @@ public void testLobbyToDetermineStartPlayer() { @Test public void testStayInLobby() { //sends the server in the lobby-state - serverAutomaton.gotoState(lobbyState); - assertTrue(serverAutomaton.getState() instanceof LobbyState); + serverGameLogic.setCurrentState(lobbyState); + assertEquals(serverGameLogic.getCurrentState(),lobbyState); - //TODO logic gets all messages - logic.received(animationEnd, from); - logic.received(clientStartGame, from); - logic.received(deselectTSK, from); - logic.received(forceContinueGame, from); - logic.received(forceStartGame, from); - logic.received(joinServer, from); - logic.received(leaveGame, from); - logic.received(lobbyReady, from); - logic.received(noPowerCard, from); - logic.received(requestBriefing, from); - logic.received(requestDice, from); - logic.received(requestMove, from); - logic.received(requestPlayCard, from); - logic.received(selectCard, from); - logic.received(selectedPieces, from); - logic.received(selectTSK, from); + //serverGameLogic gets all messages, which dont indicate a state change + serverGameLogic.received(animationEnd, IDPlayerClient); + serverGameLogic.received(deselectTSK, IDPlayerClient); + //serverGameLogic.received(disconnected, IDPlayerClient); + serverGameLogic.received(forceContinueGame, IDPlayerClient); + serverGameLogic.received(joinServer, IDPlayerClient); + //serverGameLogic.received(leaveGame, IDPlayerClient); + serverGameLogic.received(lobbyNotReady, IDPlayerClient); + serverGameLogic.received(lobbyReady, IDPlayerClient); + serverGameLogic.received(noPowerCard, IDPlayerClient); + serverGameLogic.received(requestBriefing, IDPlayerClient); + serverGameLogic.received(requestDie, IDPlayerClient); + serverGameLogic.received(requestMove, IDPlayerClient); + serverGameLogic.received(requestPlayCard, IDPlayerClient); + serverGameLogic.received(selectCard, IDPlayerClient); + serverGameLogic.received(selectedPieces, IDPlayerClient); + serverGameLogic.received(selectTSK, IDPlayerClient); + //serverGameLogic.received(startGame, IDPlayerClient); //tests if Server is still in Lobby - assertTrue(serverAutomaton.getState() instanceof LobbyState); + assertEquals(serverGameLogic.getCurrentState(),lobbyState); } /** @@ -217,28 +298,29 @@ public void testStayInLobby() { @Test public void testServerGameSubStatesToInterrupt() { //sends the server in the gameState - serverAutomaton.gotoState(gameState); - assertTrue(serverAutomaton.getState() instanceof GameState); //TODO könnte auch auf gleichheit prüfen + serverGameLogic.setCurrentState(gameState); + assertEquals(serverGameLogic.getCurrentState(),gameState); - //TODO create interrupt + //sends the interrupt + serverGameLogic.received(disconnected,IDPlayerClient); //tests if the server is in the Interrupt-state - assertTrue(serverAutomaton.getState() instanceof InterruptState); + assertEquals(serverGameLogic.getInterruptState(),interruptState); } /** - * tests the state-change from Game to Ceremony if the Game is finished + * tests the state-change IDPlayerClient Game to Ceremony if the Game is finished */ @Test public void testServerGameToCeremony() { //sends the server in the gameState - serverAutomaton.gotoState(gameState); - assertTrue(serverAutomaton.getState() instanceof GameState); + serverGameLogic.setCurrentState(gameState); + assertEquals(serverGameLogic.getCurrentState() ,gameState); //Todo game is finished //tests if the server is in the Ceremony-state - assertTrue(serverAutomaton.getState() instanceof CeremonyState); + assertEquals(serverGameLogic.getCurrentState() ,ceremonyState); } /** @@ -247,14 +329,36 @@ public void testServerGameToCeremony() { @Test public void testInterruptToGameContinue() { //sends the server in the Interrupt-State - serverAutomaton.gotoState(interruptState); - assertTrue(serverAutomaton.getState() instanceof InterruptState); + serverGameLogic.setCurrentState(interruptState); + assertEquals(serverGameLogic.getCurrentState() ,interruptState); + + //send all other messages except forceContinue + serverGameLogic.received(animationEnd, IDPlayerClient); + serverGameLogic.received(deselectTSK, IDPlayerClient); + serverGameLogic.received(disconnected, IDPlayerClient); + //serverGameLogic.received(forceContinueGame, IDPlayerClient); + serverGameLogic.received(joinServer, IDPlayerClient); + serverGameLogic.received(leaveGame, IDPlayerClient); + serverGameLogic.received(lobbyNotReady, IDPlayerClient); + serverGameLogic.received(lobbyReady, IDPlayerClient); + serverGameLogic.received(noPowerCard, IDPlayerClient); + serverGameLogic.received(requestBriefing, IDPlayerClient); + serverGameLogic.received(requestDie, IDPlayerClient); + serverGameLogic.received(requestMove, IDPlayerClient); + serverGameLogic.received(requestPlayCard, IDPlayerClient); + serverGameLogic.received(selectCard, IDPlayerClient); + serverGameLogic.received(selectedPieces, IDPlayerClient); + serverGameLogic.received(selectTSK, IDPlayerClient); + serverGameLogic.received(startGame, IDPlayerClient); + + //tests if the server is still in Interrupt + assertEquals(serverGameLogic.getCurrentState(),interruptState); //sends the continue-message to the server - logic.received(forceContinueGame, from); + serverGameLogic.received(forceContinueGame, IDPlayerClient); //tests if new Stet is in GameState - assertTrue(serverAutomaton.getState() instanceof GameState); + assertEquals(serverGameLogic.getCurrentState() ,gameState); } /** @@ -263,13 +367,13 @@ public void testInterruptToGameContinue() { @Test public void testInterruptToGameReconnect() { //sends the server in the Interrupt-State - serverAutomaton.gotoState(interruptState); - assertTrue(serverAutomaton.getState() instanceof InterruptState); + serverGameLogic.setCurrentState(interruptState); + assertEquals(serverGameLogic.getCurrentState() ,interruptState); - //todo implement the timer + //todo implement the reconnect //tests if new Stet is in GameState - assertTrue(serverAutomaton.getState() instanceof GameState); + assertEquals(serverGameLogic.getCurrentState() ,gameState); } /** @@ -278,13 +382,13 @@ public void testInterruptToGameReconnect() { @Test public void testInterruptToGameTimer() { //sends the server in the Interrupt-State - serverAutomaton.gotoState(interruptState); - assertTrue(serverAutomaton.getState() instanceof InterruptState); + serverGameLogic.setCurrentState(interruptState); + assertEquals(serverGameLogic.getCurrentState() ,interruptState); //Todo implement the timer //tests if new Stet is in GameState - assertTrue(serverAutomaton.getState() instanceof GameState); + assertEquals(serverGameLogic.getCurrentState() ,gameState); } /** @@ -292,7 +396,11 @@ public void testInterruptToGameTimer() { */ @Test public void testCeremonyToServerStateEndState() { - // TODO: Implement test logic for transition from Ceremony to Server State End State + //sends the server in ceremony + serverGameLogic.setCurrentState(ceremonyState); + assertEquals(serverGameLogic.getCurrentState() ,ceremonyState); + + //tests if the server is closed // TODO how???? } @@ -302,18 +410,35 @@ public void testCeremonyToServerStateEndState() { @Test public void testDetermineStartPlayerToDetermineStartPlayer1() { //sends the server in Game-State - serverAutomaton.gotoState(gameState); - assertTrue(serverAutomaton.getState() instanceof GameState); + serverGameLogic.setCurrentState(gameState); + assertEquals(serverGameLogic.getCurrentState() ,gameState); - //sends the gameStateMachine in DSP-state - gameStateMachine.gotoState(determineStartPlayerState); - assertTrue(gameStateMachine.getState() instanceof DetermineStartPlayerState); + //sends the gameState in DSP-state + gameState.setCurrentState(determineStartPlayerState); + assertEquals(gameState.getCurrentState() ,determineStartPlayerState); - //TODO sends messages to the server + //sends messages to the server + serverGameLogic.received(animationEnd, IDPlayerClient); + serverGameLogic.received(deselectTSK, IDPlayerClient); + //serverGameLogic.received(disconnected, IDPlayerClient); + serverGameLogic.received(forceContinueGame, IDPlayerClient); + serverGameLogic.received(joinServer, IDPlayerClient); + //serverGameLogic.received(leaveGame, IDPlayerClient); + serverGameLogic.received(lobbyNotReady, IDPlayerClient); + serverGameLogic.received(lobbyReady, IDPlayerClient); + serverGameLogic.received(noPowerCard, IDPlayerClient); + serverGameLogic.received(requestBriefing, IDPlayerClient); + serverGameLogic.received(requestDie, IDPlayerClient); + serverGameLogic.received(requestMove, IDPlayerClient); + serverGameLogic.received(requestPlayCard, IDPlayerClient); + serverGameLogic.received(selectCard, IDPlayerClient); + serverGameLogic.received(selectedPieces, IDPlayerClient); + serverGameLogic.received(selectTSK, IDPlayerClient); + serverGameLogic.received(startGame, IDPlayerClient); //tests if the server is still in DSP-state - assertTrue(serverAutomaton.getState() instanceof GameState); - assertTrue(gameStateMachine.getState() instanceof DetermineStartPlayerState); + assertEquals(serverGameLogic.getCurrentState() ,gameState); + assertEquals(gameState.getCurrentState() ,determineStartPlayerState); } /** @@ -322,18 +447,27 @@ public void testDetermineStartPlayerToDetermineStartPlayer1() { @Test public void testDetermineStartPlayerToDetermineStartPlayer2() { //sends the server in Game-State - serverAutomaton.gotoState(gameState); - assertTrue(serverAutomaton.getState() instanceof GameState); + serverGameLogic.setCurrentState(gameState); + assertEquals(serverGameLogic.getCurrentState() ,gameState); - //sends the gameStateMachine in DSP-state - gameStateMachine.gotoState(determineStartPlayerState); - assertTrue(gameStateMachine.getState() instanceof DetermineStartPlayerState); + //sends the gameState in DSP-state + gameState.setCurrentState(determineStartPlayerState); + assertEquals(gameState.getCurrentState() ,determineStartPlayerState); - //TODO sends messages 2 RequestDiceMessage, die gleich geränkt werden to the server + //TODO sends messages 2 requestDieMessage, die gleich geränkt werden to the server + //sends the requestDieMessage to the server + gameState.received(requestDie, IDPlayerClient); //tests if the server is still in DSP-state - assertTrue(serverAutomaton.getState() instanceof GameState); - assertTrue(gameStateMachine.getState() instanceof DetermineStartPlayerState); + assertEquals(serverGameLogic.getCurrentState() ,gameState); + assertEquals(gameState.getCurrentState() ,determineStartPlayerState); + + //sends the requestDieMessage to the server + gameState.received(requestMove, IDPlayerClient); + + //tests if the server is still in DSP-state + assertEquals(serverGameLogic.getCurrentState() ,gameState); + assertEquals(gameState.getCurrentState() ,determineStartPlayerState); } /** @@ -342,89 +476,103 @@ public void testDetermineStartPlayerToDetermineStartPlayer2() { @Test public void testDetermineStartPlayerToAnimation() { //sends the server in Game-State - serverAutomaton.gotoState(gameState); - assertTrue(serverAutomaton.getState() instanceof GameState); + serverGameLogic.setCurrentState(gameState); + assertEquals(serverGameLogic.getCurrentState() ,gameState); - //sends the gameStateMachine in DSP-state - gameStateMachine.gotoState(determineStartPlayerState); - assertTrue(gameStateMachine.getState() instanceof DetermineStartPlayerState); + //sends the gameState in DSP-state + gameState.setCurrentState(determineStartPlayerState); + assertEquals(gameState.getCurrentState() ,determineStartPlayerState); - //TODO sends messages 2 RequestDiceMessage, die ungleich geränkt werden, sodass der server weitergeht + //TODO sends messages 2 requestDieMessage, die ungleich geränkt werden, sodass der server weitergeht //tests if the Server is in animationState - assertTrue(serverAutomaton.getState() instanceof GameState); - assertTrue(gameStateMachine.getState() instanceof Animation); + assertEquals(serverGameLogic.getCurrentState() ,gameState); + assertEquals(gameState.getCurrentState() ,animation); } /** - * tests that the server goes from the animation-state into PowerCardState, if the animation in the client has ended + * tests that the server goes IDPlayerClient the animation-state into PowerCardState, if the animation in the client has ended * and all players have issued a animationEndMessage */ @Test public void testAnimationToPowerCard() { //sends the server in Game-State - serverAutomaton.gotoState(gameState); - assertTrue(serverAutomaton.getState() instanceof GameState); + serverGameLogic.setCurrentState(gameState); + assertEquals(serverGameLogic.getCurrentState() ,gameState); - //sends the gameStateMachine in Animation - gameStateMachine.gotoState(animation); - assertTrue(gameStateMachine.getState() instanceof Animation); + //sends the gameState in Animation + gameState.setCurrentState(animation); + assertEquals(gameState.getCurrentState() ,animation); //receives one animation endMessage and tests if the server is still in the Animation-state - logic.received(animationEnd, fromHost); - assertTrue(serverAutomaton.getState() instanceof GameState); - assertTrue(gameStateMachine.getState() instanceof Animation); + serverGameLogic.received(animationEnd, IDPlayerClient); + assertEquals(serverGameLogic.getCurrentState() ,gameState); + assertEquals(gameState.getCurrentState() ,animation); //receives another animation endMessage - logic.received(animationEnd, from); + serverGameLogic.received(animationEnd, IDPlayerClient); //tests if the server is in the PowerCard-state - assertTrue(serverAutomaton.getState() instanceof GameState); - assertTrue(gameStateMachine.getState() instanceof TurnState); - TurnState turnState1 = (TurnState) gameStateMachine.getState(); - TurnStateMachine turnStateMachine = (TurnStateMachine) turnState1.getTurnStateMachine(); - assertTrue(turnStateMachine.getState() instanceof PowerCardState); + assertEquals(serverGameLogic.getCurrentState() ,gameState); + assertEquals(gameState.getCurrentState() ,turnState); + assertEquals(turnState.getCurrentState() ,powerCardState); } /** - * this method tests that the server changes it's state from the turn-state to the animation-state, if there are at + * this method tests that the server changes it's state IDPlayerClient the turn-state to the animation-state, if there are at * least two player left */ @Test public void testTurnToAnimation() { //sends the server in Game-State - serverAutomaton.gotoState(gameState); - assertTrue(serverAutomaton.getState() instanceof GameState); + serverGameLogic.setCurrentState(gameState); + assertEquals(serverGameLogic.getCurrentState() ,gameState); - //sends the gameStateMachine in Turn - gameStateMachine.gotoState(turnState); - assertTrue(gameStateMachine.getState() instanceof TurnState); + //sends the gameState in Turn + gameState.setCurrentState(turnState); + assertEquals(gameState.getCurrentState() ,turnState); - //todo set the turn finished and there are still two players left + //sends the server in Animation + turnState.setCurrentState(animation); + assertEquals(turnState.getState(),animation); + + //set dices-eyes in game !=6 + game.setDiceEyes(4); + + //serverGameLogic receives animationEndMessages + serverGameLogic.received(animationEnd, IDPlayerClient); + + //tests if the server is still in Animation-State + assertEquals(serverGameLogic.getCurrentState() ,gameState); + assertEquals(gameState.getCurrentState() ,turnState); + assertEquals(turnState.getState(),animation); + + //sends the second animationEndMessage + serverGameLogic.received(animationEnd, IDPlayerHost); //tests if the server is in the AnimationState - assertTrue(serverAutomaton.getState() instanceof GameState); - assertTrue(gameStateMachine.getState() instanceof Animation); + assertEquals(serverGameLogic.getCurrentState() ,gameState); + assertEquals(gameState.getCurrentState() ,animation); } /** - * this method tests that the server changes it's state from the turn-state to the ceremony-state, + * this method tests that the server changes it's state IDPlayerClient the turn-state to the ceremony-state, * if there is only one player left */ @Test public void testTurnToGameEndState() { //sends the server in Game-State - serverAutomaton.gotoState(gameState); - assertTrue(serverAutomaton.getState() instanceof GameState); + serverGameLogic.setCurrentState(gameState); + assertEquals(serverGameLogic.getCurrentState() ,gameState); - //sends the gameStateMachine in Turn - gameStateMachine.gotoState(turnState); - assertTrue(gameStateMachine.getState() instanceof TurnState); + //sends the gameState in Turn + gameState.setCurrentState(turnState); + assertEquals(gameState.getCurrentState() ,turnState); //todo set the turn finished and there is only one players left //tests if the server is in the end-state of game, Ceremony - assertTrue(serverAutomaton.getState() instanceof CeremonyState); + assertEquals(serverGameLogic.getCurrentState() ,ceremonyState); } /** @@ -434,129 +582,144 @@ public void testTurnToGameEndState() { @Test public void testStayInPowerCard() { //sends the server in Game-State - serverAutomaton.gotoState(gameState); - assertTrue(serverAutomaton.getState() instanceof GameState); + serverGameLogic.setCurrentState(gameState); + assertEquals(serverGameLogic.getCurrentState() ,gameState); - //sends the gameStateMachine in Turn - gameStateMachine.gotoState(turnState); - assertTrue(gameStateMachine.getState() instanceof TurnState); + //sends the gameState in Turn + gameState.setCurrentState(turnState); + assertEquals(gameState.getCurrentState() ,turnState); - //sends the TurnStateMachine in PowerCard - turnStateMachine.gotoState(powerCardState); - assertTrue(turnStateMachine.getState() instanceof PowerCardState); + //sends the TurnState in PowerCard + turnState.setCurrentState(powerCardState); + assertEquals(turnState.getCurrentState() ,powerCardState); - //Todo: receive messages which dont lead to a state change + //receive messages which don't lead to a state change todo + serverGameLogic.received(animationEnd, IDPlayerClient); + serverGameLogic.received(deselectTSK, IDPlayerClient); + //serverGameLogic.received(disconnected, IDPlayerClient); + serverGameLogic.received(forceContinueGame, IDPlayerClient); + serverGameLogic.received(joinServer, IDPlayerClient); + serverGameLogic.received(leaveGame, IDPlayerClient); + serverGameLogic.received(lobbyNotReady, IDPlayerClient); + serverGameLogic.received(lobbyReady, IDPlayerClient); + serverGameLogic.received(noPowerCard, IDPlayerClient); + serverGameLogic.received(requestBriefing, IDPlayerClient); + serverGameLogic.received(requestDie, IDPlayerClient); + serverGameLogic.received(requestMove, IDPlayerClient); + serverGameLogic.received(requestPlayCard, IDPlayerClient); + serverGameLogic.received(selectCard, IDPlayerClient); + //serverGameLogic.received(selectedPieces, IDPlayerClient); + serverGameLogic.received(selectTSK, IDPlayerClient); + serverGameLogic.received(startGame, IDPlayerClient); //tests if the server is in PowerCard - assertTrue(serverAutomaton.getState() instanceof GameState); - assertTrue(gameStateMachine.getState() instanceof TurnState); - assertTrue(turnStateMachine.getState() instanceof PowerCardState); + assertEquals(serverGameLogic.getCurrentState() ,gameState); + assertEquals(gameState.getCurrentState() ,turnState); + assertEquals(turnState.getCurrentState() ,powerCardState); } /** - * Tests the transition from PowerCard state to PlayPowerCard state. + * Tests the transition IDPlayerClient PowerCard state to PlayPowerCard state. * UC-ServerState-17 */ @Test public void testPowerCardToPlayPowerCard() { //sends the server in Game-State - serverAutomaton.gotoState(gameState); - assertTrue(serverAutomaton.getState() instanceof GameState); + serverGameLogic.setCurrentState(gameState); + assertEquals(serverGameLogic.getCurrentState() ,gameState); - //sends the gameStateMachine in Turn - gameStateMachine.gotoState(turnState); - assertTrue(gameStateMachine.getState() instanceof TurnState); + //sends the gameState in Turn + gameState.setCurrentState(turnState); + assertEquals(gameState.getCurrentState() ,turnState); - //sends the TurnStateMachine in PowerCard - turnStateMachine.gotoState(powerCardState); - assertTrue(turnStateMachine.getState() instanceof PowerCardState); + //sends the TurnState in PowerCard + turnState.setCurrentState(powerCardState); + assertEquals(turnState.getCurrentState() ,powerCardState); //todo //tests if the server is in PlayPowerCard - assertTrue(serverAutomaton.getState() instanceof GameState); - assertTrue(gameStateMachine.getState() instanceof TurnState); - assertTrue(turnStateMachine.getState() instanceof PlayPowerCard); + assertEquals(serverGameLogic.getCurrentState() ,gameState); + assertEquals(gameState.getCurrentState() ,turnState); + assertEquals(turnState.getCurrentState() ,playPowerCard); } /** - * Tests the transition from PlayPowerCard state to RollDice state. + * Tests the transition IDPlayerClient PlayPowerCard state to RollDice state. * UC-ServerState-18 */ @Test public void testPlayPowerCardToRollDice() { //sends the server in Game-State - serverAutomaton.gotoState(gameState); - assertTrue(serverAutomaton.getState() instanceof GameState); + serverGameLogic.setCurrentState(gameState); + assertEquals(serverGameLogic.getCurrentState() ,gameState); - //sends the gameStateMachine in Turn - gameStateMachine.gotoState(turnState); - assertTrue(gameStateMachine.getState() instanceof TurnState); + //sends the gameState in Turn + gameState.setCurrentState(turnState); + assertEquals(gameState.getCurrentState() ,turnState); - //sends the TurnStateMachine in PowerCard - turnStateMachine.gotoState(playPowerCard); - assertTrue(turnStateMachine.getState() instanceof PlayPowerCard); + //sends the TurnState in PowerCard + turnState.setCurrentState(playPowerCard); + assertEquals(turnState.getCurrentState() ,playPowerCard); - //receive first AnimationEndMessage from the host - logic.received(animationEnd, fromHost); - assertTrue(serverAutomaton.getState() instanceof GameState); - assertTrue(gameStateMachine.getState() instanceof TurnState); - assertTrue(turnStateMachine.getState() instanceof PlayPowerCard); + //receive first AnimationEndMessage IDPlayerClient the host + serverGameLogic.received(animationEnd, IDPlayerClient); + assertEquals(serverGameLogic.getCurrentState() ,gameState); + assertEquals(gameState.getCurrentState() ,turnState); + assertEquals(turnState.getCurrentState() ,playPowerCard); //receive second AnimationEndMessage - logic.received(animationEnd, from); + serverGameLogic.received(animationEnd, IDPlayerClient); //tests if the server is in RollDice and in FirstRoll - assertTrue(serverAutomaton.getState() instanceof GameState); - assertTrue(gameStateMachine.getState() instanceof TurnState); - assertTrue(turnStateMachine.getState() instanceof RollDiceState); - RollDiceState rollDiceState = (RollDiceState) turnStateMachine.getState(); - RollDiceMachine rollDiceMachine1 = rollDiceState.getRollDiceStateMachine(); - assertTrue(rollDiceMachine1.getState() instanceof FirstRollStateState); + assertEquals(serverGameLogic.getCurrentState() ,gameState); + assertEquals(gameState.getCurrentState() ,turnState); + assertEquals(turnState.getCurrentState() ,rollDiceState); + assertEquals(rollDiceState.getCurrentState() ,firstRollState); } /** - * Tests the transition from ChoosePiece state to MovePiece state. + * Tests the transition IDPlayerClient ChoosePiece state to MovePiece state. * UC-ServerState-19 */ @Test public void testChoosePieceToMovePiece() { //sends the server in Game-State - serverAutomaton.gotoState(gameState); - assertTrue(serverAutomaton.getState() instanceof GameState); + serverGameLogic.setCurrentState(gameState); + assertEquals(serverGameLogic.getCurrentState() ,gameState); - //sends the gameStateMachine in Turn - gameStateMachine.gotoState(turnState); - assertTrue(gameStateMachine.getState() instanceof TurnState); + //sends the gameState in Turn + gameState.setCurrentState(turnState); + assertEquals(gameState.getCurrentState() ,turnState); - //sends the TurnStateMachine in ChoosePiece - turnStateMachine.gotoState(choosePieceState); - assertTrue(turnStateMachine.getState() instanceof ChoosePieceState); + //sends the TurnState in ChoosePiece + turnState.setCurrentState(choosePieceState); + assertEquals(turnState.getCurrentState() ,choosePieceState); //Todo ??? - assertTrue(serverAutomaton.getState() instanceof GameState); - assertTrue(gameStateMachine.getState() instanceof TurnState); - assertTrue(turnStateMachine.getState() instanceof MovePieceState); + assertEquals(serverGameLogic.getCurrentState() ,gameState); + assertEquals(gameState.getCurrentState() ,turnState); + assertEquals(turnState.getCurrentState() ,movePieceState); } /** - * Tests the transition from MovePiece state to TurnEndState. + * Tests the transition IDPlayerClient MovePiece state to TurnEndState. * UC-ServerState-20 */ @Test public void testMovePieceToTurnEndState() { //sends the server in Game-State - serverAutomaton.gotoState(gameState); - assertTrue(serverAutomaton.getState() instanceof GameState); + serverGameLogic.setCurrentState(gameState); + assertEquals(serverGameLogic.getCurrentState() ,gameState); - //sends the gameStateMachine in Turn - gameStateMachine.gotoState(turnState); - assertTrue(gameStateMachine.getState() instanceof TurnState); + //sends the gameState in Turn + gameState.setCurrentState(turnState); + assertEquals(gameState.getCurrentState() ,turnState); - //sends the TurnStateMachine in MovePiece - turnStateMachine.gotoState(movePieceState); - assertTrue(turnStateMachine.getState() instanceof MovePieceState); + //sends the TurnState in MovePiece + turnState.setCurrentState(movePieceState); + assertEquals(turnState.getCurrentState() ,movePieceState); //Todo no 6 was rolled, so the server looks, if there are 2 or less player are still in the game //TODO @@ -564,303 +727,295 @@ public void testMovePieceToTurnEndState() { } /** - * Tests the transition from MovePiece state to FirstRoll state. + * Tests the transition IDPlayerClient MovePiece state to FirstRoll state. * UC-ServerState-21 */ @Test public void testMovePieceToFirstRoll() { //sends the server in Game-State - serverAutomaton.gotoState(gameState); - assertTrue(serverAutomaton.getState() instanceof GameState); + serverGameLogic.setCurrentState(gameState); + assertEquals(serverGameLogic.getCurrentState() ,gameState); - //sends the gameStateMachine in Turn - gameStateMachine.gotoState(turnState); - assertTrue(gameStateMachine.getState() instanceof TurnState); + //sends the gameState in Turn + gameState.setCurrentState(turnState); + assertEquals(gameState.getCurrentState() ,turnState); - //sends the TurnStateMachine in MovePiece - turnStateMachine.gotoState(movePieceState); - assertTrue(turnStateMachine.getState() instanceof MovePieceState); + //sends the TurnState in MovePiece + turnState.setCurrentState(movePieceState); + assertEquals(turnState.getCurrentState() ,movePieceState); //Todo the player rolled a 6 and the player is not finished - assertTrue(serverAutomaton.getState() instanceof GameState); - assertTrue(gameStateMachine.getState() instanceof TurnState); - assertTrue(turnStateMachine.getState() instanceof RollDiceState); - RollDiceState rollDiceState = (RollDiceState) turnStateMachine.getState(); - RollDiceMachine rollDiceMachine1 = rollDiceState.getRollDiceStateMachine(); - assertTrue(rollDiceMachine1.getState() instanceof FirstRollStateState); + assertEquals(serverGameLogic.getCurrentState() ,gameState); + assertEquals(gameState.getCurrentState() ,turnState); + assertEquals(turnState.getCurrentState() ,rollDiceState); + assertEquals(rollDiceState.getCurrentState() ,firstRollState); } /** - * Tests the transition from FirstRoll state to RollDiceEndState. + * Tests the transition IDPlayerClient FirstRoll state to RollDiceEndState. * UC-ServerState-22 */ @Test public void testFirstRollToRollDiceEndState() { //sends the server in Game-State - serverAutomaton.gotoState(gameState); - assertTrue(serverAutomaton.getState() instanceof GameState); + serverGameLogic.setCurrentState(gameState); + assertEquals(serverGameLogic.getCurrentState() ,gameState); - //sends the gameStateMachine in Turn - gameStateMachine.gotoState(turnState); - assertTrue(gameStateMachine.getState() instanceof TurnState); + //sends the gameState in Turn + gameState.setCurrentState(turnState); + assertEquals(gameState.getCurrentState() ,turnState); - //sends the TurnStateMachine in RollDice - turnStateMachine.gotoState(rollDiceState); - assertTrue(turnStateMachine.getState() instanceof RollDiceState); + //sends the TurnState in RollDice + turnState.setCurrentState(rollDiceState); + assertEquals(turnState.getCurrentState() ,rollDiceState); - //sends the RollDiceMachine in FirstRoll - rollDiceMachine.gotoState(firstRollState); - assertTrue(rollDiceMachine.getState() instanceof FirstRollStateState); + //sends the RollDiceState in FirstRoll + rollDiceState.setCurrentState(firstRollState); + assertEquals(rollDiceState.getCurrentState() ,firstRollState); //TODO 2 Möglichkeiten //tests if the server is in NoPiece of ChoosePiece - assertTrue(serverAutomaton.getState() instanceof GameState); - assertTrue(gameStateMachine.getState() instanceof TurnState); - assertTrue(turnStateMachine.getState() instanceof ChoosePieceState); - ChoosePieceState choosePieceState1 = (ChoosePieceState) turnStateMachine.getState(); - ChoosePieceStateMachine choosePieceStateMachine = choosePieceState1.getChoosePieceStateMachine(); - assertTrue(choosePieceStateMachine.getState() instanceof NoPieceState); + assertEquals(serverGameLogic.getCurrentState() ,gameState); + assertEquals(gameState.getCurrentState() ,turnState); + assertEquals(turnState.getCurrentState() ,choosePieceState); + assertEquals(choosePieceState.getCurrentState() ,noPieceState); } /** - * Tests the transition from FirstRoll state to SecondRoll state. + * Tests the transition IDPlayerClient FirstRoll state to SecondRoll state. * UC-ServerState-23 */ @Test public void testFirstRollToSecondRoll() { //sends the server in Game-State - serverAutomaton.gotoState(gameState); - assertTrue(serverAutomaton.getState() instanceof GameState); + serverGameLogic.setCurrentState(gameState); + assertEquals(serverGameLogic.getCurrentState() ,gameState); - //sends the gameStateMachine in Turn - gameStateMachine.gotoState(turnState); - assertTrue(gameStateMachine.getState() instanceof TurnState); + //sends the gameState in Turn + gameState.setCurrentState(turnState); + assertEquals(gameState.getCurrentState() ,turnState); - //sends the TurnStateMachine in RollDice - turnStateMachine.gotoState(rollDiceState); - assertTrue(turnStateMachine.getState() instanceof RollDiceState); + //sends the TurnState in RollDice + turnState.setCurrentState(rollDiceState); + assertEquals(turnState.getCurrentState() ,rollDiceState); - //sends the RollDiceMachine in FirstRoll - rollDiceMachine.gotoState(firstRollState); - assertTrue(rollDiceMachine.getState() instanceof FirstRollStateState); + //sends the RollDiceState in FirstRoll + rollDiceState.setCurrentState(firstRollState); + assertEquals(rollDiceState.getCurrentState() ,firstRollState); //Todo player has no figures to move and had no 6 //tests if the server is in the SecondRoll - assertTrue(serverAutomaton.getState() instanceof GameState); - assertTrue(gameStateMachine.getState() instanceof TurnState); - assertTrue(turnStateMachine.getState() instanceof RollDiceState); - assertTrue(rollDiceMachine.getState() instanceof SecondRollState); + assertEquals(serverGameLogic.getCurrentState() ,gameState); + assertEquals(gameState.getCurrentState() ,turnState); + assertEquals(turnState.getCurrentState() ,rollDiceState); + assertEquals(rollDiceState.getCurrentState() ,secondRollState); } /** - * Tests the transition from SecondRoll state to RollDiceEndState. + * Tests the transition IDPlayerClient SecondRoll state to RollDiceEndState. * UC-ServerState-24 */ @Test public void testSecondRollToRollDiceEndState() { //sends the server in Game-State - serverAutomaton.gotoState(gameState); - assertTrue(serverAutomaton.getState() instanceof GameState); + serverGameLogic.setCurrentState(gameState); + assertEquals(serverGameLogic.getCurrentState() ,gameState); - //sends the gameStateMachine in Turn - gameStateMachine.gotoState(turnState); - assertTrue(gameStateMachine.getState() instanceof TurnState); + //sends the gameState in Turn + gameState.setCurrentState(turnState); + assertEquals(gameState.getCurrentState() ,turnState); - //sends the TurnStateMachine in RollDice - turnStateMachine.gotoState(rollDiceState); - assertTrue(turnStateMachine.getState() instanceof RollDiceState); + //sends the TurnState in RollDice + turnState.setCurrentState(rollDiceState); + assertEquals(turnState.getCurrentState() ,rollDiceState); - //sends the RollDiceMachine in SecondRoll - rollDiceMachine.gotoState(secondRoll); - assertTrue(rollDiceMachine.getState() instanceof SecondRollState); + //sends the RollDiceState in SecondRoll + rollDiceState.setCurrentState(secondRoll); + assertEquals(rollDiceState.getCurrentState() ,secondRollState); //Todo //tests if the server is in NoPiece of ChoosePiece - assertTrue(serverAutomaton.getState() instanceof GameState); - assertTrue(gameStateMachine.getState() instanceof TurnState); - assertTrue(turnStateMachine.getState() instanceof ChoosePieceState); - ChoosePieceState choosePieceState1 = (ChoosePieceState) turnStateMachine.getState(); - ChoosePieceStateMachine choosePieceStateMachine = choosePieceState1.getChoosePieceStateMachine(); - assertTrue(choosePieceStateMachine.getState() instanceof NoPieceState); + assertEquals(serverGameLogic.getCurrentState() ,gameState); + assertEquals(gameState.getCurrentState() ,turnState); + assertEquals(turnState.getCurrentState() ,choosePieceState); + assertEquals(choosePieceState.getCurrentState() ,noPieceState); } /** - * Tests the transition from SecondRoll state to ThirdRoll state. + * Tests the transition IDPlayerClient SecondRoll state to ThirdRoll state. * UC-ServerState-25 */ @Test public void testSecondRollToThirdRoll() { //sends the server in Game-State - serverAutomaton.gotoState(gameState); - assertTrue(serverAutomaton.getState() instanceof GameState); + serverGameLogic.setCurrentState(gameState); + assertEquals(serverGameLogic.getCurrentState() ,gameState); - //sends the gameStateMachine in Turn - gameStateMachine.gotoState(turnState); - assertTrue(gameStateMachine.getState() instanceof TurnState); + //sends the gameState in Turn + gameState.setCurrentState(turnState); + assertEquals(gameState.getCurrentState() ,turnState); - //sends the TurnStateMachine in RollDice - turnStateMachine.gotoState(rollDiceState); - assertTrue(turnStateMachine.getState() instanceof RollDiceState); + //sends the TurnState in RollDice + turnState.setCurrentState(rollDiceState); + assertEquals(turnState.getCurrentState() ,rollDiceState); - //sends the RollDiceMachine in SecondRoll - rollDiceMachine.gotoState(secondRoll); - assertTrue(rollDiceMachine.getState() instanceof SecondRollState); + //sends the RollDiceState in SecondRoll + rollDiceState.setCurrentState(secondRoll); + assertEquals(rollDiceState.getCurrentState() ,secondRollState); //Todo player has no figures to move and had no 6 //tests if the server is in the ThirdRoll - assertTrue(serverAutomaton.getState() instanceof GameState); - assertTrue(gameStateMachine.getState() instanceof TurnState); - assertTrue(turnStateMachine.getState() instanceof RollDiceState); - assertTrue(rollDiceMachine.getState() instanceof ThirdRollState); + assertEquals(serverGameLogic.getCurrentState() ,gameState); + assertEquals(gameState.getCurrentState() ,turnState); + assertEquals(turnState.getCurrentState() ,rollDiceState); + assertEquals(rollDiceState.getCurrentState() ,thirdRollState); } /** - * Tests the transition from ThirdRoll state to RollDiceEndState. + * Tests the transition IDPlayerClient ThirdRoll state to RollDiceEndState. * UC-ServerState-26 */ @Test public void testThirdRollToRollDiceEndState() { //sends the server in Game-State - serverAutomaton.gotoState(gameState); - assertTrue(serverAutomaton.getState() instanceof GameState); + serverGameLogic.setCurrentState(gameState); + assertEquals(serverGameLogic.getCurrentState() ,gameState); - //sends the gameStateMachine in Turn - gameStateMachine.gotoState(turnState); - assertTrue(gameStateMachine.getState() instanceof TurnState); + //sends the gameState in Turn + gameState.setCurrentState(turnState); + assertEquals(gameState.getCurrentState() ,turnState); - //sends the TurnStateMachine in RollDice - turnStateMachine.gotoState(rollDiceState); - assertTrue(turnStateMachine.getState() instanceof RollDiceState); + //sends the TurnState in RollDice + turnState.setCurrentState(rollDiceState); + assertEquals(turnState.getCurrentState() ,rollDiceState); - //sends the RollDiceMachine in ThirdRoll - rollDiceMachine.gotoState(thirdRoll); - assertTrue(rollDiceMachine.getState() instanceof ThirdRollState); + //sends the RollDiceState in ThirdRoll + rollDiceState.setCurrentState(thirdRoll); + assertEquals(rollDiceState.getCurrentState() ,thirdRollState); //Todo //tests if the server is in NoPiece of ChoosePiece - assertTrue(serverAutomaton.getState() instanceof GameState); - assertTrue(gameStateMachine.getState() instanceof TurnState); - assertTrue(turnStateMachine.getState() instanceof ChoosePieceState); - ChoosePieceState choosePieceState1 = (ChoosePieceState) turnStateMachine.getState(); - ChoosePieceStateMachine choosePieceStateMachine = choosePieceState1.getChoosePieceStateMachine(); - assertTrue(choosePieceStateMachine.getState() instanceof NoPieceState); + assertEquals(serverGameLogic.getCurrentState() ,gameState); + assertEquals(gameState.getCurrentState() ,turnState); + assertEquals(turnState.getCurrentState() ,choosePieceState); + assertEquals(choosePieceState.getCurrentState() ,noPieceState); } /** - * Tests the transition from ThirdRoll state to TurnEndState. + * Tests the transition IDPlayerClient ThirdRoll state to TurnEndState. * UC-ServerState-27 */ @Test public void testThirdRollToTurnEndState() { //sends the server in Game-State - serverAutomaton.gotoState(gameState); - assertTrue(serverAutomaton.getState() instanceof GameState); + serverGameLogic.setCurrentState(gameState); + assertEquals(serverGameLogic.getCurrentState() ,gameState); - //sends the gameStateMachine in Turn - gameStateMachine.gotoState(turnState); - assertTrue(gameStateMachine.getState() instanceof TurnState); + //sends the gameState in Turn + gameState.setCurrentState(turnState); + assertEquals(gameState.getCurrentState() ,turnState); - //sends the TurnStateMachine in RollDice - turnStateMachine.gotoState(rollDiceState); - assertTrue(turnStateMachine.getState() instanceof RollDiceState); + //sends the TurnState in RollDice + turnState.setCurrentState(rollDiceState); + assertEquals(turnState.getCurrentState() ,rollDiceState); - //sends the RollDiceMachine in ThirdRoll - rollDiceMachine.gotoState(thirdRoll); - assertTrue(rollDiceMachine.getState() instanceof ThirdRollState); + //sends the RollDiceState in ThirdRoll + rollDiceState.setCurrentState(thirdRoll); + assertEquals(rollDiceState.getCurrentState() ,thirdRollState); //Todo } /** - * Tests the transition from NoPiece state to WaitingPiece state. + * Tests the transition IDPlayerClient NoPiece state to WaitingPiece state. * UC-ServerState-28 */ @Test public void testNoPieceToWaitingPiece() { //sends the server in GameState - serverAutomaton.gotoState(gameState); - assertTrue(serverAutomaton.getState() instanceof GameState); + serverGameLogic.setCurrentState(gameState); + assertEquals(serverGameLogic.getCurrentState() ,gameState); //sends the server in Turn - gameStateMachine.gotoState(turnState); - assertTrue(gameStateMachine.getState() instanceof TurnState); + gameState.setCurrentState(turnState); + assertEquals(gameState.getCurrentState() ,turnState); //sends the server in ChoosePiece - turnStateMachine.gotoState(choosePieceState); - assertTrue(turnStateMachine.getState() instanceof ChoosePieceState); + turnState.setCurrentState(choosePieceState); + assertEquals(turnState.getCurrentState() ,choosePieceState); //sends the server in NoPiece - choosePieceStateMachine.gotoState(noPiece); - assertTrue(choosePieceStateMachine.getState() instanceof NoPieceState); + choosePieceState.setCurrentState(noPiece); + assertEquals(choosePieceState.getCurrentState() ,noPieceState); //TODO //tests if the server is in WaitingPiece - assertTrue(serverAutomaton.getState() instanceof GameState); - assertTrue(gameStateMachine.getState() instanceof TurnState); - assertTrue(turnStateMachine.getState() instanceof ChoosePieceState); - assertTrue(choosePieceStateMachine.getState() instanceof WaitingPieceState); + assertEquals(serverGameLogic.getCurrentState() ,gameState); + assertEquals(gameState.getCurrentState() ,turnState); + assertEquals(turnState.getCurrentState() ,choosePieceState); + assertEquals(choosePieceState.getCurrentState() ,waitingPieceState); } /** - * Tests the transition from NoPiece state to NoTurn state. + * Tests the transition IDPlayerClient NoPiece state to NoTurn state. * UC-ServerState-29 */ @Test public void testNoPieceToNoTurn() { //sends the server in GameState - serverAutomaton.gotoState(gameState); - assertTrue(serverAutomaton.getState() instanceof GameState); + serverGameLogic.setCurrentState(gameState); + assertEquals(serverGameLogic.getCurrentState() ,gameState); //sends the server in Turn - gameStateMachine.gotoState(turnState); - assertTrue(gameStateMachine.getState() instanceof TurnState); + gameState.setCurrentState(turnState); + assertEquals(gameState.getCurrentState() ,turnState); //sends the server in ChoosePiece - turnStateMachine.gotoState(choosePieceState); - assertTrue(turnStateMachine.getState() instanceof ChoosePieceState); + turnState.setCurrentState(choosePieceState); + assertEquals(turnState.getCurrentState() ,choosePieceState); //sends the server in NoPiece - choosePieceStateMachine.gotoState(noPiece); - assertTrue(choosePieceStateMachine.getState() instanceof NoPieceState); + choosePieceState.setCurrentState(noPiece); + assertEquals(choosePieceState.getCurrentState() ,noPieceState); //TODO //tests if the server is in NoTurn - assertTrue(serverAutomaton.getState() instanceof GameState); - assertTrue(gameStateMachine.getState() instanceof TurnState); - assertTrue(turnStateMachine.getState() instanceof ChoosePieceState); - assertTrue(choosePieceStateMachine.getState() instanceof NoTurnState); + assertEquals(serverGameLogic.getCurrentState() ,gameState); + assertEquals(gameState.getCurrentState() ,turnState); + assertEquals(turnState.getCurrentState() ,choosePieceState); + assertEquals(choosePieceState.getCurrentState() ,noTurnState); } /** - * Tests the transition from NoTurn state to TurnEndState. + * Tests the transition IDPlayerClient NoTurn state to TurnEndState. * UC-ServerState-30 */ @Test public void testNoTurnToTurnEndState() { //sends the server in GameState - serverAutomaton.gotoState(gameState); - assertTrue(serverAutomaton.getState() instanceof GameState); + serverGameLogic.setCurrentState(gameState); + assertEquals(serverGameLogic.getCurrentState() ,gameState); //sends the server in Turn - gameStateMachine.gotoState(turnState); - assertTrue(gameStateMachine.getState() instanceof TurnState); + gameState.setCurrentState(turnState); + assertEquals(gameState.getCurrentState() ,turnState); //sends the server in ChoosePiece - turnStateMachine.gotoState(choosePieceState); - assertTrue(turnStateMachine.getState() instanceof ChoosePieceState); + turnState.setCurrentState(choosePieceState); + assertEquals(turnState.getCurrentState() ,choosePieceState); //sends the server in NoTurn - choosePieceStateMachine.gotoState(noTurnState); - assertTrue(choosePieceStateMachine.getState() instanceof NoTurnState); + choosePieceState.setCurrentState(noTurnState); + assertEquals(choosePieceState.getCurrentState() ,noTurnState); //TODO } @@ -872,115 +1027,115 @@ public void testNoTurnToTurnEndState() { @Test public void testStayInWaitingPiece() { //sends the server in GameState - serverAutomaton.gotoState(gameState); - assertTrue(serverAutomaton.getState() instanceof GameState); + serverGameLogic.setCurrentState(gameState); + assertEquals(serverGameLogic.getCurrentState() ,gameState); //sends the server in Turn - gameStateMachine.gotoState(turnState); - assertTrue(gameStateMachine.getState() instanceof TurnState); + gameState.setCurrentState(turnState); + assertEquals(gameState.getCurrentState() ,turnState); //sends the server in ChoosePiece - turnStateMachine.gotoState(choosePieceState); - assertTrue(turnStateMachine.getState() instanceof ChoosePieceState); + turnState.setCurrentState(choosePieceState); + assertEquals(turnState.getCurrentState() ,choosePieceState); //sends the server in WaitingPiece - choosePieceStateMachine.gotoState(waitingPiece); - assertTrue(choosePieceStateMachine.getState() instanceof WaitingPieceState); + choosePieceState.setCurrentState(waitingPiece); + assertEquals(choosePieceState.getCurrentState() ,waitingPieceState); //TODO //tests if the server is in WaitingPiece - assertTrue(serverAutomaton.getState() instanceof GameState); - assertTrue(gameStateMachine.getState() instanceof TurnState); - assertTrue(turnStateMachine.getState() instanceof ChoosePieceState); - assertTrue(choosePieceStateMachine.getState() instanceof WaitingPieceState); + assertEquals(serverGameLogic.getCurrentState() ,gameState); + assertEquals(gameState.getCurrentState() ,turnState); + assertEquals(turnState.getCurrentState() ,choosePieceState); + assertEquals(choosePieceState.getCurrentState() ,waitingPieceState); } /** - * Tests the transition from WaitingPiece state to MovePiece state. + * Tests the transition IDPlayerClient WaitingPiece state to MovePiece state. * UC-ServerState-32 */ @Test public void testWaitingPieceToMovePiece() { //sends the server in GameState - serverAutomaton.gotoState(gameState); - assertTrue(serverAutomaton.getState() instanceof GameState); + serverGameLogic.setCurrentState(gameState); + assertEquals(serverGameLogic.getCurrentState() ,gameState); //sends the server in Turn - gameStateMachine.gotoState(turnState); - assertTrue(gameStateMachine.getState() instanceof TurnState); + gameState.setCurrentState(turnState); + assertEquals(gameState.getCurrentState() ,turnState); //sends the server in ChoosePiece - turnStateMachine.gotoState(choosePieceState); - assertTrue(turnStateMachine.getState() instanceof ChoosePieceState); + turnState.setCurrentState(choosePieceState); + assertEquals(turnState.getCurrentState() ,choosePieceState); //sends the server in WaitingPiece - choosePieceStateMachine.gotoState(waitingPiece); - assertTrue(choosePieceStateMachine.getState() instanceof WaitingPieceState); + choosePieceState.setCurrentState(waitingPiece); + assertEquals(choosePieceState.getCurrentState() ,waitingPieceState); //TODO } /** - * Tests the transition from NoPiece state to SelectPiece state. + * Tests the transition IDPlayerClient NoPiece state to SelectPiece state. * UC-ServerState-33 */ @Test public void testNoPieceToSelectPiece() { //sends the server in GameState - serverAutomaton.gotoState(gameState); - assertTrue(serverAutomaton.getState() instanceof GameState); + serverGameLogic.setCurrentState(gameState); + assertEquals(serverGameLogic.getCurrentState() ,gameState); //sends the server in Turn - gameStateMachine.gotoState(turnState); - assertTrue(gameStateMachine.getState() instanceof TurnState); + gameState.setCurrentState(turnState); + assertEquals(gameState.getCurrentState() ,turnState); //sends the server in ChoosePiece - turnStateMachine.gotoState(choosePieceState); - assertTrue(turnStateMachine.getState() instanceof ChoosePieceState); + turnState.setCurrentState(choosePieceState); + assertEquals(turnState.getCurrentState() ,choosePieceState); //sends the server in NoPiece - choosePieceStateMachine.gotoState(noPiece); - assertTrue(choosePieceStateMachine.getState() instanceof NoPieceState); + choosePieceState.setCurrentState(noPiece); + assertEquals(choosePieceState.getCurrentState() ,noPieceState); //TODO //tests if the server is in SelectPiece - assertTrue(serverAutomaton.getState() instanceof GameState); - assertTrue(gameStateMachine.getState() instanceof TurnState); - assertTrue(turnStateMachine.getState() instanceof ChoosePieceState); - assertTrue(choosePieceStateMachine.getState() instanceof SelectPieceState); + assertEquals(serverGameLogic.getCurrentState() ,gameState); + assertEquals(gameState.getCurrentState() ,turnState); + assertEquals(turnState.getCurrentState() ,choosePieceState); + assertEquals(choosePieceState.getCurrentState() ,selectPieceState); } /** - * Tests the transition from NoPiece state to StartPiece state. + * Tests the transition IDPlayerClient NoPiece state to StartPiece state. * UC-ServerState-34 */ @Test public void testNoPieceToStartPiece() { //sends the server in GameState - serverAutomaton.gotoState(gameState); - assertTrue(serverAutomaton.getState() instanceof GameState); + serverGameLogic.setCurrentState(gameState); + assertEquals(serverGameLogic.getCurrentState() ,gameState); //sends the server in Turn - gameStateMachine.gotoState(turnState); - assertTrue(gameStateMachine.getState() instanceof TurnState); + gameState.setCurrentState(turnState); + assertEquals(gameState.getCurrentState() ,turnState); //sends the server in ChoosePiece - turnStateMachine.gotoState(choosePieceState); - assertTrue(turnStateMachine.getState() instanceof ChoosePieceState); + turnState.setCurrentState(choosePieceState); + assertEquals(turnState.getCurrentState() ,choosePieceState); //sends the server in NoPiece - choosePieceStateMachine.gotoState(noPiece); - assertTrue(choosePieceStateMachine.getState() instanceof NoPieceState); + choosePieceState.setCurrentState(noPiece); + assertEquals(choosePieceState.getCurrentState() ,noPieceState); //TODO //tests if the server is in StartPiece - assertTrue(serverAutomaton.getState() instanceof GameState); - assertTrue(gameStateMachine.getState() instanceof TurnState); - assertTrue(turnStateMachine.getState() instanceof ChoosePieceState); - assertTrue(choosePieceStateMachine.getState() instanceof StartPieceState); + assertEquals(serverGameLogic.getCurrentState() ,gameState); + assertEquals(gameState.getCurrentState() ,turnState); + assertEquals(turnState.getCurrentState() ,choosePieceState); + assertEquals(choosePieceState.getCurrentState() ,startPieceState); } /** @@ -990,53 +1145,58 @@ public void testNoPieceToStartPiece() { @Test public void testStayInSelectPiece() { //sends the server in GameState - serverAutomaton.gotoState(gameState); - assertTrue(serverAutomaton.getState() instanceof GameState); + serverGameLogic.setCurrentState(gameState); + assertEquals(serverGameLogic.getCurrentState() ,gameState); //sends the server in Turn - gameStateMachine.gotoState(turnState); - assertTrue(gameStateMachine.getState() instanceof TurnState); + gameState.setCurrentState(turnState); + assertEquals(gameState.getCurrentState() ,turnState); //sends the server in ChoosePiece - turnStateMachine.gotoState(choosePieceState); - assertTrue(turnStateMachine.getState() instanceof ChoosePieceState); + turnState.setCurrentState(choosePieceState); + assertEquals(turnState.getCurrentState() ,choosePieceState); //sends the server in SelectPiece - choosePieceStateMachine.gotoState(selectPiece); - assertTrue(choosePieceStateMachine.getState() instanceof SelectPieceState); + choosePieceState.setCurrentState(selectPiece); + assertEquals(choosePieceState.getCurrentState() ,selectPieceState); //TODO //tests if the server is in SelectPiece - assertTrue(serverAutomaton.getState() instanceof GameState); - assertTrue(gameStateMachine.getState() instanceof TurnState); - assertTrue(turnStateMachine.getState() instanceof ChoosePieceState); - assertTrue(choosePieceStateMachine.getState() instanceof SelectPieceState); + assertEquals(serverGameLogic.getCurrentState() ,gameState); + assertEquals(gameState.getCurrentState() ,turnState); + assertEquals(turnState.getCurrentState() ,choosePieceState); + assertEquals(choosePieceState.getCurrentState() ,selectPieceState); } /** - * Tests the transition from SelectPiece state to MovePiece state. + * Tests the transition IDPlayerClient SelectPiece state to MovePiece state. * UC-ServerState-36 */ @Test public void testSelectPieceToMovePiece() { //sends the server in GameState - serverAutomaton.gotoState(gameState); - assertTrue(serverAutomaton.getState() instanceof GameState); + serverGameLogic.setCurrentState(gameState); + assertEquals(serverGameLogic.getCurrentState() ,gameState); //sends the server in Turn - gameStateMachine.gotoState(turnState); - assertTrue(gameStateMachine.getState() instanceof TurnState); + gameState.setCurrentState(turnState); + assertEquals(gameState.getCurrentState() ,turnState); //sends the server in ChoosePiece - turnStateMachine.gotoState(choosePieceState); - assertTrue(turnStateMachine.getState() instanceof ChoosePieceState); + turnState.setCurrentState(choosePieceState); + assertEquals(turnState.getCurrentState() ,choosePieceState); //sends the server in SelectPiece - choosePieceStateMachine.gotoState(selectPiece); - assertTrue(choosePieceStateMachine.getState() instanceof SelectPieceState); + choosePieceState.setCurrentState(selectPiece); + assertEquals(choosePieceState.getCurrentState() ,selectPieceState); //TODO + + //tests if the server is in movePiece-state + assertEquals(serverGameLogic.getCurrentState() ,gameState); + assertEquals(gameState.getCurrentState() ,turnState); + assertEquals(turnState.getCurrentState() ,movePieceState); } /** @@ -1046,52 +1206,57 @@ public void testSelectPieceToMovePiece() { @Test public void testStayInStartPiece() { //sends the server in GameState - serverAutomaton.gotoState(gameState); - assertTrue(serverAutomaton.getState() instanceof GameState); + serverGameLogic.setCurrentState(gameState); + assertEquals(serverGameLogic.getCurrentState() ,gameState); //sends the server in Turn - gameStateMachine.gotoState(turnState); - assertTrue(gameStateMachine.getState() instanceof TurnState); + gameState.setCurrentState(turnState); + assertEquals(gameState.getCurrentState() ,turnState); //sends the server in ChoosePiece - turnStateMachine.gotoState(choosePieceState); - assertTrue(turnStateMachine.getState() instanceof ChoosePieceState); + turnState.setCurrentState(choosePieceState); + assertEquals(turnState.getCurrentState() ,choosePieceState); //sends the server in StartPiece - choosePieceStateMachine.gotoState(startPiece); - assertTrue(choosePieceStateMachine.getState() instanceof StartPieceState); + choosePieceState.setCurrentState(startPiece); + assertEquals(choosePieceState.getCurrentState() ,startPieceState); //TODO //tests if the server is in StartPiece - assertTrue(serverAutomaton.getState() instanceof GameState); - assertTrue(gameStateMachine.getState() instanceof TurnState); - assertTrue(turnStateMachine.getState() instanceof ChoosePieceState); - assertTrue(choosePieceStateMachine.getState() instanceof StartPieceState); + assertEquals(serverGameLogic.getCurrentState() ,gameState); + assertEquals(gameState.getCurrentState() ,turnState); + assertEquals(turnState.getCurrentState() ,choosePieceState); + assertEquals(choosePieceState.getCurrentState() ,startPieceState); } /** - * Tests the transition from StartPiece state to MovePiece state. + * Tests the transition IDPlayerClient StartPiece state to MovePiece state. * UC-ServerState-38 */ @Test public void testStartPieceToMovePiece() { //sends the server in GameState - serverAutomaton.gotoState(gameState); - assertTrue(serverAutomaton.getState() instanceof GameState); + serverGameLogic.setCurrentState(gameState); + assertEquals(serverGameLogic.getCurrentState() ,gameState); //sends the server in Turn - gameStateMachine.gotoState(turnState); - assertTrue(gameStateMachine.getState() instanceof TurnState); + gameState.setCurrentState(turnState); + assertEquals(gameState.getCurrentState() ,turnState); //sends the server in ChoosePiece - turnStateMachine.gotoState(choosePieceState); - assertTrue(turnStateMachine.getState() instanceof ChoosePieceState); + turnState.setCurrentState(choosePieceState); + assertEquals(turnState.getCurrentState() ,choosePieceState); //sends the server in StartPiece - choosePieceStateMachine.gotoState(startPiece); - assertTrue(choosePieceStateMachine.getState() instanceof StartPieceState); + choosePieceState.setCurrentState(startPiece); + assertEquals(choosePieceState.getCurrentState() ,startPieceState); //TODO + + //tests if the server is in movePiece-state + assertEquals(serverGameLogic.getCurrentState() ,gameState); + assertEquals(gameState.getCurrentState() ,turnState); + assertEquals(turnState.getCurrentState() ,movePieceState); } }