added some logic to the tests

This commit is contained in:
Benjamin Feyer
2024-12-03 06:35:45 +01:00
parent 9ef897f873
commit ee70699150
2 changed files with 40 additions and 5 deletions

View File

@@ -234,7 +234,9 @@ public void testInitialStateClientState() {
public void testDialogsToGame() { public void testDialogsToGame() {
//tests if the client is in Dialogs //tests if the client is in Dialogs
clientGameLogic.setState(dialogs); clientGameLogic.setState(dialogs);
dialogs.setState(lobby);
assertEquals(clientGameLogic.getState(), dialogs); assertEquals(clientGameLogic.getState(), dialogs);
assertEquals(dialogs.getState(), lobby);
//sends all messages, which don't indicate a statechange //sends all messages, which don't indicate a statechange
clientGameLogic.received(activePlayer); clientGameLogic.received(activePlayer);
@@ -263,8 +265,8 @@ public void testDialogsToGame() {
clientGameLogic.received(resumeGame); clientGameLogic.received(resumeGame);
//clientGameLogic.received(startGame); //clientGameLogic.received(startGame);
clientGameLogic.received(startPieceMessage); clientGameLogic.received(startPieceMessage);
clientGameLogic.received(updateReady); //clientGameLogic.received(updateReady);todo
clientGameLogic.received(updateTSK); //clientGameLogic.received(updateTSK);
clientGameLogic.received(waitPiece); clientGameLogic.received(waitPiece);
clientGameLogic.received(spectatorMessage); clientGameLogic.received(spectatorMessage);
clientGameLogic.received(selectPieceMessage); clientGameLogic.received(selectPieceMessage);

View File

@@ -1,5 +1,7 @@
package pp.mdga.server.serverstate; package pp.mdga.server.serverstate;
//TODO important: set activePlayer, setPlayers, setPieces, setBonusCards
import org.junit.*; import org.junit.*;
import pp.mdga.game.*; import pp.mdga.game.*;
import pp.mdga.message.server.ServerMessage; import pp.mdga.message.server.ServerMessage;
@@ -200,6 +202,11 @@ public void disconnectClient(int id) {
waitingPieceState = choosePieceState.getWaitingPieceState(); waitingPieceState = choosePieceState.getWaitingPieceState();
startPieceState = choosePieceState.getStartPieceState(); startPieceState = choosePieceState.getStartPieceState();
selectPieceState = choosePieceState.getSelectPieceState(); selectPieceState = choosePieceState.getSelectPieceState();
/*
* this attribute is used, so the server knows, that always it's the host's turn
*/
game.setActiveColor(playerHostColor);
} }
/** /**
@@ -454,7 +461,13 @@ public void testDetermineStartPlayerToDetermineStartPlayer2() {
gameState.setCurrentState(determineStartPlayerState); gameState.setCurrentState(determineStartPlayerState);
assertEquals(gameState.getCurrentState(), determineStartPlayerState); assertEquals(gameState.getCurrentState(), determineStartPlayerState);
//TODO sends messages 2 requestDieMessage, die gleich geränkt werden to the server //set die to 6
game.setDie(new Die(6));
//sends the two requestDiceMessages
serverGameLogic.received(requestDie, IDPlayerClient);
serverGameLogic.received(requestDie, IDPlayerHost);
//sends the requestDieMessage to the server //sends the requestDieMessage to the server
gameState.received(requestDie, IDPlayerClient); gameState.received(requestDie, IDPlayerClient);
@@ -483,7 +496,17 @@ public void testDetermineStartPlayerToAnimation() {
gameState.setCurrentState(determineStartPlayerState); gameState.setCurrentState(determineStartPlayerState);
assertEquals(gameState.getCurrentState(), determineStartPlayerState); assertEquals(gameState.getCurrentState(), determineStartPlayerState);
//TODO sends messages 2 requestDieMessage, die ungleich geränkt werden, sodass der server weitergeht //set die to 6
game.setDie(new Die(6));
//sends the two requestDiceMessages
serverGameLogic.received(requestDie, IDPlayerClient);
//set die to 6
game.setDie(new Die(5));
//sends the two requestDiceMessages
serverGameLogic.received(requestDie, IDPlayerClient);
//tests if the Server is in animationState //tests if the Server is in animationState
assertEquals(serverGameLogic.getCurrentState(), gameState); assertEquals(serverGameLogic.getCurrentState(), gameState);
@@ -637,6 +660,7 @@ public void testPowerCardToPlayPowerCard() {
assertEquals(turnState.getCurrentState(), powerCardState); assertEquals(turnState.getCurrentState(), powerCardState);
//todo //todo
serverGameLogic.received(selectCard, IDPlayerClient);
//tests if the server is in PlayPowerCard //tests if the server is in PlayPowerCard
assertEquals(serverGameLogic.getCurrentState(), gameState); assertEquals(serverGameLogic.getCurrentState(), gameState);
@@ -732,6 +756,9 @@ public void testMovePieceToTurnEndState() {
*/ */
@Test @Test
public void testMovePieceToFirstRoll() { public void testMovePieceToFirstRoll() {
//sets the die to 6
game.setDie(new Die(6));
//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);
@@ -744,12 +771,18 @@ public void testMovePieceToFirstRoll() {
turnState.setCurrentState(movePieceState); turnState.setCurrentState(movePieceState);
assertEquals(turnState.getCurrentState(), movePieceState); assertEquals(turnState.getCurrentState(), movePieceState);
//Todo the player rolled a 6 and the player is not finished //sends the animationEndMessage
serverGameLogic.received(animationEnd, IDPlayerClient);
serverGameLogic.received(animationEnd, IDPlayerHost);
//tests if the server is in firstRoll
assertEquals(serverGameLogic.getCurrentState(), gameState); assertEquals(serverGameLogic.getCurrentState(), gameState);
assertEquals(gameState.getCurrentState(), turnState); assertEquals(gameState.getCurrentState(), turnState);
assertEquals(turnState.getCurrentState(), rollDiceState); assertEquals(turnState.getCurrentState(), rollDiceState);
assertEquals(rollDiceState.getCurrentState(), firstRollState); assertEquals(rollDiceState.getCurrentState(), firstRollState);
//tests if the activeColor is still Host
assertEquals(game.getActiveColor(),playerHostColor);
} }
/** /**