added two more tests for the substates of turn to their end-states and added some simulated inputs in the lobby and dialogs

This commit is contained in:
Benjamin Feyer
2024-11-29 16:00:10 +01:00
parent d0361b2759
commit c6462a50ca

View File

@@ -1,32 +1,23 @@
package pp.mdga.client.clientState;
import org.junit.Before;
import org.junit.Test;
import org.junit.*;
import pp.mdga.client.*;
import pp.mdga.client.dialogState.*;
import pp.mdga.client.ceremonyState.*;
import pp.mdga.client.gameState.*;
import pp.mdga.client.gameState.turnState.choosePieceState.NoPieceState;
import pp.mdga.client.gameState.turnState.choosePieceState.SelectPieceState;
import pp.mdga.client.gameState.turnState.choosePieceState.StartPieceState;
import pp.mdga.client.gameState.turnState.choosePieceState.WaitingPieceState;
import pp.mdga.client.settingsState.*;
import pp.mdga.client.gameState.turnState.*;
import pp.mdga.client.gameState.determineStartPlayerState.*;
import pp.mdga.client.gameState.turnState.choosePiece.*;
import pp.mdga.client.gameState.turnState.choosePieceState.*;
import pp.mdga.client.gameState.turnState.powerCardState.*;
import pp.mdga.game.Game;
import pp.mdga.message.server.*;
import pp.mdga.game.BonusCard;
import pp.mdga.game.Color;
import pp.mdga.message.client.ClientMessage;
import java.util.ArrayList;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotEquals;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.*;
/**
* this test-class tests the testcases T170-T239
@@ -101,7 +92,7 @@ public class ClientStateTest {
private UpdateReadyMessage updateReady;
private UpdateTSKMessage updateTSK;
private WaitPieceMessage waitPiece;
private SpectatorMessage spectatorMessage = new SpectatorMessage();
private SpectatorMessage spectatorMessage;
private int from;
private String name;
@@ -162,6 +153,7 @@ public void send(ClientMessage msg) {
updateTSK = new UpdateTSKMessage(name, color);
waitPiece = new WaitPieceMessage();
interruptMessage = new PauseGameMessage();
spectatorMessage = new SpectatorMessage();
//initialize the settings
mainSettings = settings.getMainSettings();
@@ -363,7 +355,8 @@ public void testGameToDialogs() {
clientGameLogic.setState(gameState);
assertEquals(clientGameLogic.getState(), gameState);
//TODO
//receives a GameClosedMessage
clientGameLogic.received();//TODO
assertEquals(clientGameLogic.getState(), dialogs);
assertEquals(dialogs.getState(), startDialog);
@@ -439,7 +432,7 @@ public void testInterruptToDialogs() {
clientGameLogic.setState(interrupt);
assertEquals(clientGameLogic.getState(), interrupt);
//Todo send the server-closed message and the leave option
//Todo send the server-closed
assertEquals(clientGameLogic.getState(), dialogs);
assertEquals(dialogs.getState(), startDialog);
@@ -469,6 +462,11 @@ public void testCeremonyToDialogs() {
*/
@Test
public void testStartDialogToNetworkDialog1() {
/**
* tests the transition from StartDialog to Network-Dialog through button-push
*/
// sends the clientGameLogic in StartDialog
clientGameLogic.setState(dialogs);
assertEquals(clientGameLogic.getState(), dialogs);
@@ -477,7 +475,8 @@ public void testStartDialogToNetworkDialog1() {
dialogs.setState(startDialog);
assertEquals(dialogs.getState(), startDialog);
//todo simulate pushBtn as client or host
//simulate the button-push for the join-Button
clientGameLogic.selectJoin("www");//TODO
assertEquals(clientGameLogic.getState(), dialogs);
assertEquals(dialogs.getState(), networkDialog);
@@ -488,6 +487,10 @@ public void testStartDialogToNetworkDialog1() {
*/
@Test
public void testStartDialogToNetworkDialog2() {
/**
* test if the player can change it's state through btn-push of the host-button
*/
// sends the clientGameLogic in StartDialog
clientGameLogic.setState(dialogs);
assertEquals(clientGameLogic.getState(), dialogs);
@@ -496,7 +499,8 @@ public void testStartDialogToNetworkDialog2() {
dialogs.setState(startDialog);
assertEquals(dialogs.getState(), startDialog);
//todo simulate pushBtn as client or host
//simulate the button-push for the host-Button
clientGameLogic.selectHost("www");//TODO
assertEquals(clientGameLogic.getState(), dialogs);
assertEquals(dialogs.getState(), networkDialog);
@@ -507,8 +511,23 @@ public void testStartDialogToNetworkDialog2() {
*/
@Test
public void testStartDialogToDialogsEndState() {
// Implementation goes here
//TODO how to test?
/**
* test if the player can end it's application through btn-push of the leave-button
*/
// 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
}
/**
@@ -524,8 +543,10 @@ public void testNetworkDialogToStartDialog() {
dialogs.setState(networkDialog);
assertEquals(dialogs.getState(), networkDialog);
//todo simulate pushBtn
//simulate the leave-Btn push
clientGameLogic.selectLeave();
//tests if the client is in startDialog
assertEquals(clientGameLogic.getState(), dialogs);
assertEquals(dialog.getState(), startDialog);
}
@@ -543,8 +564,20 @@ public void testNetworkDialogToNetworkDialog1() {
dialogs.setState(networkDialog);
assertEquals(dialogs.getState(), networkDialog);
//todo test input
//simulate all input, that don't indicate a state-change
clientGameLogic.selectPiece(null);
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 TODO
clientGameLogic.selectAnimationEnd();
clientGameLogic.selectStart();
//tests if the client is still in the network-dialog
assertEquals(clientGameLogic.getState(), dialogs);
assertEquals(dialogs.getState(), networkDialog);
}
@@ -605,8 +638,10 @@ public void testLobbyToStartDialog() {
dialogs.setState(lobby);
assertEquals(dialogs.getState(), lobby);
//todo simulate leave the lobby
//simulate the leave-Btn
clientGameLogic.selectLeave();
//tests if the client is in the Start-Dialog
assertEquals(clientGameLogic.getState(), dialogs);
assertEquals(dialogs.getState(), startDialog);
}
@@ -624,6 +659,18 @@ public void testStayInLobby() {
dialogs.setState(lobby);
assertEquals(dialogs.getState(), lobby);
//simulate all input that don't indicate a state-change
clientGameLogic.selectPiece(null);
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
//sends all messages, which don't indicate a statechange
clientGameLogic.received(activePlayer);
@@ -634,8 +681,8 @@ public void testStayInLobby() {
clientGameLogic.received(diceAgain);
clientGameLogic.received(diceNow);
clientGameLogic.received(endOfTurn);
clientGameLogic.received(lobbyAccept);//Todo rightful message
clientGameLogic.received(lobbyDeny);//Todo rightful message
clientGameLogic.received(lobbyAccept);
clientGameLogic.received(lobbyDeny);
clientGameLogic.received(lobbyPlayerJoin);
clientGameLogic.received(lobbyPlayerLeave);
clientGameLogic.received(moveMessage);
@@ -650,7 +697,7 @@ public void testStayInLobby() {
clientGameLogic.received(rankingRollAgain);
clientGameLogic.received(reconnectBriefing);
clientGameLogic.received(resumeGame);
//clientGameLogic.received(startGame); Todo rightful message
//clientGameLogic.received(startGame); commented because it indicate a state-change to determineStartPlayer
clientGameLogic.received(startPieceMessage);
clientGameLogic.received(updateReady);
clientGameLogic.received(updateTSK);
@@ -817,7 +864,61 @@ public void testWaitToGameEndState() {
*/
@Test
public void testTurnSubStatesToGameEndState() {
// todo 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(rankingResponce);
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
//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);
}
/**
@@ -833,7 +934,61 @@ public void testTurnSubStatesToWait() {
*/
@Test
public void testTurnSubStatesToSpectator() {
// todo 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(rankingResponce);
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
//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);
}
/**
@@ -841,7 +996,56 @@ public void testTurnSubStatesToSpectator() {
*/
@Test
public void testSpectatorToGameEndState() {
// todo 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(rankingResponce);
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);
//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);
}
/**