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 3b7c87db..875dd611 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,247 +1,256 @@ 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.gamestate.*; -import pp.mdga.client.gamestate.turnstate.choosepiecestate.*; -import pp.mdga.client.gamestate.determineStartPlayer.DetermineStartPlayerStateMachine; +import pp.mdga.client.ceremonystate.*; +import pp.mdga.client.dialogstate.*; +import pp.mdga.client.gamestate.AnimationState; +import pp.mdga.client.gamestate.DetermineStartPlayerState; +import pp.mdga.client.gamestate.SpectatorState; +import pp.mdga.client.gamestate.TurnState; +import pp.mdga.client.gamestate.WaitingState; +import pp.mdga.client.gamestate.determinestartplayerstate.RollRankingDiceState; +import pp.mdga.client.gamestate.determinestartplayerstate.WaitRankingState; +import pp.mdga.client.gamestate.turnstate.ChoosePieceState; +import pp.mdga.client.gamestate.turnstate.MovePieceState; 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.turnstate.choosepiecestate.*; +import pp.mdga.client.gamestate.turnstate.powercardstate.*; +import pp.mdga.game.Game; +import pp.mdga.game.Piece; +import pp.mdga.game.PieceState; +import pp.mdga.game.Player; +import pp.mdga.game.card.PowerCard; +import pp.mdga.message.server.*; import pp.mdga.game.BonusCard; import pp.mdga.game.Color; import pp.mdga.message.client.ClientMessage; +import pp.mdga.visitor.Visitor; import java.util.ArrayList; +import java.util.List; -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 LobbyPlayerJoinedMessage 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 PossibleCardsMessage 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; private Color color; - private BonusCard swapCard; - private BonusCard shieldCard; - private BonusCard turboCard; + private PowerCard swapCard; + private PowerCard shieldCard; + private PowerCard turboCard; - private pp.mdga.game.Game game; + //declare a player + private Player player; + + //declare own piece + private Piece ownPiece= new Piece(Color.ARMY, PieceState.ACTIVE); + + //declare enemy piece + private Piece enemyPiece = new Piece(Color.CYBER, PieceState.ACTIVE); @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(); - //initialize the clientGameLogic - clientGameLogic = new ClientGameLogic(game, new ClientSender() { + clientGameLogic = new ClientGameLogic(new ClientSender() { @Override 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 game + game = clientGameLogic.getGame(); + //initialize the playerID + from = 1234; + name = "Daniel"; + color = Color.ARMY; - //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 a player + player = new Player(name); + //todo piece - //initialize the states - dialogsState = new DialogsState(clientAutomaton,clientGameLogic); - gameState = new GameState(clientAutomaton,clientGameLogic); - ceremonyState = new CeremonyState(clientAutomaton,clientGameLogic); - interruptState = new InterruptState(clientAutomaton,clientGameLogic,gameState); + swapCard = new PowerCard() { + @Override + public void accept(Visitor visitor) { - startDialogState = new StartDialogState(dialogsStateMachine,clientGameLogic); - networkDialogState = new NetworkDialogState(dialogsStateMachine,clientGameLogic); - lobbyState = new LobbyState(dialogsStateMachine,clientGameLogic); + } + }; + shieldCard = new PowerCard() { + @Override + public void accept(Visitor visitor) { - podium = new PodiumState(ceremonyStateMachine,clientGameLogic); - statistics = new StatisticsState(ceremonyStateMachine,clientGameLogic); + } + }; + turboCard = new PowerCard() { + @Override + public void accept(Visitor visitor) { - 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); + } + }; - rollRankingDice = new RollRankingDice(determineStartPlayerStateMachine,clientGameLogic); - waitRanking = new WaitRanking(determineStartPlayerStateMachine,clientGameLogic); + //initialize the messages from the server + activePlayer = new ActivePlayerMessage(color); + anyPiece = new AnyPieceMessage(); + briefing = new BriefingMessage(); + ceremonyMessage = new CeremonyMessage(); + die = new DieMessage(6); + diceAgain = new DiceAgainMessage(); + diceNow = new DiceNowMessage(); + endOfTurn = new EndOfTurnMessage(); + lobbyAccept = new LobbyAcceptMessage(); + lobbyDeny = new LobbyDenyMessage(); + lobbyPlayerJoin = new LobbyPlayerJoinedMessage(from, player,true); + lobbyPlayerLeave = new LobbyPlayerLeaveMessage(from); + moveMessage = new MoveMessage(ownPiece, false, 25); + noTurn = new NoTurnMessage(); + interruptMessage = new PauseGameMessage(); + playCardSwap = new PlayCardMessage(swapCard, new ArrayList<>(List.of(ownPiece, enemyPiece)), 1); //TODO + playCardShield = new PlayCardMessage(shieldCard, new ArrayList<>(List.of(ownPiece)), 1); + playCardTurbo = new PlayCardMessage(turboCard, new ArrayList<>(),1); + possibleCard = new PossibleCardsMessage(new ArrayList<>(List.of(swapCard,shieldCard,turboCard))); + 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(ownPiece.getUuid(),25); + updateReady = new UpdateReadyMessage(from, true); + updateTSK = new UpdateTSKMessage(from, color,false); + waitPiece = new WaitPieceMessage(); + interruptMessage = new PauseGameMessage(); + spectatorMessage = new SpectatorMessage(); + selectPieceMessage = new SelectPieceMessage(); - 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); - - choosePowerCardState = new ChoosePowerCardState(powerCardStateMachine,clientGameLogic); - shieldState =new ShieldState(powerCardStateMachine,clientGameLogic); - swapState = new SwapState(powerCardStateMachine,clientGameLogic); - - noPieceState = new NoPieceState(choosePieceStateMachine,clientGameLogic); - waitingPieceState = new WaitingPieceState(choosePieceStateMachine,clientGameLogic); - selectPieceState = new SelectPieceState(choosePieceStateMachine,clientGameLogic); - startPieceState = new StartPieceState(choosePieceStateMachine,clientGameLogic); + //initialize the client-state + //sets the clientGameLogic-states + dialogs = clientGameLogic.getDialogs(); + gameState = clientGameLogic.getGameState(); + ceremony = clientGameLogic.getCeremony(); + interrupt = clientGameLogic.getInterrupt(); + //sets the dialogs-states + startDialog = dialogs.getStartDialog(); + networkDialog = dialogs.getNetworkDialog(); + lobby = dialogs.getLobby(); + //sets the ceremony-states + podium = ceremony.getPodiumState(); + statistics = ceremony.getStatisticsState(); + //sets the game-states + determineStartPlayer = gameState.getDetermineStartPlayer(); + waiting = gameState.getWaiting(); + animation = gameState.getAnimation(); + turnState = gameState.getTurn(); + spectator = gameState.getSpectator(); + //sets the determineStartPlayer-states + rollRankingDice = determineStartPlayer.getRollRankingDice(); + waitRanking = determineStartPlayer.getWaitRanking(); + //sets the turn-states + powerCard = turnState.getPowerCard(); + playPowerCard = turnState.getPlayPowerCard(); + rollDice = turnState.getRollDice(); + choosePiece = turnState.getChoosePiece(); + movePiece = turnState.getMovePiece(); + //sets the powerCard-states + choosePowerCard = powerCard.getChoosePowerCard(); + shield = powerCard.getShield(); + swap = powerCard.getSwap(); + //sets the choosePiece-states + noPiece = choosePiece.getNoPiece(); + waitingPiece = choosePiece.getWaitingPiece(); + selectPiece = choosePiece.getSelectPiece(); + startPiece = choosePiece.getStartPiece(); } /** - * UC-ClientState-01: Test the initial state of the ClientState. + * UC-ClientState-01: Test the initial-state of the ClientState. */ @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 +259,59 @@ 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); + dialogs.setState(lobby); + assertEquals(clientGameLogic.getState(), dialogs); + assertEquals(dialogs.getState(), lobby); + + //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);todo + //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 +319,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,20 +335,58 @@ 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); + + //sends the gameState in wait + gameState.setState(waiting); + assertEquals(gameState.getState(), waiting); + + 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); + System.out.println(clientGameLogic.getState()); + 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); } /** @@ -305,17 +394,15 @@ public void testClientGameToCeremony() { */ @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 +410,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 +426,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 +472,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 +488,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 +506,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 +525,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 +550,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,27 +575,41 @@ 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 } /** - * UC-ClientState-14: Test the transition from NetworkDialog to StartDialog. + * UC-ClientState-14: Test the transitions from NetworkDialog to StartDialog. */ @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 +617,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 +648,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 +672,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 +691,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 +712,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 +776,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 +801,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 +822,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 +877,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,7 +905,20 @@ 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); } /** @@ -678,23 +926,315 @@ public void testWaitToGameEndState() { */ @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); } /** - * UC-ClientState-26: Test the transition from Turn sub-states to Wait. + * UC-ClientState-26: Test the transition from Turn substates to Wait. */ @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); } /** - * UC-ClientState-27: Test the transition from Turn sub-states to Spectator. + * UC-ClientState-27: Test the transition from Turn substates to Spectator. */ @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,23 +1242,149 @@ 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); } /** - * UC-ClientState-29: Test the transition from PowerCard sub-states to PlayPowerCard. + * UC-ClientState-29: Test the transition from PowerCard substates to PlayPowerCard. */ @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. + * UC-ClientState-30: Test the transition from PowerCard substates 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 +1392,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 +1448,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 +1512,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 +1568,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 +1594,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 +1739,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 +1765,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 +1790,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 +1815,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 +1871,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 +1901,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 +1932,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 +1963,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 +2024,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 +2093,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 +2123,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 +2186,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 +2249,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 +2312,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 +2379,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 +2440,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 +2469,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 +2529,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 +2558,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 +2687,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 +2751,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 +2815,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 +2878,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 +2899,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/server/serverState/ServerStateTest.java b/Projekte/mdga/model/src/test/java/pp/mdga/server/serverState/ServerStateTest.java index f410785c..6c6a760c 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,155 +1,224 @@ package pp.mdga.server.serverState; -import org.junit.Before; -import org.junit.Test; -import pp.mdga.game.Game; +//TODO important: set activePlayer, setPlayers, setPieces, setBonusCards + +import org.junit.*; +import pp.mdga.game.*; +import pp.mdga.game.card.PowerCard; 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 pp.mdga.server.automaton.game.*; +import pp.mdga.server.automaton.game.turn.*; +import pp.mdga.server.automaton.game.turn.choosepiece.*; +import pp.mdga.server.automaton.game.turn.rolldice.*; +import pp.mdga.visitor.Visitor; import static org.junit.Assert.*; /** * this test-class tests the Testcases T132-T169 */ + 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 JoinedLobbyMessage 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 PowerCard bonusCardClient; + + //TODO declare the states here + private AnimationState animationState; private CeremonyState ceremonyState; private ChoosePieceState choosePieceState; private DetermineStartPlayerState determineStartPlayerState; - private FirstRollStateState firstRollState; + private FirstRollState firstRollState; private GameState gameState; private InterruptState interruptState; private LobbyState lobbyState; private MovePieceState movePieceState; - private NoPieceState noPiece; + private NoPieceState noPieceState; private NoTurnState noTurnState; - private PlayPowerCard playPowerCard; + private PlayPowerCardState playPowerCardState; private PowerCardState powerCardState; private RollDiceState rollDiceState; - private SecondRollState secondRoll; - private SelectPieceState selectPiece; - private StartPieceState startPiece; - private ThirdRollState thirdRoll; + private SecondRollState secondRollState; + private SelectPieceState selectPieceState; + private StartPieceState startPieceState; + private ThirdRollState thirdRollState; private TurnState turnState; - private WaitingPieceState waitingPiece; + private WaitingPieceState waitingPieceState; + + /** - * TODO + * this method is used to initialize the attributes of this test-class */ @Before public void setUp() { + game = new Game(); + //initialize two players + playerHost = new Player("Host"); + IDPlayerHost = 1; + playerHostColor = Color.CYBER; + playerHost.setColor(playerHostColor); + game.addPlayer(IDPlayerHost, playerHost); - logic = new ServerGameLogic(new Game(), new ServerSender() { + playerClient = new Player("Client"); + IDPlayerClient = 2; + playerClientColor = Color.ARMY; + playerClient.setColor(playerClientColor); + playerClient.addHandCard(bonusCardClient); + game.addPlayer(IDPlayerClient, playerClient); //TODO random uuid + + serverGameLogic = new ServerGameLogic(new ServerSender() { @Override - public void send(int id, ServerMessage msg) { + public void send(int id, ServerMessage message) { + + } + + @Override + public void broadcast(ServerMessage message) { + + } + + @Override + public void disconnectClient(int id) { + + } + + @Override + public void shutdown() { + + } + }, game); + + + game.setActiveColor(playerClientColor); + + //initialize a piece for client + IDPiece = 3; + pieceState = PieceState.ACTIVE; + piece = new Piece(playerClientColor, pieceState); + 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); + pieceHome2 = new Piece(playerClientColor, PieceState.HOMEFINISHED); + pieceHome3 = new Piece(playerClientColor, PieceState.HOMEFINISHED); + game.getPlayers().get(playerClientColor).setPieceInHome(1, pieceHome1); + game.getPlayers().get(playerClientColor).setPieceInHome(2, pieceHome2); + game.getPlayers().get(playerClientColor).setPieceInHome(3, pieceHome3); + + //initialize the powerCard + bonusCardClient = new PowerCard() { + @Override + public void accept(Visitor visitor) { } - }); - 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(); + lobbyState = serverGameLogic.getLobbyState(); + gameState = serverGameLogic.getGameState(); + ceremonyState = serverGameLogic.getCeremonyState(); + interruptState = serverGameLogic.getInterruptState(); - thirdRoll = new ThirdRollState(rollDiceMachine, logic); - secondRoll = new SecondRollState(rollDiceMachine, logic); - firstRollState = new FirstRollStateState(rollDiceMachine, logic); + determineStartPlayerState = gameState.getDetermineStartPlayerState(); + turnState = gameState.getTurnState(); + animationState = gameState.getAnimationState(); - 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); - 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); + animationEnd = new AnimationEndMessage(); + deselectTSK = new DeselectTSKMessage(playerClientColor); + disconnected = new DisconnectedMessage(); + forceContinueGame = new ForceContinueGameMessage(); + joinServer = new JoinedLobbyMessage(); + leaveGame = new LeaveGameMessage(); + lobbyNotReady = new LobbyNotReadyMessage(); + lobbyReady = new LobbyReadyMessage(); + noPowerCard = new NoPowerCardMessage(); + requestBriefing = new RequestBriefingMessage(); + requestDie = new RequestDieMessage(); + //requestMove = new RequestMoveMessage(); TODO + //requestPlayCard = RequestPlayCardMessage.requestPlayShield(bonusCardClient); //TODO + //selectCard = new SelectCardMessage(); //TODO + //selectedPieces = new SelectedPiecesMessage(); TODO + //selectTSK = new SelectTSKMessage(); TODO + //startGame = new StartGameMessage(); TODO - determineStartPlayerState = new DetermineStartPlayerState(gameStateMachine, logic); - turnState = new TurnState(gameStateMachine, logic); - animation = new Animation(gameStateMachine, logic); + //initialize the states here - lobbyState = new LobbyState(serverAutomaton, logic); - gameState = new GameState(serverAutomaton, logic); - ceremonyState = new CeremonyState(serverAutomaton, logic); - interruptState = new InterruptState(serverAutomaton, logic, gameState); + powerCardState = turnState.getPowerCardState(); + playPowerCardState = turnState.getPlayPowerCardState(); + rollDiceState = turnState.getRollDiceState(); + choosePieceState = turnState.getChoosePieceState(); + movePieceState = turnState.getMovePieceState(); + + thirdRollState = rollDiceState.getThirdRollState(); + secondRollState = rollDiceState.getSecondRollState(); + firstRollState = rollDiceState.getFirstRollState(); + + noPieceState = choosePieceState.getNoPieceState(); + noTurnState = choosePieceState.getNoTurnState(); + waitingPieceState = choosePieceState.getWaitingPieceState(); + startPieceState = choosePieceState.getStartPieceState(); + selectPieceState = choosePieceState.getSelectPieceState(); + + /* + * this attribute is used, so the server knows, that always it's the host's turn + */ + game.setActiveColor(playerHostColor); } /** @@ -157,7 +226,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 +237,46 @@ 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 don't 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 todo + //game.setAllReady(false); + + //tests if the server is still in the lobby-state + assertEquals(serverGameLogic.getLobbyState(), lobbyState); + + //sets both players ready todo + //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 +285,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 don't 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 +317,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 +348,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 +386,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 +401,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 +415,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 +429,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 +466,33 @@ 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 + //set die to 6 + game.setDie(new Die(6)); + + //sends the two requestDiceMessages + serverGameLogic.received(requestDie, IDPlayerClient); + serverGameLogic.received(requestDie, IDPlayerHost); + + //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 +501,113 @@ 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 + //set die to 6 + game.setDie(new Die(6)); + + //sends the two requestDiceMessages + serverGameLogic.received(requestDie, IDPlayerClient); + + //set die to 6 + game.setDie(new Die(5)); + + //sends the two requestDiceMessages + serverGameLogic.received(requestDie, IDPlayerClient); //tests if the Server is in animationState - assertTrue(serverAutomaton.getState() instanceof GameState); - assertTrue(gameStateMachine.getState() instanceof Animation); + assertEquals(serverGameLogic.getCurrentState(), gameState); + assertEquals(gameState.getCurrentState(), animationState); } /** - * 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(animationState); + assertEquals(gameState.getCurrentState(), animationState); //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(), animationState); //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(movePieceState); + assertEquals(turnState.getCurrentState(), movePieceState); + + //set dices-eyes in game !=6 + game.setDiceEyes(4); + + //serverGameLogic receives animationEndMessages + serverGameLogic.received(animationEnd, IDPlayerClient); + + //tests if the server is still in movePieceState + assertEquals(serverGameLogic.getCurrentState(), gameState); + assertEquals(gameState.getCurrentState(), turnState); + assertEquals(turnState.getCurrentState(), movePieceState); + + //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(), animationState); } /** - * 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 +617,145 @@ 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 + serverGameLogic.received(selectCard, IDPlayerClient); //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(), playPowerCardState); } /** - * 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(playPowerCardState); + assertEquals(turnState.getCurrentState(), playPowerCardState); - //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(), playPowerCardState); //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 +763,303 @@ 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() { + //sets the die to 6 + game.setDie(new Die(6)); + //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 + //sends the animationEndMessage + serverGameLogic.received(animationEnd, IDPlayerClient); + serverGameLogic.received(animationEnd, IDPlayerHost); - 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); + //tests if the server is in firstRoll + assertEquals(serverGameLogic.getCurrentState(), gameState); + assertEquals(gameState.getCurrentState(), turnState); + assertEquals(turnState.getCurrentState(), rollDiceState); + assertEquals(rollDiceState.getCurrentState(), firstRollState); + + //tests if the activeColor is still Host + assertEquals(game.getActiveColor(),playerHostColor); } /** - * 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(secondRollState); + 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(secondRollState); + 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(thirdRollState); + 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(thirdRollState); + 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(noPieceState); + 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(noPieceState); + 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 +1071,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(waitingPieceState); + 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(waitingPieceState); + 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(noPieceState); + 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(noPieceState); + 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 +1189,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(selectPieceState); + 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(selectPieceState); + 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 +1250,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(startPieceState); + 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(startPieceState); + 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); } }