From 23d4bf31a70d058988d3a2cf0d180765fd61e327 Mon Sep 17 00:00:00 2001 From: Benjamin Feyer Date: Fri, 13 Dec 2024 05:49:23 +0100 Subject: [PATCH] added testcase T004 --- .../src/test/java/pp/mdga/game/GameTest.java | 92 ++++++++++++++++++- 1 file changed, 90 insertions(+), 2 deletions(-) diff --git a/Projekte/mdga/model/src/test/java/pp/mdga/game/GameTest.java b/Projekte/mdga/model/src/test/java/pp/mdga/game/GameTest.java index b8a2dcf1..e29939b2 100644 --- a/Projekte/mdga/model/src/test/java/pp/mdga/game/GameTest.java +++ b/Projekte/mdga/model/src/test/java/pp/mdga/game/GameTest.java @@ -269,10 +269,98 @@ public void testGameFinishes() { assertEquals(logic.getCurrentState(), logic.getCeremonyState()); } - // UC-Game-03 + /** + * this test-method is used to test, when a player finishes + *

+ * T003 + */ @Test public void testPlayerFinishes() { - // TODO: Implement test logic for player finishes + //tests if both player have no color and are not ready + assertFalse(playerClient.isReady()); + assertFalse(playerHost.isReady()); + assertEquals(playerClient.getColor(), Color.NONE); + assertEquals(playerHost.getColor(), Color.NONE); + + //send the selectTSK-message + logic.received(new SelectTSKMessage(Color.CYBER), IDClient); + logic.received(new SelectTSKMessage(Color.ARMY), IDHost); + + //sends and tests the readyMessage for the client + logic.received(new LobbyReadyMessage(), IDClient); + logic.received(new LobbyReadyMessage(), IDHost); + assertTrue(playerClient.isReady()); + assertTrue(playerHost.isReady()); + + //tests if the game has started after the gameStartMessage + logic.received(new StartGameMessage(), IDHost); + assertEquals(logic.getCurrentState(), logic.getGameState()); + + //roll the order + game.setDie(new Die(4)); + logic.received(new RequestDieMessage(), IDHost); + game.setDie(new Die(3)); + logic.received(new RequestDieMessage(), IDClient); + logic.received(new AnimationEndMessage(), IDClient); + logic.received(new AnimationEndMessage(), IDHost); + + //tests that the server is in the animation-state + assertEquals(logic.getCurrentState(), logic.getGameState()); + assertEquals(logic.getGameState().getCurrentState(), logic.getGameState().getAnimationState()); + + logic.received(new AnimationEndMessage(), IDHost); + logic.received(new AnimationEndMessage(), IDClient); + + //set all pieces except one in the home, the other direct in front of the home + Piece piece1 = game.getBoard().getInfield()[playerHost.getStartNodeIndex()].getOccupant(); + Piece piece2 = playerHost.getWaitingArea()[1]; + Piece piece3 = playerHost.getWaitingArea()[2]; + Piece piece4 = playerHost.getWaitingArea()[3]; + piece1.setState(PieceState.HOMEFINISHED); + piece2.setState(PieceState.HOMEFINISHED); + piece3.setState(PieceState.HOMEFINISHED); + piece4.setState(PieceState.ACTIVE); + playerHost.removeWaitingPiece(piece1); + playerHost.removeWaitingPiece(piece2); + playerHost.removeWaitingPiece(piece3); + playerHost.removeWaitingPiece(piece4); + playerHost.setPieceInHome(3,piece1); + playerHost.setPieceInHome(2,piece2); + playerHost.setPieceInHome(1,piece3); + + game.getBoard().getInfield()[playerHost.getStartNodeIndex()-1].setOccupant(piece4); + + logic.received(new NoPowerCardMessage(), IDHost); + + //tests if the server is in first-roll + assertEquals(logic.getCurrentState(), logic.getGameState()); + assertEquals(logic.getGameState().getCurrentState(), logic.getGameState().getTurnState()); + TurnState turn = logic.getGameState().getTurnState(); + assertEquals(turn.getCurrentState(), turn.getRollDiceState()); + RollDiceState rollDiceState = turn.getRollDiceState(); + assertEquals(rollDiceState.getCurrentState(), rollDiceState.getFirstRollState()); + + game.setDie(new Die(1)); + logic.received(new RequestDieMessage(), IDHost); + logic.received(new AnimationEndMessage(), IDHost); + + //tests if the server is in choose-piece-state + assertEquals(logic.getCurrentState(), logic.getGameState()); + assertEquals(logic.getGameState().getCurrentState(), logic.getGameState().getTurnState()); + assertEquals(turn.getCurrentState(), turn.getChoosePieceState()); + assertEquals(turn.getChoosePieceState().getSelectPieceState(), turn.getChoosePieceState().getCurrentState()); + + logic.received(new RequestMoveMessage(piece4),IDHost); + //tests if the server is in choose-piece-state + assertEquals(logic.getCurrentState(), logic.getGameState()); + assertEquals(logic.getGameState().getCurrentState(), logic.getGameState().getTurnState()); + assertEquals(turn.getCurrentState(), turn.getMovePieceState()); + + + logic.received(new AnimationEndMessage(),IDHost); + logic.received(new AnimationEndMessage(),IDClient); + + assertTrue(playerHost.isFinished()); } /**