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