diff --git a/Projekte/mdga/model/src/test/java/pp/mdga/game/PieceTest.java b/Projekte/mdga/model/src/test/java/pp/mdga/game/PieceTest.java index 0abc3780..6911471b 100644 --- a/Projekte/mdga/model/src/test/java/pp/mdga/game/PieceTest.java +++ b/Projekte/mdga/model/src/test/java/pp/mdga/game/PieceTest.java @@ -203,17 +203,17 @@ public void disconnectClient(int id) { */ @Test public void testMove() { - //sends the server in selectPiece + //sends the server in firstRoll serverGameLogic.setCurrentState(gameState); - serverGameLogic.getGameState().setCurrentState(turnState); - serverGameLogic.getGameState().getTurnState().setCurrentState(choosePieceState); - serverGameLogic.getGameState().getTurnState().getChoosePieceState().setCurrentState(selectPieceState); + gameState.setCurrentState(turnState); + turnState.setCurrentState(rollDiceState); + rollDiceState.setCurrentState(firstRollState); - //tests if the server is in selectPieces + //tests if the server is in firstRoll assertEquals(serverGameLogic.getCurrentState(),gameState); assertEquals(gameState.getCurrentState(), turnState); - assertEquals(turnState.getCurrentState(),choosePieceState); - assertEquals(choosePieceState.getCurrentState(),selectPieceState); + assertEquals(turnState.getCurrentState(),rollDiceState); + assertEquals(rollDiceState.getCurrentState(),firstRollState); //sets the active Player to host game.setActiveColor(hostColor); @@ -241,17 +241,17 @@ public void testMove() { */ @Test public void testCantMove() { - //sends the server in selectPiece + //sends the server in firstRoll serverGameLogic.setCurrentState(gameState); - serverGameLogic.getGameState().setCurrentState(turnState); - serverGameLogic.getGameState().getTurnState().setCurrentState(choosePieceState); - serverGameLogic.getGameState().getTurnState().getChoosePieceState().setCurrentState(selectPieceState); + gameState.setCurrentState(turnState); + turnState.setCurrentState(rollDiceState); + rollDiceState.setCurrentState(firstRollState); - //tests if the server is in selectPieces + //tests if the server is in firstRoll assertEquals(serverGameLogic.getCurrentState(),gameState); assertEquals(gameState.getCurrentState(), turnState); - assertEquals(turnState.getCurrentState(),choosePieceState); - assertEquals(choosePieceState.getCurrentState(),selectPieceState); + assertEquals(turnState.getCurrentState(),rollDiceState); + assertEquals(rollDiceState.getCurrentState(),firstRollState); //set active player to army game.setActiveColor(clientColor); @@ -293,17 +293,17 @@ public void testNoPossibleMove() { */ @Test public void testThrow() { - //sends the server in selectPiece + //sends the server in firstRoll serverGameLogic.setCurrentState(gameState); - serverGameLogic.getGameState().setCurrentState(turnState); - serverGameLogic.getGameState().getTurnState().setCurrentState(choosePieceState); - serverGameLogic.getGameState().getTurnState().getChoosePieceState().setCurrentState(selectPieceState); + gameState.setCurrentState(turnState); + turnState.setCurrentState(rollDiceState); + rollDiceState.setCurrentState(firstRollState); - //tests if the server is in selectPieces + //tests if the server is in firstRoll assertEquals(serverGameLogic.getCurrentState(),gameState); assertEquals(gameState.getCurrentState(), turnState); - assertEquals(turnState.getCurrentState(),choosePieceState); - assertEquals(choosePieceState.getCurrentState(),selectPieceState); + assertEquals(turnState.getCurrentState(),rollDiceState); + assertEquals(rollDiceState.getCurrentState(),firstRollState); //set active player to host game.setActiveColor(hostColor); @@ -335,17 +335,17 @@ public void testThrow() { */ @Test public void testGetThrown() { - //sends the server in selectPiece + //sends the server in firstRoll serverGameLogic.setCurrentState(gameState); - serverGameLogic.getGameState().setCurrentState(turnState); - serverGameLogic.getGameState().getTurnState().setCurrentState(choosePieceState); - serverGameLogic.getGameState().getTurnState().getChoosePieceState().setCurrentState(selectPieceState); + gameState.setCurrentState(turnState); + turnState.setCurrentState(rollDiceState); + rollDiceState.setCurrentState(firstRollState); - //tests if the server is in selectPieces + //tests if the server is in firstRoll assertEquals(serverGameLogic.getCurrentState(),gameState); assertEquals(gameState.getCurrentState(), turnState); - assertEquals(turnState.getCurrentState(),choosePieceState); - assertEquals(choosePieceState.getCurrentState(),selectPieceState); + assertEquals(turnState.getCurrentState(),rollDiceState); + assertEquals(rollDiceState.getCurrentState(),firstRollState); //set active player to host game.setActiveColor(hostColor); @@ -371,17 +371,17 @@ public void testGetThrown() { */ @Test public void testLeaveWaitingArea() { - //sends the server in selectPiece + //sends the server in firstRoll serverGameLogic.setCurrentState(gameState); - serverGameLogic.getGameState().setCurrentState(turnState); - serverGameLogic.getGameState().getTurnState().setCurrentState(choosePieceState); - serverGameLogic.getGameState().getTurnState().getChoosePieceState().setCurrentState(selectPieceState); + gameState.setCurrentState(turnState); + turnState.setCurrentState(rollDiceState); + rollDiceState.setCurrentState(firstRollState); - //tests if the server is in selectPieces + //tests if the server is in firstRoll assertEquals(serverGameLogic.getCurrentState(),gameState); assertEquals(gameState.getCurrentState(), turnState); - assertEquals(turnState.getCurrentState(),choosePieceState); - assertEquals(choosePieceState.getCurrentState(),selectPieceState); + assertEquals(turnState.getCurrentState(),rollDiceState); + assertEquals(rollDiceState.getCurrentState(),firstRollState); //set active player to host game.setActiveColor(hostColor); @@ -444,23 +444,40 @@ public void testCantLeaveStartingField() { */ @Test public void testReachBonusField() { - // TODO: Implement test logic for when a piece reaches a bonus field - //sends the server in RollDice + //sends the server in firstRoll + serverGameLogic.setCurrentState(gameState); + gameState.setCurrentState(turnState); + turnState.setCurrentState(rollDiceState); + rollDiceState.setCurrentState(firstRollState); + //tests if the server is in firstRoll + assertEquals(serverGameLogic.getCurrentState(),gameState); + assertEquals(gameState.getCurrentState(), turnState); + assertEquals(turnState.getCurrentState(),rollDiceState); + assertEquals(rollDiceState.getCurrentState(),firstRollState); + + //gets the top bonusCard BonusCard card = game.getDrawPile().get(0); + //sets the active Player to Host game.setActiveColor(hostColor); //sets the dice-seed to 4 + game.setDie(die4); //sends the requestDice-Message - serverGameLogic.setCurrentState(serverGameLogic.getGameState()); + serverGameLogic.received(new RequestDieMessage(),IDHost); - //requestMOve of hostPiece3 + //requestMove of hostPiece3 + serverGameLogic.received(new RequestMoveMessage(pieceHost3.getUuid()),IDHost); //tests the position of hostPiece3 + assertTrue(game.getBoard().getInfield()[4].isOccupied()); + assertEquals(game.getBoard().getInfield()[4].getOccupant(),pieceHost3); //tests if the player has received a bonusCard + assertNotEquals(card, game.getDrawPile().get(0)); + assertTrue(game.getPlayers().get(IDHost).getHandCards().stream().toList().contains(card)); } /** @@ -543,7 +560,33 @@ public void testEnterHouse() { */ @Test public void testOnlyEnterOwnHouse() { - // TODO: Implement test logic to ensure a piece can only enter its own house + //sends the server in firstRoll + serverGameLogic.setCurrentState(gameState); + gameState.setCurrentState(turnState); + turnState.setCurrentState(rollDiceState); + rollDiceState.setCurrentState(firstRollState); + + //tests if the server is in firstRoll + assertEquals(serverGameLogic.getCurrentState(),gameState); + assertEquals(gameState.getCurrentState(), turnState); + assertEquals(turnState.getCurrentState(),rollDiceState); + assertEquals(rollDiceState.getCurrentState(),firstRollState); + + //set activePlayer to client + game.setActiveColor(hostColor); + + //set the die in Game to 3 + game.setDie(die3); + + //sends the request-Dice-message + serverGameLogic.received(new RequestDieMessage(),IDHost); + + //sends the requestMove-message for pieceClient1 + serverGameLogic.received(new RequestMoveMessage(pieceHost1.getUuid()),IDHost); + + //tests if hostPiece1 is at idx 20 + assertTrue(game.getBoard().getInfield()[20].isOccupied()); + assertEquals(game.getBoard().getInfield()[20].getOccupant(),pieceHost1); } /** @@ -554,7 +597,33 @@ public void testOnlyEnterOwnHouse() { */ @Test public void testActiveHomePiece() { - // TODO: Implement test logic for activating a piece in the home area + //sends the server in firstRoll + serverGameLogic.setCurrentState(gameState); + gameState.setCurrentState(turnState); + turnState.setCurrentState(rollDiceState); + rollDiceState.setCurrentState(firstRollState); + + //tests if the server is in firstRoll + assertEquals(serverGameLogic.getCurrentState(),gameState); + assertEquals(gameState.getCurrentState(), turnState); + assertEquals(turnState.getCurrentState(),rollDiceState); + assertEquals(rollDiceState.getCurrentState(),firstRollState); + + //set activePlayer to client + game.setActiveColor(clientColor); + + //set the die in Game to 2 + game.setDie(die2); + + //sends the request-Dice-message + serverGameLogic.received(new RequestDieMessage(),IDClient); + + //sends the requestMove-message for pieceClient1 + serverGameLogic.received(new RequestMoveMessage(pieceHost1.getUuid()),IDClient); + + //tests if clientPiece1 is in the home at idx 3 + assertTrue(game.getBoard().getPlayerData().get(clientColor).getHomeNodes()[3].isOccupied()); + assertEquals(game.getBoard().getPlayerData().get(clientColor).getHomeNodes()[3].getOccupant(),pieceClient1); } /** @@ -565,16 +634,33 @@ public void testActiveHomePiece() { */ @Test public void testCantJumpOverFigureInHouse() { - // TODO: Implement test logic to prevent jumping over another piece in the house - //sets the active Player to Client + //sends the server in firstRoll + serverGameLogic.setCurrentState(gameState); + gameState.setCurrentState(turnState); + turnState.setCurrentState(rollDiceState); + rollDiceState.setCurrentState(firstRollState); - //sets the dice-seed to 1 + //tests if the server is in firstRoll + assertEquals(serverGameLogic.getCurrentState(),gameState); + assertEquals(gameState.getCurrentState(), turnState); + assertEquals(turnState.getCurrentState(),rollDiceState); + assertEquals(rollDiceState.getCurrentState(),firstRollState); + + //set activePlayer to client + game.setActiveColor(clientColor); + + //set the die in Game to 4 + game.setDie(die4); //send requestDice-Message + serverGameLogic.received(new RequestDieMessage(),IDClient); //sends requestMoveMessage with clientPiece 02 + serverGameLogic.received(new RequestMoveMessage(pieceHost2.getUuid()),IDHost); - //tests, if the piece is in the first slot of the home + //tests, if the clientPiece02 is at idx 19 + assertTrue(game.getBoard().getInfield()[19].isOccupied()); + assertEquals(game.getBoard().getInfield()[20].getOccupant(),pieceClient2); } /** @@ -596,18 +682,37 @@ public void testActiveHomePieceBlocked() { */ @Test public void testOnStartingFieldWithShield() { - // TODO: Implement test logic for a piece on the starting field with a shield //sets the color to host - //sets the dice-seed to 2 + //sets the dice to 2 + game.setDie(die2); //sets the shield of hostPiece1 true + pieceHost1.setShield(ShieldState.ACTIVE); + + //sends the server in firstRoll + serverGameLogic.setCurrentState(gameState); + gameState.setCurrentState(turnState); + turnState.setCurrentState(rollDiceState); + rollDiceState.setCurrentState(firstRollState); + + //tests if the server is in firstRoll + assertEquals(serverGameLogic.getCurrentState(),gameState); + assertEquals(gameState.getCurrentState(), turnState); + assertEquals(turnState.getCurrentState(),rollDiceState); + assertEquals(rollDiceState.getCurrentState(),firstRollState); //sends the requestDice-message + serverGameLogic.received(new RequestDieMessage(),IDHost); //sends the moveMessage + serverGameLogic.received(new RequestMoveMessage(pieceHost1.getUuid()),IDHost); //tests the position of the hostPiece1 and that shield is suppressed + assertTrue(game.getBoard().getInfield()[20].isOccupied()); + assertEquals(game.getBoard().getInfield()[20].getOccupant(),pieceClient1); + + assertEquals(pieceHost1.getShield(),ShieldState.SUPPRESSED); } /** @@ -627,17 +732,17 @@ public void testThrowFigureWithShield() { //set die to 1 game.setDie(die1); - //sends the server in selectPiece + //sends the server in firstRoll serverGameLogic.setCurrentState(gameState); - serverGameLogic.getGameState().setCurrentState(turnState); - serverGameLogic.getGameState().getTurnState().setCurrentState(choosePieceState); - serverGameLogic.getGameState().getTurnState().getChoosePieceState().setCurrentState(selectPieceState); + gameState.setCurrentState(turnState); + turnState.setCurrentState(rollDiceState); + rollDiceState.setCurrentState(firstRollState); - //tests if the server is in selectPieces + //tests if the server is in firstRoll assertEquals(serverGameLogic.getCurrentState(),gameState); assertEquals(gameState.getCurrentState(), turnState); - assertEquals(turnState.getCurrentState(),choosePieceState); - assertEquals(choosePieceState.getCurrentState(),selectPieceState); + assertEquals(turnState.getCurrentState(),rollDiceState); + assertEquals(rollDiceState.getCurrentState(),firstRollState); //send requestDice serverGameLogic.received(new RequestDieMessage(),IDHost);