aaded some tests!

This commit is contained in:
Benjamin Feyer
2024-12-13 01:59:34 +01:00
parent 48d6516073
commit ea3f4df636

View File

@@ -31,6 +31,8 @@
import java.util.List; import java.util.List;
import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertEquals;
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
@@ -120,7 +122,6 @@ public class ServerStateTest {
private SelectedPiecesMessage selectedPiecesMessage; private SelectedPiecesMessage selectedPiecesMessage;
/** /**
* this method is used to initialize the attributes of this test-class * this method is used to initialize the attributes of this test-class
*/ */
@@ -131,10 +132,9 @@ public void setUp() {
playerHost = new Player("Host"); playerHost = new Player("Host");
playerHostColor = Color.CYBER; playerHostColor = Color.CYBER;
playerHost.setColor(playerHostColor); playerHost.setColor(playerHostColor);
PowerCard shield= new ShieldCard(); PowerCard shield = new ShieldCard();
selectCard = new SelectCardMessage(shield); selectCard = new SelectCardMessage(shield);
playerHost.addHandCard(shield); playerHost.addHandCard(shield);
playerHost.addHandCard(new SwapCard()); playerHost.addHandCard(new SwapCard());
playerHost.addHandCard(new TurboCard()); playerHost.addHandCard(new TurboCard());
@@ -145,16 +145,12 @@ public void setUp() {
hostPiece2 = playerHost.getWaitingArea()[1]; hostPiece2 = playerHost.getWaitingArea()[1];
hostPiece3 = playerHost.getWaitingArea()[2]; hostPiece3 = playerHost.getWaitingArea()[2];
hostPiece4 = playerHost.getWaitingArea()[3]; hostPiece4 = playerHost.getWaitingArea()[3];
game.getBoard().setPieceOnBoard(15,hostPiece1); game.getBoard().setPieceOnBoard(15, hostPiece1);
hostPiece1.setState(PieceState.ACTIVE); hostPiece1.setState(PieceState.ACTIVE);
game.getBoard().setPieceOnBoard(35,hostPiece2); game.getBoard().setPieceOnBoard(35, hostPiece2);
hostPiece2.setState(PieceState.ACTIVE); hostPiece2.setState(PieceState.ACTIVE);
selectedPiecesMessage = new SelectedPiecesMessage(List.of(hostPiece2)); selectedPiecesMessage = new SelectedPiecesMessage(List.of(hostPiece2));
playerClient = new Player("Client"); playerClient = new Player("Client");
playerClient.addHandCard(new ShieldCard()); playerClient.addHandCard(new ShieldCard());
playerClient.addHandCard(new SwapCard()); playerClient.addHandCard(new SwapCard());
@@ -166,10 +162,9 @@ public void setUp() {
playerClient.addHandCard(bonusCardClient); playerClient.addHandCard(bonusCardClient);
game.addPlayer(IDPlayerClient, playerClient); game.addPlayer(IDPlayerClient, playerClient);
pieceClient4 = playerClient.getWaitingArea()[3]; pieceClient4 = playerClient.getWaitingArea()[3];
game.getBoard().setPieceOnBoard(22,pieceClient4); game.getBoard().setPieceOnBoard(22, pieceClient4);
pieceClient4.setState(PieceState.ACTIVE); pieceClient4.setState(PieceState.ACTIVE);
serverGameLogic = new ServerGameLogic(new ServerSender() { serverGameLogic = new ServerGameLogic(new ServerSender() {
@Override @Override
public void send(int id, ServerMessage message) { public void send(int id, ServerMessage message) {
@@ -226,7 +221,6 @@ public void accept(Visitor visitor) {
turnState = gameState.getTurnState(); turnState = gameState.getTurnState();
animationState = gameState.getAnimationState(); animationState = gameState.getAnimationState();
animationEnd = new AnimationEndMessage(); animationEnd = new AnimationEndMessage();
deselectTSK = new DeselectTSKMessage(playerClientColor); deselectTSK = new DeselectTSKMessage(playerClientColor);
disconnected = new DisconnectedMessage(); disconnected = new DisconnectedMessage();
@@ -271,7 +265,7 @@ public void accept(Visitor visitor) {
/** /**
* this test-method tests, that the server, when initialized, is in the Lobby-state * this test-method tests, that the server, when initialized, is in the Lobby-state
* * <p>
* serverStateTest1 * serverStateTest1
*/ */
@Test @Test
@@ -283,7 +277,7 @@ public void testInitialStateServerState() {
/** /**
* this method tests that the server, if all players are ready and the startGameMessage is issued, * this method tests that the server, if all players are ready and the startGameMessage is issued,
* changes into the DetermineStartPlayer-state * changes into the DetermineStartPlayer-state
* * <p>
* serverStateTest2 * serverStateTest2
*/ */
@Test @Test
@@ -327,7 +321,7 @@ public void testLobbyToDetermineStartPlayer() {
/** /**
* this method tests, that the server stays in the Lobby * this method tests, that the server stays in the Lobby
* * <p>
* serverStateTest3 * serverStateTest3
*/ */
@Test @Test
@@ -357,7 +351,7 @@ public void testStayInLobby() {
/** /**
* this method tests, that the server can go into the interrupt-state * this method tests, that the server can go into the interrupt-state
* * <p>
* serverStateTest4 * serverStateTest4
*/ */
@Test @Test
@@ -375,7 +369,7 @@ public void testServerGameSubStatesToInterrupt() {
/** /**
* tests the state-change IDPlayerClient Game to Ceremony if the Game is finished * tests the state-change IDPlayerClient Game to Ceremony if the Game is finished
* * <p>
* serverStateTest5 * serverStateTest5
*/ */
@Test @Test
@@ -392,7 +386,7 @@ public void testServerGameToCeremony() {
/** /**
* this method tests that the server goes back to the Game, when the ForceStartGame-message is issued * this method tests that the server goes back to the Game, when the ForceStartGame-message is issued
* * <p>
* serverStateTest6 * serverStateTest6
*/ */
@Test @Test
@@ -431,7 +425,7 @@ public void testInterruptToGameContinue() {
/** /**
* this method tests, that the server goes back to the game, if the missing client has reconnected * this method tests, that the server goes back to the game, if the missing client has reconnected
* * <p>
* serverStateTest7 * serverStateTest7
*/ */
@Test @Test
@@ -448,7 +442,7 @@ public void testInterruptToGameReconnect() {
/** /**
* this method tests, that th e server continues with the game, if there is no time left on the timer * this method tests, that th e server continues with the game, if there is no time left on the timer
* * <p>
* serverStateTest8 * serverStateTest8
*/ */
@Test @Test
@@ -465,7 +459,7 @@ public void testInterruptToGameTimer() {
/** /**
* this method tests, that the server closes, if the ceremony has ended * this method tests, that the server closes, if the ceremony has ended
* * <p>
* serverStateTest9 * serverStateTest9
*/ */
@Test @Test
@@ -550,7 +544,7 @@ public void testDetermineStartPlayerToDetermineStartPlayer2() {
/** /**
* this method tests that the server goes into Animation-state, if there is an order * this method tests that the server goes into Animation-state, if there is an order
* * <p>
* serverStateTest12 * serverStateTest12
*/ */
@Test @Test
@@ -574,7 +568,7 @@ public void testDetermineStartPlayerToAnimation() {
//sends the two requestDiceMessages //sends the two requestDiceMessages
serverGameLogic.received(requestDie, IDPlayerHost); serverGameLogic.received(requestDie, IDPlayerHost);
serverGameLogic.received(new AnimationEndMessage(),IDPlayerClient); serverGameLogic.received(new AnimationEndMessage(), IDPlayerClient);
serverGameLogic.received(new AnimationEndMessage(), IDPlayerHost); serverGameLogic.received(new AnimationEndMessage(), IDPlayerHost);
//tests if the Server is in animationState //tests if the Server is in animationState
@@ -585,7 +579,7 @@ public void testDetermineStartPlayerToAnimation() {
/** /**
* tests that the server goes IDPlayerClient the animation-state into PowerCardState, if the animation in the client has ended * tests that the server goes IDPlayerClient the animation-state into PowerCardState, if the animation in the client has ended
* and all players have issued a animationEndMessage * and all players have issued a animationEndMessage
* * <p>
* serverStateTest13 * serverStateTest13
*/ */
@Test @Test
@@ -616,7 +610,7 @@ public void testAnimationToPowerCard() {
/** /**
* this method tests that the server changes it's state IDPlayerClient the turn-state to the animation-state, if there are at * this method tests that the server changes it's state IDPlayerClient the turn-state to the animation-state, if there are at
* least two player left * least two player left
* * <p>
* serverStateTest14 * serverStateTest14
*/ */
@Test @Test
@@ -655,7 +649,7 @@ public void testTurnToAnimation() {
/** /**
* this method tests that the server changes it's state IDPlayerClient the turn-state to the ceremony-state, * this method tests that the server changes it's state IDPlayerClient the turn-state to the ceremony-state,
* if there is only one player left * if there is only one player left
* * <p>
* serverStateTest15 * serverStateTest15
*/ */
@Test @Test
@@ -677,7 +671,7 @@ public void testTurnToGameEndState() {
/** /**
* this method tests that the server don't change it's state whe issued with messages, * this method tests that the server don't change it's state whe issued with messages,
* which don't implicate a statechange * which don't implicate a statechange
* * <p>
* serverStateTest16 * serverStateTest16
*/ */
@Test @Test
@@ -788,7 +782,7 @@ public void testChoosePieceToMovePiece() {
game.setActiveColor(playerClientColor); game.setActiveColor(playerClientColor);
turnState.setPlayer(playerClient); turnState.setPlayer(playerClient);
playerClient.removeWaitingPiece(pieceClient4); playerClient.removeWaitingPiece(pieceClient4);
game.getBoard().setPieceOnBoard(25,pieceClient4); game.getBoard().setPieceOnBoard(25, pieceClient4);
pieceClient4.setState(PieceState.ACTIVE); pieceClient4.setState(PieceState.ACTIVE);
//sends the server in Game-State //sends the server in Game-State
@@ -810,8 +804,7 @@ public void testChoosePieceToMovePiece() {
selectPieceState.setIsHomeMove(new ArrayList<>(List.of(false))); selectPieceState.setIsHomeMove(new ArrayList<>(List.of(false)));
selectPieceState.setTargetIndex(new ArrayList<>(List.of(23))); selectPieceState.setTargetIndex(new ArrayList<>(List.of(23)));
serverGameLogic.received(new RequestMoveMessage(pieceClient4),IDPlayerClient); serverGameLogic.received(new RequestMoveMessage(pieceClient4), IDPlayerClient);
assertEquals(serverGameLogic.getCurrentState(), gameState); assertEquals(serverGameLogic.getCurrentState(), gameState);
assertEquals(gameState.getCurrentState(), turnState); assertEquals(gameState.getCurrentState(), turnState);
@@ -905,8 +898,8 @@ public void testFirstRollToRollDiceEndState() {
game.setDie(new Die(1)); game.setDie(new Die(1));
serverGameLogic.received(new RequestDieMessage(),IDPlayerClient); serverGameLogic.received(new RequestDieMessage(), IDPlayerClient);
serverGameLogic.received(new AnimationEndMessage(),IDPlayerClient); serverGameLogic.received(new AnimationEndMessage(), IDPlayerClient);
//tests if the server is in ChoosePiece //tests if the server is in ChoosePiece
assertEquals(serverGameLogic.getCurrentState(), gameState); assertEquals(serverGameLogic.getCurrentState(), gameState);
@@ -952,7 +945,6 @@ public void testFirstRollToSecondRoll() {
assertEquals(gameState.getCurrentState(), turnState); assertEquals(gameState.getCurrentState(), turnState);
assertEquals(turnState.getCurrentState(), rollDiceState); assertEquals(turnState.getCurrentState(), rollDiceState);
assertEquals(rollDiceState.getCurrentState(), secondRollState); assertEquals(rollDiceState.getCurrentState(), secondRollState);
} }
/** /**
@@ -985,14 +977,13 @@ public void testSecondRollToRollDiceEndState() {
game.setDie(new Die(6)); game.setDie(new Die(6));
// //
serverGameLogic.received(requestDie,IDPlayerClient); serverGameLogic.received(requestDie, IDPlayerClient);
serverGameLogic.received(animationEnd, IDPlayerClient); serverGameLogic.received(animationEnd, IDPlayerClient);
//tests if the server is in NoPiece of ChoosePiece //tests if the server is in NoPiece of ChoosePiece
assertEquals(serverGameLogic.getCurrentState(), gameState); assertEquals(serverGameLogic.getCurrentState(), gameState);
assertEquals(gameState.getCurrentState(), turnState); assertEquals(gameState.getCurrentState(), turnState);
assertEquals(turnState.getCurrentState(), choosePieceState); assertEquals(turnState.getCurrentState(), choosePieceState);
} }
/** /**
@@ -1057,7 +1048,7 @@ public void testThirdRollToRollDiceEndState() {
//die =6 //die =6
game.setDie(new Die(6)); game.setDie(new Die(6));
serverGameLogic.received(requestDie,IDPlayerClient); serverGameLogic.received(requestDie, IDPlayerClient);
System.out.println(game.getActivePlayer()); System.out.println(game.getActivePlayer());
System.out.println(game.getActivePlayer().getStartNodeIndex()); System.out.println(game.getActivePlayer().getStartNodeIndex());
serverGameLogic.received(animationEnd, IDPlayerClient); serverGameLogic.received(animationEnd, IDPlayerClient);
@@ -1074,6 +1065,9 @@ public void testThirdRollToRollDiceEndState() {
*/ */
@Test @Test
public void testThirdRollToTurnEndState() { public void testThirdRollToTurnEndState() {
game.setActiveColor(playerClientColor);
playerClient.setHandCards(new ArrayList<>());
//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);
@@ -1090,7 +1084,12 @@ public void testThirdRollToTurnEndState() {
rollDiceState.setCurrentState(thirdRollState); rollDiceState.setCurrentState(thirdRollState);
assertEquals(rollDiceState.getCurrentState(), thirdRollState); assertEquals(rollDiceState.getCurrentState(), thirdRollState);
//Todo game.setDie(new Die(4));
serverGameLogic.received(new RequestDieMessage(), IDPlayerClient);
serverGameLogic.received(new AnimationEndMessage(), IDPlayerClient);
assertNotSame(game.getActiveColor(), playerClientColor);
} }
/** /**
@@ -1099,6 +1098,10 @@ public void testThirdRollToTurnEndState() {
*/ */
@Test @Test
public void testNoPieceToWaitingPiece() { public void testNoPieceToWaitingPiece() {
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);
@@ -1115,13 +1118,12 @@ public void testNoPieceToWaitingPiece() {
choosePieceState.setCurrentState(noPieceState); choosePieceState.setCurrentState(noPieceState);
assertEquals(choosePieceState.getCurrentState(), noPieceState); assertEquals(choosePieceState.getCurrentState(), noPieceState);
//TODO
//tests if the server is in WaitingPiece //tests if the server is in WaitingPiece
assertEquals(serverGameLogic.getCurrentState(), gameState); assertEquals(serverGameLogic.getCurrentState(), gameState);
assertEquals(gameState.getCurrentState(), turnState); assertEquals(gameState.getCurrentState(), turnState);
assertEquals(turnState.getCurrentState(), choosePieceState); assertEquals(turnState.getCurrentState(), powerCardState);
assertEquals(choosePieceState.getCurrentState(), waitingPieceState);
assertNotSame(game.getActiveColor(), playerClientColor);
} }
/** /**
@@ -1304,6 +1306,10 @@ public void testNoPieceToStartPiece() {
*/ */
@Test @Test
public void testStayInSelectPiece() { public void testStayInSelectPiece() {
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);
@@ -1313,14 +1319,24 @@ public void testStayInSelectPiece() {
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 SelectPiece game.setDie(new Die(4));
choosePieceState.setCurrentState(selectPieceState); serverGameLogic.received(new RequestDieMessage(), IDPlayerClient);
serverGameLogic.received(new AnimationEndMessage(), IDPlayerClient);
//sends the server in StartPiece
assertEquals(choosePieceState.getCurrentState(), selectPieceState); assertEquals(choosePieceState.getCurrentState(), selectPieceState);
//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 SelectPiece //tests if the server is in SelectPiece
assertEquals(serverGameLogic.getCurrentState(), gameState); assertEquals(serverGameLogic.getCurrentState(), gameState);
@@ -1335,6 +1351,10 @@ public void testStayInSelectPiece() {
*/ */
@Test @Test
public void testSelectPieceToMovePiece() { public void testSelectPieceToMovePiece() {
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);
@@ -1343,15 +1363,17 @@ public void testSelectPieceToMovePiece() {
gameState.setCurrentState(turnState); gameState.setCurrentState(turnState);
assertEquals(gameState.getCurrentState(), turnState); assertEquals(gameState.getCurrentState(), turnState);
//sends the server in ChoosePiece //tests the server in rollDiceState
turnState.setCurrentState(choosePieceState); assertEquals(turnState.getCurrentState(), rollDiceState);
assertEquals(turnState.getCurrentState(), choosePieceState);
//sends the server in SelectPiece game.setDie(new Die(4));
choosePieceState.setCurrentState(selectPieceState); serverGameLogic.received(new RequestDieMessage(), IDPlayerClient);
serverGameLogic.received(new AnimationEndMessage(), IDPlayerClient);
//tests if the server in selectPiece
assertEquals(choosePieceState.getCurrentState(), selectPieceState); assertEquals(choosePieceState.getCurrentState(), selectPieceState);
//TODO serverGameLogic.received(new RequestMoveMessage(pieceClient4), IDPlayerClient);
//tests if the server is in movePiece-state //tests if the server is in movePiece-state
assertEquals(serverGameLogic.getCurrentState(), gameState); assertEquals(serverGameLogic.getCurrentState(), gameState);
@@ -1365,6 +1387,12 @@ public void testSelectPieceToMovePiece() {
*/ */
@Test @Test
public void testStayInStartPiece() { public void testStayInStartPiece() {
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);
@@ -1373,15 +1401,25 @@ public void testStayInStartPiece() {
gameState.setCurrentState(turnState); gameState.setCurrentState(turnState);
assertEquals(gameState.getCurrentState(), turnState); assertEquals(gameState.getCurrentState(), turnState);
//sends the server in ChoosePiece //tests the server in ChoosePiece
turnState.setCurrentState(choosePieceState); assertEquals(turnState.getCurrentState(), rollDiceState);
assertEquals(turnState.getCurrentState(), choosePieceState);
//sends the server in StartPiece game.setDie(new Die(4));
choosePieceState.setCurrentState(startPieceState); serverGameLogic.received(new RequestDieMessage(), IDPlayerClient);
serverGameLogic.received(new AnimationEndMessage(), IDPlayerClient);
//tests the server in StartPiece
assertEquals(choosePieceState.getCurrentState(), startPieceState); assertEquals(choosePieceState.getCurrentState(), startPieceState);
//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 StartPiece //tests if the server is in StartPiece
assertEquals(serverGameLogic.getCurrentState(), gameState); assertEquals(serverGameLogic.getCurrentState(), gameState);
@@ -1396,6 +1434,12 @@ public void testStayInStartPiece() {
*/ */
@Test @Test
public void testStartPieceToMovePiece() { public void testStartPieceToMovePiece() {
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);
@@ -1405,14 +1449,16 @@ public void testStartPieceToMovePiece() {
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);
game.setDie(new Die(4));
serverGameLogic.received(new RequestDieMessage(), IDPlayerClient);
serverGameLogic.received(new AnimationEndMessage(), IDPlayerClient);
//sends the server in StartPiece //sends the server in StartPiece
choosePieceState.setCurrentState(startPieceState);
assertEquals(choosePieceState.getCurrentState(), startPieceState); assertEquals(choosePieceState.getCurrentState(), startPieceState);
//TODO serverGameLogic.received(new RequestMoveMessage(pieceClient4), IDPlayerClient);
//tests if the server is in movePiece-state //tests if the server is in movePiece-state
assertEquals(serverGameLogic.getCurrentState(), gameState); assertEquals(serverGameLogic.getCurrentState(), gameState);