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 8e49f064..251a0b9b 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 @@ -31,6 +31,8 @@ import java.util.List; import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertNotSame; /** * this test-class tests the Testcases T132-T169 @@ -120,7 +122,6 @@ public class ServerStateTest { private SelectedPiecesMessage selectedPiecesMessage; - /** * this method is used to initialize the attributes of this test-class */ @@ -131,10 +132,9 @@ public void setUp() { playerHost = new Player("Host"); playerHostColor = Color.CYBER; playerHost.setColor(playerHostColor); - PowerCard shield= new ShieldCard(); + PowerCard shield = new ShieldCard(); selectCard = new SelectCardMessage(shield); - playerHost.addHandCard(shield); playerHost.addHandCard(new SwapCard()); playerHost.addHandCard(new TurboCard()); @@ -145,16 +145,12 @@ public void setUp() { hostPiece2 = playerHost.getWaitingArea()[1]; hostPiece3 = playerHost.getWaitingArea()[2]; hostPiece4 = playerHost.getWaitingArea()[3]; - game.getBoard().setPieceOnBoard(15,hostPiece1); + game.getBoard().setPieceOnBoard(15, hostPiece1); hostPiece1.setState(PieceState.ACTIVE); - game.getBoard().setPieceOnBoard(35,hostPiece2); + game.getBoard().setPieceOnBoard(35, hostPiece2); hostPiece2.setState(PieceState.ACTIVE); selectedPiecesMessage = new SelectedPiecesMessage(List.of(hostPiece2)); - - - - playerClient = new Player("Client"); playerClient.addHandCard(new ShieldCard()); playerClient.addHandCard(new SwapCard()); @@ -166,10 +162,9 @@ public void setUp() { playerClient.addHandCard(bonusCardClient); game.addPlayer(IDPlayerClient, playerClient); pieceClient4 = playerClient.getWaitingArea()[3]; - game.getBoard().setPieceOnBoard(22,pieceClient4); + game.getBoard().setPieceOnBoard(22, pieceClient4); pieceClient4.setState(PieceState.ACTIVE); - serverGameLogic = new ServerGameLogic(new ServerSender() { @Override public void send(int id, ServerMessage message) { @@ -226,7 +221,6 @@ public void accept(Visitor visitor) { turnState = gameState.getTurnState(); animationState = gameState.getAnimationState(); - animationEnd = new AnimationEndMessage(); deselectTSK = new DeselectTSKMessage(playerClientColor); disconnected = new DisconnectedMessage(); @@ -271,7 +265,7 @@ public void accept(Visitor visitor) { /** * this test-method tests, that the server, when initialized, is in the Lobby-state - * + *
* serverStateTest1 */ @Test @@ -283,7 +277,7 @@ public void testInitialStateServerState() { /** * this method tests that the server, if all players are ready and the startGameMessage is issued, * changes into the DetermineStartPlayer-state - * + *
* serverStateTest2 */ @Test @@ -327,7 +321,7 @@ public void testLobbyToDetermineStartPlayer() { /** * this method tests, that the server stays in the Lobby - * + *
* serverStateTest3 */ @Test @@ -357,7 +351,7 @@ public void testStayInLobby() { /** * this method tests, that the server can go into the interrupt-state - * + *
* serverStateTest4 */ @Test @@ -375,7 +369,7 @@ public void testServerGameSubStatesToInterrupt() { /** * tests the state-change IDPlayerClient Game to Ceremony if the Game is finished - * + *
* serverStateTest5 */ @Test @@ -392,7 +386,7 @@ public void testServerGameToCeremony() { /** * this method tests that the server goes back to the Game, when the ForceStartGame-message is issued - * + *
* serverStateTest6 */ @Test @@ -431,7 +425,7 @@ public void testInterruptToGameContinue() { /** * this method tests, that the server goes back to the game, if the missing client has reconnected - * + *
* serverStateTest7 */ @Test @@ -448,7 +442,7 @@ public void testInterruptToGameReconnect() { /** * this method tests, that th e server continues with the game, if there is no time left on the timer - * + *
* serverStateTest8 */ @Test @@ -465,7 +459,7 @@ public void testInterruptToGameTimer() { /** * this method tests, that the server closes, if the ceremony has ended - * + *
* serverStateTest9 */ @Test @@ -550,7 +544,7 @@ public void testDetermineStartPlayerToDetermineStartPlayer2() { /** * this method tests that the server goes into Animation-state, if there is an order - * + *
* serverStateTest12 */ @Test @@ -574,7 +568,7 @@ public void testDetermineStartPlayerToAnimation() { //sends the two requestDiceMessages serverGameLogic.received(requestDie, IDPlayerHost); - serverGameLogic.received(new AnimationEndMessage(),IDPlayerClient); + serverGameLogic.received(new AnimationEndMessage(), IDPlayerClient); serverGameLogic.received(new AnimationEndMessage(), IDPlayerHost); //tests if the Server is in animationState @@ -585,7 +579,7 @@ public void testDetermineStartPlayerToAnimation() { /** * 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 - * + *
* serverStateTest13 */ @Test @@ -616,7 +610,7 @@ public void testAnimationToPowerCard() { /** * 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 - * + *
* serverStateTest14 */ @Test @@ -655,7 +649,7 @@ public void testTurnToAnimation() { /** * 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 - * + *
* serverStateTest15 */ @Test @@ -677,7 +671,7 @@ public void testTurnToGameEndState() { /** * this method tests that the server don't change it's state whe issued with messages, * which don't implicate a statechange - * + *
* serverStateTest16 */ @Test @@ -788,7 +782,7 @@ public void testChoosePieceToMovePiece() { game.setActiveColor(playerClientColor); turnState.setPlayer(playerClient); playerClient.removeWaitingPiece(pieceClient4); - game.getBoard().setPieceOnBoard(25,pieceClient4); + game.getBoard().setPieceOnBoard(25, pieceClient4); pieceClient4.setState(PieceState.ACTIVE); //sends the server in Game-State @@ -810,8 +804,7 @@ public void testChoosePieceToMovePiece() { selectPieceState.setIsHomeMove(new ArrayList<>(List.of(false))); selectPieceState.setTargetIndex(new ArrayList<>(List.of(23))); - serverGameLogic.received(new RequestMoveMessage(pieceClient4),IDPlayerClient); - + serverGameLogic.received(new RequestMoveMessage(pieceClient4), IDPlayerClient); assertEquals(serverGameLogic.getCurrentState(), gameState); assertEquals(gameState.getCurrentState(), turnState); @@ -905,8 +898,8 @@ public void testFirstRollToRollDiceEndState() { game.setDie(new Die(1)); - serverGameLogic.received(new RequestDieMessage(),IDPlayerClient); - serverGameLogic.received(new AnimationEndMessage(),IDPlayerClient); + serverGameLogic.received(new RequestDieMessage(), IDPlayerClient); + serverGameLogic.received(new AnimationEndMessage(), IDPlayerClient); //tests if the server is in ChoosePiece assertEquals(serverGameLogic.getCurrentState(), gameState); @@ -952,7 +945,6 @@ public void testFirstRollToSecondRoll() { assertEquals(gameState.getCurrentState(), turnState); assertEquals(turnState.getCurrentState(), rollDiceState); assertEquals(rollDiceState.getCurrentState(), secondRollState); - } /** @@ -985,14 +977,13 @@ public void testSecondRollToRollDiceEndState() { game.setDie(new Die(6)); // - serverGameLogic.received(requestDie,IDPlayerClient); + serverGameLogic.received(requestDie, IDPlayerClient); serverGameLogic.received(animationEnd, IDPlayerClient); //tests if the server is in NoPiece of ChoosePiece assertEquals(serverGameLogic.getCurrentState(), gameState); assertEquals(gameState.getCurrentState(), turnState); assertEquals(turnState.getCurrentState(), choosePieceState); - } /** @@ -1057,7 +1048,7 @@ public void testThirdRollToRollDiceEndState() { //die =6 game.setDie(new Die(6)); - serverGameLogic.received(requestDie,IDPlayerClient); + serverGameLogic.received(requestDie, IDPlayerClient); System.out.println(game.getActivePlayer()); System.out.println(game.getActivePlayer().getStartNodeIndex()); serverGameLogic.received(animationEnd, IDPlayerClient); @@ -1074,6 +1065,9 @@ public void testThirdRollToRollDiceEndState() { */ @Test public void testThirdRollToTurnEndState() { + game.setActiveColor(playerClientColor); + playerClient.setHandCards(new ArrayList<>()); + //sends the server in Game-State serverGameLogic.setCurrentState(gameState); assertEquals(serverGameLogic.getCurrentState(), gameState); @@ -1090,7 +1084,12 @@ public void testThirdRollToTurnEndState() { rollDiceState.setCurrentState(thirdRollState); assertEquals(rollDiceState.getCurrentState(), thirdRollState); - //Todo + game.setDie(new Die(4)); + + serverGameLogic.received(new RequestDieMessage(), IDPlayerClient); + serverGameLogic.received(new AnimationEndMessage(), IDPlayerClient); + + assertNotSame(game.getActiveColor(), playerClientColor); } /** @@ -1099,6 +1098,10 @@ public void testThirdRollToTurnEndState() { */ @Test public void testNoPieceToWaitingPiece() { + game.setActiveColor(playerClientColor); + playerClient.setHandCards(new ArrayList<>()); + turnState.setPlayer(playerClient); + //sends the server in GameState serverGameLogic.setCurrentState(gameState); assertEquals(serverGameLogic.getCurrentState(), gameState); @@ -1115,13 +1118,12 @@ public void testNoPieceToWaitingPiece() { choosePieceState.setCurrentState(noPieceState); assertEquals(choosePieceState.getCurrentState(), noPieceState); - //TODO - //tests if the server is in WaitingPiece assertEquals(serverGameLogic.getCurrentState(), gameState); assertEquals(gameState.getCurrentState(), turnState); - assertEquals(turnState.getCurrentState(), choosePieceState); - assertEquals(choosePieceState.getCurrentState(), waitingPieceState); + assertEquals(turnState.getCurrentState(), powerCardState); + + assertNotSame(game.getActiveColor(), playerClientColor); } /** @@ -1304,6 +1306,10 @@ public void testNoPieceToStartPiece() { */ @Test public void testStayInSelectPiece() { + game.setActiveColor(playerClientColor); + playerClient.setHandCards(new ArrayList<>()); + turnState.setPlayer(playerClient); + //sends the server in GameState serverGameLogic.setCurrentState(gameState); assertEquals(serverGameLogic.getCurrentState(), gameState); @@ -1313,14 +1319,24 @@ public void testStayInSelectPiece() { assertEquals(gameState.getCurrentState(), turnState); //sends the server in ChoosePiece - turnState.setCurrentState(choosePieceState); - assertEquals(turnState.getCurrentState(), choosePieceState); + assertEquals(turnState.getCurrentState(), rollDiceState); - //sends the server in SelectPiece - choosePieceState.setCurrentState(selectPieceState); + game.setDie(new Die(4)); + serverGameLogic.received(new RequestDieMessage(), IDPlayerClient); + serverGameLogic.received(new AnimationEndMessage(), IDPlayerClient); + + //sends the server in StartPiece assertEquals(choosePieceState.getCurrentState(), selectPieceState); - //TODO + serverGameLogic.received(deselectTSK, IDPlayerClient); + serverGameLogic.received(forceContinueGame, IDPlayerClient); + serverGameLogic.received(joinServer, IDPlayerClient); + serverGameLogic.received(lobbyNotReady, IDPlayerClient); + serverGameLogic.received(lobbyReady, IDPlayerClient); + serverGameLogic.received(requestBriefing, IDPlayerClient); + serverGameLogic.received(requestDie, IDPlayerClient); + serverGameLogic.received(selectTSK, IDPlayerClient); + serverGameLogic.received(startGame, IDPlayerClient); //tests if the server is in SelectPiece assertEquals(serverGameLogic.getCurrentState(), gameState); @@ -1335,6 +1351,10 @@ public void testStayInSelectPiece() { */ @Test public void testSelectPieceToMovePiece() { + game.setActiveColor(playerClientColor); + playerClient.setHandCards(new ArrayList<>()); + turnState.setPlayer(playerClient); + //sends the server in GameState serverGameLogic.setCurrentState(gameState); assertEquals(serverGameLogic.getCurrentState(), gameState); @@ -1343,15 +1363,17 @@ public void testSelectPieceToMovePiece() { gameState.setCurrentState(turnState); assertEquals(gameState.getCurrentState(), turnState); - //sends the server in ChoosePiece - turnState.setCurrentState(choosePieceState); - assertEquals(turnState.getCurrentState(), choosePieceState); + //tests the server in rollDiceState + assertEquals(turnState.getCurrentState(), rollDiceState); - //sends the server in SelectPiece - choosePieceState.setCurrentState(selectPieceState); + game.setDie(new Die(4)); + serverGameLogic.received(new RequestDieMessage(), IDPlayerClient); + serverGameLogic.received(new AnimationEndMessage(), IDPlayerClient); + + //tests if the server in selectPiece assertEquals(choosePieceState.getCurrentState(), selectPieceState); - //TODO + serverGameLogic.received(new RequestMoveMessage(pieceClient4), IDPlayerClient); //tests if the server is in movePiece-state assertEquals(serverGameLogic.getCurrentState(), gameState); @@ -1365,6 +1387,12 @@ public void testSelectPieceToMovePiece() { */ @Test public void testStayInStartPiece() { + game.setActiveColor(playerClientColor); + playerClient.setHandCards(new ArrayList<>()); + turnState.setPlayer(playerClient); + game.getBoard().getInfield()[22].clearOccupant(); + game.getBoard().setPieceOnBoard(30, pieceClient4); + //sends the server in GameState serverGameLogic.setCurrentState(gameState); assertEquals(serverGameLogic.getCurrentState(), gameState); @@ -1373,15 +1401,25 @@ public void testStayInStartPiece() { gameState.setCurrentState(turnState); assertEquals(gameState.getCurrentState(), turnState); - //sends the server in ChoosePiece - turnState.setCurrentState(choosePieceState); - assertEquals(turnState.getCurrentState(), choosePieceState); + //tests the server in ChoosePiece + assertEquals(turnState.getCurrentState(), rollDiceState); - //sends the server in StartPiece - choosePieceState.setCurrentState(startPieceState); + game.setDie(new Die(4)); + serverGameLogic.received(new RequestDieMessage(), IDPlayerClient); + serverGameLogic.received(new AnimationEndMessage(), IDPlayerClient); + + //tests the server in StartPiece assertEquals(choosePieceState.getCurrentState(), startPieceState); - //TODO + serverGameLogic.received(deselectTSK, IDPlayerClient); + serverGameLogic.received(forceContinueGame, IDPlayerClient); + serverGameLogic.received(joinServer, IDPlayerClient); + serverGameLogic.received(lobbyNotReady, IDPlayerClient); + serverGameLogic.received(lobbyReady, IDPlayerClient); + serverGameLogic.received(requestBriefing, IDPlayerClient); + serverGameLogic.received(requestDie, IDPlayerClient); + serverGameLogic.received(selectTSK, IDPlayerClient); + serverGameLogic.received(startGame, IDPlayerClient); //tests if the server is in StartPiece assertEquals(serverGameLogic.getCurrentState(), gameState); @@ -1396,6 +1434,12 @@ public void testStayInStartPiece() { */ @Test public void testStartPieceToMovePiece() { + game.setActiveColor(playerClientColor); + playerClient.setHandCards(new ArrayList<>()); + turnState.setPlayer(playerClient); + game.getBoard().getInfield()[22].clearOccupant(); + game.getBoard().setPieceOnBoard(30, pieceClient4); + //sends the server in GameState serverGameLogic.setCurrentState(gameState); assertEquals(serverGameLogic.getCurrentState(), gameState); @@ -1405,14 +1449,16 @@ public void testStartPieceToMovePiece() { assertEquals(gameState.getCurrentState(), turnState); //sends the server in ChoosePiece - turnState.setCurrentState(choosePieceState); - assertEquals(turnState.getCurrentState(), choosePieceState); + assertEquals(turnState.getCurrentState(), rollDiceState); + + game.setDie(new Die(4)); + serverGameLogic.received(new RequestDieMessage(), IDPlayerClient); + serverGameLogic.received(new AnimationEndMessage(), IDPlayerClient); //sends the server in StartPiece - choosePieceState.setCurrentState(startPieceState); assertEquals(choosePieceState.getCurrentState(), startPieceState); - //TODO + serverGameLogic.received(new RequestMoveMessage(pieceClient4), IDPlayerClient); //tests if the server is in movePiece-state assertEquals(serverGameLogic.getCurrentState(), gameState);