edited some tests for the server

This commit is contained in:
Benjamin Feyer
2024-12-13 02:18:45 +01:00
parent ea3f4df636
commit 911ab42101

View File

@@ -1,7 +1,5 @@
package pp.mdga.server.serverState;
//TODO important: set activePlayer, setPlayers, setPieces, setBonusCards
import org.junit.Before;
import org.junit.Test;
import pp.mdga.game.*;
@@ -30,9 +28,7 @@
import java.util.ArrayList;
import java.util.List;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotSame;
import static org.junit.Assert.*;
/**
* this test-class tests the Testcases T132-T169
@@ -79,7 +75,6 @@ public class ServerStateTest {
private Piece piece;
private PieceState pieceState;
private int IDPiece;
private Piece hostPiece1;
private Piece hostPiece2;
@@ -88,11 +83,8 @@ public class ServerStateTest {
//declare 3 pieces in home from client
private Piece pieceHome1;
private int IDPiece1;
private Piece pieceHome2;
private int IDPiece2;
private Piece pieceHome3;
private int IDPiece3;
private Piece pieceClient4;
//todo declare a card for client
@@ -188,15 +180,11 @@ public void shutdown() {
}, game);
//initialize a piece for client
IDPiece = 3;
pieceState = PieceState.ACTIVE;
piece = new Piece(playerClientColor, pieceState);
game.getBoard().setPieceOnBoard(15, piece); //sets the piece at inx 12, bc the home begins after inx 19
//initialize the other 3 House-Pieces
IDPiece1 = 4;
IDPiece2 = 5;
IDPiece3 = 6;
pieceHome1 = playerHost.getWaitingArea()[0];
pieceHome2 = playerHost.getWaitingArea()[1];
pieceHome3 = playerHost.getWaitingArea()[2];
@@ -817,21 +805,45 @@ public void testChoosePieceToMovePiece() {
*/
@Test
public void testMovePieceToTurnEndState() {
//sends the server in Game-State
game.setActiveColor(playerClientColor);
playerClient.setHandCards(new ArrayList<>());
turnState.setPlayer(playerClient);
//sends the server in GameState
serverGameLogic.setCurrentState(gameState);
assertEquals(serverGameLogic.getCurrentState(), gameState);
//sends the gameState in Turn
//sends the server in Turn
gameState.setCurrentState(turnState);
assertEquals(gameState.getCurrentState(), turnState);
//sends the TurnState in MovePiece
turnState.setCurrentState(movePieceState);
assertEquals(turnState.getCurrentState(), movePieceState);
//sends the server in ChoosePiece
assertEquals(turnState.getCurrentState(), rollDiceState);
//Todo no 6 was rolled, so the server looks, if there are 2 or less player are still in the game
//TODO
game.setDie(new Die(3));
serverGameLogic.received(new RequestDieMessage(), IDPlayerClient);
serverGameLogic.received(new AnimationEndMessage(), IDPlayerClient);
//tests if the server is in SelectPiece
assertEquals(serverGameLogic.getCurrentState(), gameState);
assertEquals(gameState.getCurrentState(), turnState);
assertEquals(turnState.getCurrentState(),choosePieceState);
assertEquals(choosePieceState.getCurrentState(),selectPieceState);
serverGameLogic.received(new RequestMoveMessage(pieceClient4),IDPlayerClient);
//tests if the server is in SelectPiece
assertEquals(serverGameLogic.getCurrentState(), gameState);
assertEquals(gameState.getCurrentState(), turnState);
assertEquals(turnState.getCurrentState(),movePieceState);
serverGameLogic.received(new AnimationEndMessage(),IDPlayerClient);
serverGameLogic.received(new AnimationEndMessage(),IDPlayerHost);
assertEquals(serverGameLogic.getCurrentState(), gameState);
assertEquals(gameState.getCurrentState(), turnState);
assertNotEquals(turnState.getCurrentState(),movePieceState);
assertNotSame(game.getActiveColor(),playerClientColor);
}
/**
@@ -1101,6 +1113,8 @@ public void testNoPieceToWaitingPiece() {
game.setActiveColor(playerClientColor);
playerClient.setHandCards(new ArrayList<>());
turnState.setPlayer(playerClient);
game.getBoard().getInfield()[22].clearOccupant();
game.getBoard().setPieceOnBoard(29, pieceClient4);
//sends the server in GameState
serverGameLogic.setCurrentState(gameState);
@@ -1111,19 +1125,17 @@ public void testNoPieceToWaitingPiece() {
assertEquals(gameState.getCurrentState(), turnState);
//sends the server in ChoosePiece
turnState.setCurrentState(choosePieceState);
assertEquals(turnState.getCurrentState(), choosePieceState);
assertEquals(turnState.getCurrentState(), rollDiceState);
//sends the server in NoPiece
choosePieceState.setCurrentState(noPieceState);
assertEquals(choosePieceState.getCurrentState(), noPieceState);
game.setDie(new Die(6));
serverGameLogic.received(new RequestDieMessage(), IDPlayerClient);
serverGameLogic.received(new AnimationEndMessage(), IDPlayerClient);
//tests if the server is in WaitingPiece
//tests if the server is in WaitPiece
assertEquals(serverGameLogic.getCurrentState(), gameState);
assertEquals(gameState.getCurrentState(), turnState);
assertEquals(turnState.getCurrentState(), powerCardState);
assertNotSame(game.getActiveColor(), playerClientColor);
assertEquals(turnState.getCurrentState(), choosePieceState);
assertEquals(choosePieceState.getCurrentState(), waitingPieceState);
}
/**
@@ -1132,6 +1144,12 @@ public void testNoPieceToWaitingPiece() {
*/
@Test
public void testNoPieceToNoTurn() {
game.setActiveColor(playerClientColor);
playerClient.setHandCards(new ArrayList<>());
turnState.setPlayer(playerClient);
game.getBoard().getInfield()[22].clearOccupant();
game.getBoard().setPieceOnBoard(29, pieceClient4);
//sends the server in GameState
serverGameLogic.setCurrentState(gameState);
assertEquals(serverGameLogic.getCurrentState(), gameState);
@@ -1141,20 +1159,16 @@ public void testNoPieceToNoTurn() {
assertEquals(gameState.getCurrentState(), turnState);
//sends the server in ChoosePiece
turnState.setCurrentState(choosePieceState);
assertEquals(turnState.getCurrentState(), choosePieceState);
assertEquals(turnState.getCurrentState(), rollDiceState);
//sends the server in NoPiece
choosePieceState.setCurrentState(noPieceState);
assertEquals(choosePieceState.getCurrentState(), noPieceState);
game.setDie(new Die(5));
serverGameLogic.received(new RequestDieMessage(), IDPlayerClient);
serverGameLogic.received(new AnimationEndMessage(), IDPlayerClient);
//TODO
//tests if the server is in NoTurn
//tests if the server is in WaitPiece
assertEquals(serverGameLogic.getCurrentState(), gameState);
assertEquals(gameState.getCurrentState(), turnState);
assertEquals(turnState.getCurrentState(), choosePieceState);
assertEquals(choosePieceState.getCurrentState(), noTurnState);
assertNotSame(game.getActiveColor(),playerClientColor);
}
/**
@@ -1163,6 +1177,12 @@ public void testNoPieceToNoTurn() {
*/
@Test
public void testNoTurnToTurnEndState() {
game.setActiveColor(playerClientColor);
playerClient.setHandCards(new ArrayList<>());
turnState.setPlayer(playerClient);
game.getBoard().getInfield()[22].clearOccupant();
game.getBoard().setPieceOnBoard(29, pieceClient4);
//sends the server in GameState
serverGameLogic.setCurrentState(gameState);
assertEquals(serverGameLogic.getCurrentState(), gameState);
@@ -1172,14 +1192,16 @@ public void testNoTurnToTurnEndState() {
assertEquals(gameState.getCurrentState(), turnState);
//sends the server in ChoosePiece
turnState.setCurrentState(choosePieceState);
assertEquals(turnState.getCurrentState(), choosePieceState);
assertEquals(turnState.getCurrentState(), rollDiceState);
//sends the server in NoTurn
choosePieceState.setCurrentState(noTurnState);
assertEquals(choosePieceState.getCurrentState(), noTurnState);
game.setDie(new Die(5));
serverGameLogic.received(new RequestDieMessage(), IDPlayerClient);
serverGameLogic.received(new AnimationEndMessage(), IDPlayerClient);
//TODO
//tests if the server is in WaitPiece
assertEquals(serverGameLogic.getCurrentState(), gameState);
assertEquals(gameState.getCurrentState(), turnState);
assertNotSame(game.getActiveColor(),playerClientColor);
}
/**
@@ -1188,6 +1210,12 @@ public void testNoTurnToTurnEndState() {
*/
@Test
public void testStayInWaitingPiece() {
game.setActiveColor(playerClientColor);
playerClient.setHandCards(new ArrayList<>());
turnState.setPlayer(playerClient);
game.getBoard().getInfield()[22].clearOccupant();
game.getBoard().setPieceOnBoard(29, pieceClient4);
//sends the server in GameState
serverGameLogic.setCurrentState(gameState);
assertEquals(serverGameLogic.getCurrentState(), gameState);
@@ -1197,14 +1225,27 @@ public void testStayInWaitingPiece() {
assertEquals(gameState.getCurrentState(), turnState);
//sends the server in ChoosePiece
turnState.setCurrentState(choosePieceState);
assertEquals(turnState.getCurrentState(), choosePieceState);
assertEquals(turnState.getCurrentState(), rollDiceState);
//sends the server in WaitingPiece
choosePieceState.setCurrentState(waitingPieceState);
game.setDie(new Die(6));
serverGameLogic.received(new RequestDieMessage(), IDPlayerClient);
serverGameLogic.received(new AnimationEndMessage(), IDPlayerClient);
//tests if the server is in WaitPiece
assertEquals(serverGameLogic.getCurrentState(), gameState);
assertEquals(gameState.getCurrentState(), turnState);
assertEquals(turnState.getCurrentState(), choosePieceState);
assertEquals(choosePieceState.getCurrentState(), waitingPieceState);
//TODO
serverGameLogic.received(deselectTSK, IDPlayerClient);
serverGameLogic.received(forceContinueGame, IDPlayerClient);
serverGameLogic.received(joinServer, IDPlayerClient);
serverGameLogic.received(lobbyNotReady, IDPlayerClient);
serverGameLogic.received(lobbyReady, IDPlayerClient);
serverGameLogic.received(requestBriefing, IDPlayerClient);
serverGameLogic.received(requestDie, IDPlayerClient);
serverGameLogic.received(selectTSK, IDPlayerClient);
serverGameLogic.received(startGame, IDPlayerClient);
//tests if the server is in WaitingPiece
assertEquals(serverGameLogic.getCurrentState(), gameState);
@@ -1219,6 +1260,12 @@ public void testStayInWaitingPiece() {
*/
@Test
public void testWaitingPieceToMovePiece() {
game.setActiveColor(playerClientColor);
playerClient.setHandCards(new ArrayList<>());
turnState.setPlayer(playerClient);
game.getBoard().getInfield()[22].clearOccupant();
game.getBoard().setPieceOnBoard(29, pieceClient4);
//sends the server in GameState
serverGameLogic.setCurrentState(gameState);
assertEquals(serverGameLogic.getCurrentState(), gameState);
@@ -1228,14 +1275,24 @@ public void testWaitingPieceToMovePiece() {
assertEquals(gameState.getCurrentState(), turnState);
//sends the server in ChoosePiece
turnState.setCurrentState(choosePieceState);
assertEquals(turnState.getCurrentState(), choosePieceState);
assertEquals(turnState.getCurrentState(), rollDiceState);
//sends the server in WaitingPiece
choosePieceState.setCurrentState(waitingPieceState);
game.setDie(new Die(6));
serverGameLogic.received(new RequestDieMessage(), IDPlayerClient);
serverGameLogic.received(new AnimationEndMessage(), IDPlayerClient);
//tests if the server is in WaitPiece
assertEquals(serverGameLogic.getCurrentState(), gameState);
assertEquals(gameState.getCurrentState(), turnState);
assertEquals(turnState.getCurrentState(), choosePieceState);
assertEquals(choosePieceState.getCurrentState(), waitingPieceState);
//TODO
serverGameLogic.received(new RequestMoveMessage(playerClient.getWaitingPiece()),IDPlayerClient);
//tests if the server is in WaitPiece
assertEquals(serverGameLogic.getCurrentState(), gameState);
assertEquals(gameState.getCurrentState(), turnState);
assertEquals(turnState.getCurrentState(), movePieceState);
}
/**
@@ -1244,6 +1301,10 @@ public void testWaitingPieceToMovePiece() {
*/
@Test
public void testNoPieceToSelectPiece() {
game.setActiveColor(playerClientColor);
playerClient.setHandCards(new ArrayList<>());
turnState.setPlayer(playerClient);
//sends the server in GameState
serverGameLogic.setCurrentState(gameState);
assertEquals(serverGameLogic.getCurrentState(), gameState);
@@ -1253,14 +1314,11 @@ public void testNoPieceToSelectPiece() {
assertEquals(gameState.getCurrentState(), turnState);
//sends the server in ChoosePiece
turnState.setCurrentState(choosePieceState);
assertEquals(turnState.getCurrentState(), choosePieceState);
assertEquals(turnState.getCurrentState(), rollDiceState);
//sends the server in NoPiece
choosePieceState.setCurrentState(noPieceState);
assertEquals(choosePieceState.getCurrentState(), noPieceState);
//TODO
game.setDie(new Die(4));
serverGameLogic.received(new RequestDieMessage(), IDPlayerClient);
serverGameLogic.received(new AnimationEndMessage(), IDPlayerClient);
//tests if the server is in SelectPiece
assertEquals(serverGameLogic.getCurrentState(), gameState);
@@ -1275,6 +1333,12 @@ public void testNoPieceToSelectPiece() {
*/
@Test
public void testNoPieceToStartPiece() {
game.setActiveColor(playerClientColor);
playerClient.setHandCards(new ArrayList<>());
turnState.setPlayer(playerClient);
game.getBoard().getInfield()[22].clearOccupant();
game.getBoard().setPieceOnBoard(30, pieceClient4);
//sends the server in GameState
serverGameLogic.setCurrentState(gameState);
assertEquals(serverGameLogic.getCurrentState(), gameState);
@@ -1284,14 +1348,11 @@ public void testNoPieceToStartPiece() {
assertEquals(gameState.getCurrentState(), turnState);
//sends the server in ChoosePiece
turnState.setCurrentState(choosePieceState);
assertEquals(turnState.getCurrentState(), choosePieceState);
assertEquals(turnState.getCurrentState(), rollDiceState);
//sends the server in NoPiece
choosePieceState.setCurrentState(noPieceState);
assertEquals(choosePieceState.getCurrentState(), noPieceState);
//TODO
game.setDie(new Die(5));
serverGameLogic.received(new RequestDieMessage(), IDPlayerClient);
serverGameLogic.received(new AnimationEndMessage(), IDPlayerClient);
//tests if the server is in StartPiece
assertEquals(serverGameLogic.getCurrentState(), gameState);