fixed some tests

This commit is contained in:
Benjamin Feyer
2024-12-12 01:02:55 +01:00
parent a6215b9986
commit af8ab21e5f

View File

@@ -27,6 +27,8 @@
import pp.mdga.server.automaton.game.turn.rolldice.ThirdRollState; import pp.mdga.server.automaton.game.turn.rolldice.ThirdRollState;
import pp.mdga.visitor.Visitor; import pp.mdga.visitor.Visitor;
import java.util.List;
import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertEquals;
/** /**
@@ -115,6 +117,8 @@ public class ServerStateTest {
private TurnState turnState; private TurnState turnState;
private WaitingPieceState waitingPieceState; private WaitingPieceState waitingPieceState;
private SelectedPiecesMessage selectedPiecesMessage;
/** /**
* this method is used to initialize the attributes of this test-class * this method is used to initialize the attributes of this test-class
@@ -124,7 +128,11 @@ public void setUp() {
game = new Game(); game = new Game();
//initialize two players //initialize two players
playerHost = new Player("Host"); playerHost = new Player("Host");
playerHost.addHandCard(new ShieldCard()); PowerCard shield= new ShieldCard();
selectCard = new SelectCardMessage(shield);
playerHost.addHandCard(shield);
playerHost.addHandCard(new SwapCard()); playerHost.addHandCard(new SwapCard());
playerHost.addHandCard(new TurboCard()); playerHost.addHandCard(new TurboCard());
playerHost.initialize(); playerHost.initialize();
@@ -140,6 +148,7 @@ public void setUp() {
hostPiece1.setState(PieceState.ACTIVE); hostPiece1.setState(PieceState.ACTIVE);
game.getBoard().setPieceOnBoard(35,hostPiece2); game.getBoard().setPieceOnBoard(35,hostPiece2);
hostPiece2.setState(PieceState.ACTIVE); hostPiece2.setState(PieceState.ACTIVE);
selectedPiecesMessage = new SelectedPiecesMessage(List.of(hostPiece2));
@@ -182,9 +191,6 @@ public void shutdown() {
} }
}, game); }, game);
game.setActiveColor(playerClientColor);
//initialize a piece for client //initialize a piece for client
IDPiece = 3; IDPiece = 3;
pieceState = PieceState.ACTIVE; pieceState = PieceState.ACTIVE;
@@ -264,6 +270,8 @@ public void accept(Visitor visitor) {
/** /**
* this test-method tests, that the server, when initialized, is in the Lobby-state * this test-method tests, that the server, when initialized, is in the Lobby-state
*
* serverStateTest1
*/ */
@Test @Test
public void testInitialStateServerState() { public void testInitialStateServerState() {
@@ -274,6 +282,8 @@ public void testInitialStateServerState() {
/** /**
* this method tests that the server, if all players are ready and the startGameMessage is issued, * this method tests that the server, if all players are ready and the startGameMessage is issued,
* changes into the DetermineStartPlayer-state * changes into the DetermineStartPlayer-state
*
* serverStateTest2
*/ */
@Test @Test
public void testLobbyToDetermineStartPlayer() { public void testLobbyToDetermineStartPlayer() {
@@ -316,6 +326,8 @@ public void testLobbyToDetermineStartPlayer() {
/** /**
* this method tests, that the server stays in the Lobby * this method tests, that the server stays in the Lobby
*
* serverStateTest3
*/ */
@Test @Test
public void testStayInLobby() { public void testStayInLobby() {
@@ -344,6 +356,8 @@ public void testStayInLobby() {
/** /**
* this method tests, that the server can go into the interrupt-state * this method tests, that the server can go into the interrupt-state
*
* serverStateTest4
*/ */
@Test @Test
public void testServerGameSubStatesToInterrupt() { public void testServerGameSubStatesToInterrupt() {
@@ -360,6 +374,8 @@ public void testServerGameSubStatesToInterrupt() {
/** /**
* tests the state-change IDPlayerClient Game to Ceremony if the Game is finished * tests the state-change IDPlayerClient Game to Ceremony if the Game is finished
*
* serverStateTest5
*/ */
@Test @Test
public void testServerGameToCeremony() { public void testServerGameToCeremony() {
@@ -375,6 +391,8 @@ public void testServerGameToCeremony() {
/** /**
* this method tests that the server goes back to the Game, when the ForceStartGame-message is issued * this method tests that the server goes back to the Game, when the ForceStartGame-message is issued
*
* serverStateTest6
*/ */
@Test @Test
public void testInterruptToGameContinue() { public void testInterruptToGameContinue() {
@@ -412,6 +430,8 @@ public void testInterruptToGameContinue() {
/** /**
* this method tests, that the server goes back to the game, if the missing client has reconnected * this method tests, that the server goes back to the game, if the missing client has reconnected
*
* serverStateTest7
*/ */
@Test @Test
public void testInterruptToGameReconnect() { public void testInterruptToGameReconnect() {
@@ -427,6 +447,8 @@ public void testInterruptToGameReconnect() {
/** /**
* this method tests, that th e server continues with the game, if there is no time left on the timer * this method tests, that th e server continues with the game, if there is no time left on the timer
*
* serverStateTest8
*/ */
@Test @Test
public void testInterruptToGameTimer() { public void testInterruptToGameTimer() {
@@ -442,6 +464,8 @@ public void testInterruptToGameTimer() {
/** /**
* this method tests, that the server closes, if the ceremony has ended * this method tests, that the server closes, if the ceremony has ended
*
* serverStateTest9
*/ */
@Test @Test
public void testCeremonyToServerStateEndState() { public void testCeremonyToServerStateEndState() {
@@ -525,6 +549,8 @@ public void testDetermineStartPlayerToDetermineStartPlayer2() {
/** /**
* this method tests that the server goes into Animation-state, if there is an order * this method tests that the server goes into Animation-state, if there is an order
*
* serverStateTest12
*/ */
@Test @Test
public void testDetermineStartPlayerToAnimation() { public void testDetermineStartPlayerToAnimation() {
@@ -558,6 +584,8 @@ public void testDetermineStartPlayerToAnimation() {
/** /**
* tests that the server goes IDPlayerClient 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 * and all players have issued a animationEndMessage
*
* serverStateTest13
*/ */
@Test @Test
public void testAnimationToPowerCard() { public void testAnimationToPowerCard() {
@@ -587,6 +615,8 @@ 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 * 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 * least two player left
*
* serverStateTest14
*/ */
@Test @Test
public void testTurnToAnimation() { public void testTurnToAnimation() {
@@ -624,6 +654,8 @@ public void testTurnToAnimation() {
/** /**
* this method tests that the server changes it's state IDPlayerClient 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 * if there is only one player left
*
* serverStateTest15
*/ */
@Test @Test
public void testTurnToGameEndState() { public void testTurnToGameEndState() {
@@ -644,6 +676,8 @@ public void testTurnToGameEndState() {
/** /**
* this method tests that the server don't change it's state whe issued with messages, * this method tests that the server don't change it's state whe issued with messages,
* which don't implicate a statechange * which don't implicate a statechange
*
* serverStateTest16
*/ */
@Test @Test
public void testStayInPowerCard() { public void testStayInPowerCard() {
@@ -660,17 +694,14 @@ public void testStayInPowerCard() {
assertEquals(turnState.getCurrentState(), powerCardState); assertEquals(turnState.getCurrentState(), powerCardState);
//receive messages which don't lead to a state change //receive messages which don't lead to a state change
serverGameLogic.received(animationEnd, IDPlayerClient);
serverGameLogic.received(deselectTSK, IDPlayerClient); serverGameLogic.received(deselectTSK, IDPlayerClient);
serverGameLogic.received(forceContinueGame, IDPlayerClient); serverGameLogic.received(forceContinueGame, IDPlayerClient);
serverGameLogic.received(joinServer, IDPlayerClient); serverGameLogic.received(joinServer, IDPlayerClient);
serverGameLogic.received(lobbyNotReady, IDPlayerClient); serverGameLogic.received(lobbyNotReady, IDPlayerClient);
serverGameLogic.received(lobbyReady, IDPlayerClient); serverGameLogic.received(lobbyReady, IDPlayerClient);
serverGameLogic.received(noPowerCard, IDPlayerClient);
serverGameLogic.received(requestBriefing, IDPlayerClient); serverGameLogic.received(requestBriefing, IDPlayerClient);
serverGameLogic.received(requestDie, IDPlayerClient); serverGameLogic.received(requestDie, IDPlayerClient);
serverGameLogic.received(requestMove, IDPlayerClient); serverGameLogic.received(requestMove, IDPlayerClient);
serverGameLogic.received(selectCard, IDPlayerClient);
serverGameLogic.received(selectTSK, IDPlayerClient); serverGameLogic.received(selectTSK, IDPlayerClient);
serverGameLogic.received(startGame, IDPlayerClient); serverGameLogic.received(startGame, IDPlayerClient);
@@ -698,8 +729,12 @@ public void testPowerCardToPlayPowerCard() {
turnState.setCurrentState(powerCardState); turnState.setCurrentState(powerCardState);
assertEquals(turnState.getCurrentState(), powerCardState); assertEquals(turnState.getCurrentState(), powerCardState);
//todo //sends the server in shieldState
serverGameLogic.received(selectCard, IDPlayerClient); powerCardState.setCurrentState(powerCardState.getShieldCardState());
assertEquals(powerCardState.getCurrentState(), powerCardState.getShieldCardState());
//
serverGameLogic.received(selectedPiecesMessage, IDPlayerHost);
//tests if the server is in PlayPowerCard //tests if the server is in PlayPowerCard
assertEquals(serverGameLogic.getCurrentState(), gameState); assertEquals(serverGameLogic.getCurrentState(), gameState);
@@ -797,7 +832,7 @@ public void testMovePieceToTurnEndState() {
@Test @Test
public void testMovePieceToFirstRoll() { public void testMovePieceToFirstRoll() {
//sets the die to 6 //sets the die to 6
game.setDie(new Die(6)); game.setDiceEyes(6);
//sends the server in Game-State //sends the server in Game-State
serverGameLogic.setCurrentState(gameState); serverGameLogic.setCurrentState(gameState);
@@ -831,6 +866,8 @@ public void testMovePieceToFirstRoll() {
*/ */
@Test @Test
public void testFirstRollToRollDiceEndState() { public void testFirstRollToRollDiceEndState() {
//sends the server in Game-State //sends the server in Game-State
serverGameLogic.setCurrentState(gameState); serverGameLogic.setCurrentState(gameState);
assertEquals(serverGameLogic.getCurrentState(), gameState); assertEquals(serverGameLogic.getCurrentState(), gameState);
@@ -878,7 +915,11 @@ public void testFirstRollToSecondRoll() {
rollDiceState.setCurrentState(firstRollState); rollDiceState.setCurrentState(firstRollState);
assertEquals(rollDiceState.getCurrentState(), firstRollState); assertEquals(rollDiceState.getCurrentState(), firstRollState);
game.setDie(new Die(5));
game.setDiceEyes(5);
//Todo player has no figures to move and had no 6 //Todo player has no figures to move and had no 6
serverGameLogic.received(requestDie, IDPlayerHost);
serverGameLogic.received(animationEnd, IDPlayerHost);
//tests if the server is in the SecondRoll //tests if the server is in the SecondRoll
assertEquals(serverGameLogic.getCurrentState(), gameState); assertEquals(serverGameLogic.getCurrentState(), gameState);
@@ -893,7 +934,6 @@ public void testFirstRollToSecondRoll() {
*/ */
@Test @Test
public void testSecondRollToRollDiceEndState() { public void testSecondRollToRollDiceEndState() {
//sends the server in Game-State
serverGameLogic.setCurrentState(gameState); serverGameLogic.setCurrentState(gameState);
assertEquals(serverGameLogic.getCurrentState(), gameState); assertEquals(serverGameLogic.getCurrentState(), gameState);
@@ -909,7 +949,7 @@ public void testSecondRollToRollDiceEndState() {
rollDiceState.setCurrentState(secondRollState); rollDiceState.setCurrentState(secondRollState);
assertEquals(rollDiceState.getCurrentState(), secondRollState); assertEquals(rollDiceState.getCurrentState(), secondRollState);
//Todo //TODO
//tests if the server is in NoPiece of ChoosePiece //tests if the server is in NoPiece of ChoosePiece
assertEquals(serverGameLogic.getCurrentState(), gameState); assertEquals(serverGameLogic.getCurrentState(), gameState);
@@ -940,7 +980,11 @@ public void testSecondRollToThirdRoll() {
rollDiceState.setCurrentState(secondRollState); rollDiceState.setCurrentState(secondRollState);
assertEquals(rollDiceState.getCurrentState(), secondRollState); assertEquals(rollDiceState.getCurrentState(), secondRollState);
//Todo player has no figures to move and had no 6 game.setDie(new Die(5));
game.setDiceEyes(5);
//player has no figures to move and had no 6
serverGameLogic.received(requestDie, IDPlayerHost);
serverGameLogic.received(animationEnd, IDPlayerHost);
//tests if the server is in the ThirdRoll //tests if the server is in the ThirdRoll
assertEquals(serverGameLogic.getCurrentState(), gameState); assertEquals(serverGameLogic.getCurrentState(), gameState);