fixed some tests

This commit is contained in:
Benjamin Feyer
2024-12-10 20:56:08 +01:00
parent 3b73d1229b
commit cc8b2abbde
2 changed files with 47 additions and 24 deletions

View File

@@ -76,4 +76,13 @@ public StatisticsState getStatisticsState(){
public CeremonyStates getState(){ public CeremonyStates getState(){
return currentState; return currentState;
} }
/**
* this method is used to parse the selectNext from the clientGameLogic
*
*/
@Override
public void selectNext(){
currentState.selectNext();
}
} }

View File

@@ -76,6 +76,7 @@ public class ClientStateTest {
//private todo //private todo
//declare server-messages here //declare server-messages here
private ShutdownMessage shutdownMessage;
private ActivePlayerMessage activePlayer; private ActivePlayerMessage activePlayer;
private AnyPieceMessage anyPiece; private AnyPieceMessage anyPiece;
private BriefingMessage briefing; private BriefingMessage briefing;
@@ -110,6 +111,7 @@ public class ClientStateTest {
private SpectatorMessage spectatorMessage; private SpectatorMessage spectatorMessage;
private SelectPieceMessage selectPieceMessage; private SelectPieceMessage selectPieceMessage;
private Color enemyColor;
private int from; private int from;
private String name; private String name;
private Color color; private Color color;
@@ -176,6 +178,9 @@ public void accept(Visitor visitor) {
//declare other player //declare other player
enemy= new Player(name); enemy= new Player(name);
enemy.setColor(Color.CYBER); enemy.setColor(Color.CYBER);
enemyColor=Color.CYBER;
game.addPlayer(2345,enemy);
enemy.initialize();
//sets the player in the game //sets the player in the game
@@ -186,6 +191,7 @@ public void accept(Visitor visitor) {
//initialize the messages from the server //initialize the messages from the server
shutdownMessage = new ShutdownMessage();
activePlayer = new ActivePlayerMessage(color); activePlayer = new ActivePlayerMessage(color);
anyPiece = new AnyPieceMessage(); anyPiece = new AnyPieceMessage();
briefing = new BriefingMessage(); briefing = new BriefingMessage();
@@ -258,6 +264,11 @@ public void accept(Visitor visitor) {
waitingPiece = choosePiece.getWaitingPiece(); waitingPiece = choosePiece.getWaitingPiece();
selectPiece = choosePiece.getSelectPiece(); selectPiece = choosePiece.getSelectPiece();
startPiece = choosePiece.getStartPiece(); startPiece = choosePiece.getStartPiece();
player.initialize();
game.addPlayer(1234,player);
game.setActiveColor(color);
} }
/** /**
@@ -433,7 +444,7 @@ public void testGameToDialogs() {
assertEquals(clientGameLogic.getState(), gameState); assertEquals(clientGameLogic.getState(), gameState);
//receives a GameClosedMessage //receives a GameClosedMessage
//clientGameLogic.received();//TODO clientGameLogic.received(shutdownMessage);
assertEquals(clientGameLogic.getState(), dialogs); assertEquals(clientGameLogic.getState(), dialogs);
assertEquals(dialogs.getState(), startDialog); assertEquals(dialogs.getState(), startDialog);
@@ -493,6 +504,7 @@ public void testClientInterruptToGame() {
//sends the ClientGameLogic in Interrupt //sends the ClientGameLogic in Interrupt
clientGameLogic.setState(interrupt); clientGameLogic.setState(interrupt);
assertEquals(clientGameLogic.getState(), interrupt); assertEquals(clientGameLogic.getState(), interrupt);
interrupt.setPreviousState(gameState);
//sends the continue message //sends the continue message
clientGameLogic.received(resumeGame); clientGameLogic.received(resumeGame);
@@ -510,8 +522,8 @@ public void testInterruptToDialogs() {
clientGameLogic.setState(interrupt); clientGameLogic.setState(interrupt);
assertEquals(clientGameLogic.getState(), interrupt); assertEquals(clientGameLogic.getState(), interrupt);
//Todo send the server-closed //send the server-closed
//clientGameLogic.received(); clientGameLogic.received(shutdownMessage);
//tests if the client is in the startDialog //tests if the client is in the startDialog
assertEquals(clientGameLogic.getState(), dialogs); assertEquals(clientGameLogic.getState(), dialogs);
@@ -553,7 +565,7 @@ public void testStartDialogToNetworkDialog1() {
assertEquals(dialogs.getState(), startDialog); assertEquals(dialogs.getState(), startDialog);
//simulate the button-push for the join-Button //simulate the button-push for the join-Button
clientGameLogic.selectJoin(name); clientGameLogic.selectName(name);
//tests if the client is in the network-dialog //tests if the client is in the network-dialog
assertEquals(clientGameLogic.getState(), dialogs); assertEquals(clientGameLogic.getState(), dialogs);
@@ -578,12 +590,14 @@ public void testStartDialogToNetworkDialog2() {
assertEquals(dialogs.getState(), startDialog); assertEquals(dialogs.getState(), startDialog);
//simulate the button-push for the host-Button //simulate the button-push for the host-Button
clientGameLogic.selectHost(name); clientGameLogic.selectName(name);
//tests if the client is in the network-dialog //tests if the client is in the network-dialog
assertEquals(clientGameLogic.getState(), dialogs); assertEquals(clientGameLogic.getState(), dialogs);
assertEquals(dialogs.getState(), networkDialog); assertEquals(dialogs.getState(), networkDialog);
clientGameLogic.received(new LobbyAcceptMessage(1234));
//tests if the client is host //tests if the client is host
assertTrue(clientGameLogic.isHost()); assertTrue(clientGameLogic.isHost());
} }
@@ -680,6 +694,7 @@ public void testNetworkDialogToNetworkDialog2() {
assertEquals(dialogs.getState(), networkDialog); assertEquals(dialogs.getState(), networkDialog);
//todo simulate try connect to server with send: join-lobby and received lobby-refuse-message //todo simulate try connect to server with send: join-lobby and received lobby-refuse-message
clientGameLogic.received(new LobbyDenyMessage());
assertEquals(clientGameLogic.getState(), dialogs); assertEquals(clientGameLogic.getState(), dialogs);
assertEquals(dialogs.getState(), networkDialog); assertEquals(dialogs.getState(), networkDialog);
@@ -698,7 +713,9 @@ public void testNetworkDialogToLobby() {
dialogs.setState(networkDialog); dialogs.setState(networkDialog);
assertEquals(dialogs.getState(), networkDialog); assertEquals(dialogs.getState(), networkDialog);
//todo simulate connect to server with send lobby request //simulate connect to server with send lobby request
clientGameLogic.selectJoin("IP");
clientGameLogic.received(new LobbyAcceptMessage(1234) );
assertEquals(clientGameLogic.getState(), dialogs); assertEquals(clientGameLogic.getState(), dialogs);
assertEquals(dialogs.getState(), lobby); assertEquals(dialogs.getState(), lobby);
@@ -827,8 +844,18 @@ public void testDetermineStartPlayerToWait() {
gameState.setState(determineStartPlayer); gameState.setState(determineStartPlayer);
assertEquals(gameState.getState(), determineStartPlayer); assertEquals(gameState.getState(), determineStartPlayer);
//sends the determineStartPlayer into WaitRanking
determineStartPlayer.setState(waitRanking);
assertEquals(determineStartPlayer.getState(), waitRanking);
//sends the message, that indicate a statechange to wait //sends the message, that indicate a statechange to wait
clientGameLogic.received(noTurn); clientGameLogic.received(activePlayer);
clientGameLogic.selectAnimationEnd();
//tests if the
assertEquals(clientGameLogic.getState(), gameState);
assertEquals(gameState.getState(), determineStartPlayer);
assertEquals(determineStartPlayer.getState(),determineStartPlayer.getIntro());
//tests if the client is in the Wait-State //tests if the client is in the Wait-State
assertEquals(clientGameLogic.getState(), gameState); assertEquals(clientGameLogic.getState(), gameState);
@@ -895,6 +922,7 @@ public void testWaitToAnimation() {
@Test @Test
public void testWaitToTurn() { public void testWaitToTurn() {
//sends client in gameState //sends client in gameState
game.setActiveColor(enemyColor);
clientGameLogic.setState(gameState); clientGameLogic.setState(gameState);
assertEquals(clientGameLogic.getState(), gameState); assertEquals(clientGameLogic.getState(), gameState);
@@ -2721,7 +2749,6 @@ public void testRollRankingDiceToWaitRanking() {
clientGameLogic.received(activePlayer); clientGameLogic.received(activePlayer);
clientGameLogic.received(anyPiece); clientGameLogic.received(anyPiece);
clientGameLogic.received(briefing); clientGameLogic.received(briefing);
clientGameLogic.received(ceremonyMessage);
//clientGameLogic.received(die); //clientGameLogic.received(die);
clientGameLogic.received(diceAgain); clientGameLogic.received(diceAgain);
clientGameLogic.received(diceNow); clientGameLogic.received(diceNow);
@@ -2785,25 +2812,19 @@ public void testWaitRankingToRollRankingDice() {
clientGameLogic.received(activePlayer); clientGameLogic.received(activePlayer);
clientGameLogic.received(anyPiece); clientGameLogic.received(anyPiece);
clientGameLogic.received(briefing); clientGameLogic.received(briefing);
clientGameLogic.received(ceremonyMessage);
clientGameLogic.received(die); clientGameLogic.received(die);
clientGameLogic.received(diceAgain);
clientGameLogic.received(diceNow);
//clientGameLogic.received(endOfTurn);
clientGameLogic.received(lobbyAccept); clientGameLogic.received(lobbyAccept);
clientGameLogic.received(lobbyDeny); clientGameLogic.received(lobbyDeny);
clientGameLogic.received(lobbyPlayerJoin); clientGameLogic.received(lobbyPlayerJoin);
clientGameLogic.received(lobbyPlayerLeave); clientGameLogic.received(lobbyPlayerLeave);
clientGameLogic.received(moveMessage); clientGameLogic.received(moveMessage);
clientGameLogic.received(noTurn); clientGameLogic.received(noTurn);
//clientGameLogic.received(interruptMessage);
clientGameLogic.received(playCardSwap); clientGameLogic.received(playCardSwap);
clientGameLogic.received(playCardShield); clientGameLogic.received(playCardShield);
clientGameLogic.received(playCardTurbo); clientGameLogic.received(playCardTurbo);
clientGameLogic.received(possibleCard); clientGameLogic.received(possibleCard);
clientGameLogic.received(possiblePiece); clientGameLogic.received(possiblePiece);
clientGameLogic.received(rankingResponse); clientGameLogic.received(rankingResponse);
//clientGameLogic.received(rankingRollAgain);
clientGameLogic.received(reconnectBriefing); clientGameLogic.received(reconnectBriefing);
clientGameLogic.received(resumeGame); clientGameLogic.received(resumeGame);
clientGameLogic.received(startGame); clientGameLogic.received(startGame);
@@ -2820,7 +2841,7 @@ public void testWaitRankingToRollRankingDice() {
assertEquals(determineStartPlayer.getState(), waitRanking); assertEquals(determineStartPlayer.getState(), waitRanking);
//sends rankingRollAgain-message //sends rankingRollAgain-message
clientGameLogic.received(rankingRollAgain); clientGameLogic.received(diceNow);
//test if the client is in rollRankingDice //test if the client is in rollRankingDice
assertEquals(clientGameLogic.getState(), gameState); assertEquals(clientGameLogic.getState(), gameState);
@@ -2846,13 +2867,9 @@ public void testWaitRankingToEndStateDetermineStartingPlayer() {
assertEquals(determineStartPlayer.getState(), waitRanking); assertEquals(determineStartPlayer.getState(), waitRanking);
//sends all messages that don't indicate a state-change //sends all messages that don't indicate a state-change
clientGameLogic.received(activePlayer);
clientGameLogic.received(anyPiece); clientGameLogic.received(anyPiece);
clientGameLogic.received(briefing); clientGameLogic.received(briefing);
clientGameLogic.received(ceremonyMessage);
clientGameLogic.received(die); clientGameLogic.received(die);
clientGameLogic.received(diceAgain);
clientGameLogic.received(diceNow);
//clientGameLogic.received(endOfTurn); //clientGameLogic.received(endOfTurn);
clientGameLogic.received(lobbyAccept); clientGameLogic.received(lobbyAccept);
clientGameLogic.received(lobbyDeny); clientGameLogic.received(lobbyDeny);
@@ -2860,21 +2877,18 @@ public void testWaitRankingToEndStateDetermineStartingPlayer() {
clientGameLogic.received(lobbyPlayerLeave); clientGameLogic.received(lobbyPlayerLeave);
clientGameLogic.received(moveMessage); clientGameLogic.received(moveMessage);
clientGameLogic.received(noTurn); clientGameLogic.received(noTurn);
//clientGameLogic.received(interruptMessage);
clientGameLogic.received(playCardSwap); clientGameLogic.received(playCardSwap);
clientGameLogic.received(playCardShield); clientGameLogic.received(playCardShield);
clientGameLogic.received(playCardTurbo); clientGameLogic.received(playCardTurbo);
clientGameLogic.received(possibleCard); clientGameLogic.received(possibleCard);
clientGameLogic.received(possiblePiece); clientGameLogic.received(possiblePiece);
clientGameLogic.received(rankingResponse); clientGameLogic.received(rankingResponse);
//clientGameLogic.received(rankingRollAgain);
clientGameLogic.received(reconnectBriefing); clientGameLogic.received(reconnectBriefing);
clientGameLogic.received(resumeGame); clientGameLogic.received(resumeGame);
clientGameLogic.received(startGame); clientGameLogic.received(startGame);
clientGameLogic.received(startPieceMessage); clientGameLogic.received(startPieceMessage);
clientGameLogic.received(updateReady); clientGameLogic.received(updateReady);
clientGameLogic.received(updateTSK); clientGameLogic.received(updateTSK);
clientGameLogic.received(waitPiece);
clientGameLogic.received(spectatorMessage); clientGameLogic.received(spectatorMessage);
clientGameLogic.received(selectPieceMessage); clientGameLogic.received(selectPieceMessage);
@@ -2883,8 +2897,8 @@ public void testWaitRankingToEndStateDetermineStartingPlayer() {
assertEquals(gameState.getState(), determineStartPlayer); assertEquals(gameState.getState(), determineStartPlayer);
assertEquals(determineStartPlayer.getState(), waitRanking); assertEquals(determineStartPlayer.getState(), waitRanking);
//sends endOfTurn-message //sends endOfTurn-message todo intro
clientGameLogic.received(endOfTurn); clientGameLogic.received(activePlayer);
//test if the client is in wait //test if the client is in wait
assertEquals(clientGameLogic.getState(), gameState); assertEquals(clientGameLogic.getState(), gameState);