added some testmethods for piecetest
This commit is contained in:
@@ -4,6 +4,9 @@
|
||||
import org.junit.Test;
|
||||
import pp.mdga.message.client.RequestDieMessage;
|
||||
import pp.mdga.message.client.RequestMoveMessage;
|
||||
import pp.mdga.message.client.RequestPlayCardMessage;
|
||||
import pp.mdga.message.client.SelectCardMessage;
|
||||
import pp.mdga.message.client.SelectedPiecesMessage;
|
||||
import pp.mdga.message.server.MoveMessage;
|
||||
import pp.mdga.message.server.SelectPieceMessage;
|
||||
import pp.mdga.message.server.ServerMessage;
|
||||
@@ -12,11 +15,14 @@
|
||||
import pp.mdga.server.automaton.GameState;
|
||||
import pp.mdga.server.automaton.game.TurnState;
|
||||
import pp.mdga.server.automaton.game.turn.ChoosePieceState;
|
||||
import pp.mdga.server.automaton.game.turn.PlayPowerCardState;
|
||||
import pp.mdga.server.automaton.game.turn.PowerCardState;
|
||||
import pp.mdga.server.automaton.game.turn.RollDiceState;
|
||||
import pp.mdga.server.automaton.game.turn.choosepiece.SelectPieceState;
|
||||
import pp.mdga.server.automaton.game.turn.rolldice.FirstRollState;
|
||||
|
||||
import java.sql.SQLOutput;
|
||||
import java.util.Arrays;
|
||||
import java.util.Map;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
@@ -65,6 +71,8 @@ public class PieceTest {
|
||||
FirstRollState firstRollState;
|
||||
ChoosePieceState choosePieceState;
|
||||
SelectPieceState selectPieceState;
|
||||
PowerCardState powerCardState;
|
||||
PlayPowerCardState playPowerCardState;
|
||||
|
||||
//declare dies
|
||||
private Die die1;
|
||||
@@ -174,6 +182,8 @@ public void disconnectClient(int id) {
|
||||
firstRollState= rollDiceState.getFirstRollState();
|
||||
choosePieceState= turnState.getChoosePieceState();
|
||||
selectPieceState= choosePieceState.getSelectPieceState();
|
||||
powerCardState = turnState.getPowerCardState();
|
||||
playPowerCardState = turnState.getPlayPowerCardState();
|
||||
|
||||
//initialize dies
|
||||
die1 = new Die(1);
|
||||
@@ -231,7 +241,6 @@ public void testMove() {
|
||||
*/
|
||||
@Test
|
||||
public void testCantMove() {
|
||||
// TODO: Implement test logic for when a piece can't move
|
||||
//sends the server in selectPiece
|
||||
serverGameLogic.setCurrentState(gameState);
|
||||
serverGameLogic.getGameState().setCurrentState(turnState);
|
||||
@@ -245,21 +254,20 @@ public void testCantMove() {
|
||||
assertEquals(choosePieceState.getCurrentState(),selectPieceState);
|
||||
|
||||
//set active player to army
|
||||
game.setActiveColor(hostColor);
|
||||
game.setActiveColor(clientColor);
|
||||
|
||||
//set die-class
|
||||
game.setDie(die2);
|
||||
|
||||
//send request Die-message
|
||||
serverGameLogic.received(new RequestDieMessage(),IDHost);
|
||||
serverGameLogic.received(new RequestDieMessage(),IDClient);
|
||||
|
||||
//send requestMove-Message
|
||||
serverGameLogic.received(new RequestMoveMessage(pieceHost2.getUuid()),IDHost);
|
||||
serverGameLogic.received(new RequestMoveMessage(pieceClient2.getUuid()),IDClient);
|
||||
|
||||
//tests if the hostPiece2 is still at idx 19 and the server is still in selectable pieces
|
||||
assertTrue(game.getBoard().getInfield()[19].isOccupied());
|
||||
assertEquals(game.getBoard().getInfield()[19].getOccupant(),pieceHost2);
|
||||
|
||||
assertEquals(game.getBoard().getInfield()[19].getOccupant(),pieceClient2);
|
||||
assertEquals(serverGameLogic.getCurrentState(),gameState);
|
||||
assertEquals(gameState.getCurrentState(), turnState);
|
||||
assertEquals(turnState.getCurrentState(),choosePieceState);
|
||||
@@ -285,7 +293,38 @@ public void testNoPossibleMove() {
|
||||
*/
|
||||
@Test
|
||||
public void testThrow() {
|
||||
// TODO: Implement test logic for throwing a piece off the board
|
||||
//sends the server in selectPiece
|
||||
serverGameLogic.setCurrentState(gameState);
|
||||
serverGameLogic.getGameState().setCurrentState(turnState);
|
||||
serverGameLogic.getGameState().getTurnState().setCurrentState(choosePieceState);
|
||||
serverGameLogic.getGameState().getTurnState().getChoosePieceState().setCurrentState(selectPieceState);
|
||||
|
||||
//tests if the server is in selectPieces
|
||||
assertEquals(serverGameLogic.getCurrentState(),gameState);
|
||||
assertEquals(gameState.getCurrentState(), turnState);
|
||||
assertEquals(turnState.getCurrentState(),choosePieceState);
|
||||
assertEquals(choosePieceState.getCurrentState(),selectPieceState);
|
||||
|
||||
//set active player to host
|
||||
game.setActiveColor(hostColor);
|
||||
|
||||
//set Dice to 1
|
||||
game.setDie(die1);
|
||||
|
||||
//send requestDice
|
||||
serverGameLogic.received(new RequestDieMessage(),IDHost);
|
||||
|
||||
//send requestMove-message
|
||||
serverGameLogic.received(new RequestMoveMessage(pieceHost1.getUuid()),IDHost);
|
||||
|
||||
//tests if the idx is unoccupied
|
||||
assertFalse(game.getBoard().getInfield()[19].isOccupied());
|
||||
|
||||
//tests if the idx 20 is occupied
|
||||
assertTrue(game.getBoard().getInfield()[20].isOccupied());
|
||||
|
||||
//tests if the piece on idx 20 is pieceHost1
|
||||
assertEquals(game.getBoard().getInfield()[20].getOccupant(),pieceHost1);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -296,7 +335,32 @@ public void testThrow() {
|
||||
*/
|
||||
@Test
|
||||
public void testGetThrown() {
|
||||
// TODO: Implement test logic for when a piece gets thrown
|
||||
//sends the server in selectPiece
|
||||
serverGameLogic.setCurrentState(gameState);
|
||||
serverGameLogic.getGameState().setCurrentState(turnState);
|
||||
serverGameLogic.getGameState().getTurnState().setCurrentState(choosePieceState);
|
||||
serverGameLogic.getGameState().getTurnState().getChoosePieceState().setCurrentState(selectPieceState);
|
||||
|
||||
//tests if the server is in selectPieces
|
||||
assertEquals(serverGameLogic.getCurrentState(),gameState);
|
||||
assertEquals(gameState.getCurrentState(), turnState);
|
||||
assertEquals(turnState.getCurrentState(),choosePieceState);
|
||||
assertEquals(choosePieceState.getCurrentState(),selectPieceState);
|
||||
|
||||
//set active player to host
|
||||
game.setActiveColor(hostColor);
|
||||
|
||||
//set Dice to 1
|
||||
game.setDie(die1);
|
||||
|
||||
//send requestDice
|
||||
serverGameLogic.received(new RequestDieMessage(),IDHost);
|
||||
|
||||
//send requestMove-message
|
||||
serverGameLogic.received(new RequestMoveMessage(pieceHost1.getUuid()),IDHost);
|
||||
|
||||
//tests if pieceClient2 is waitingArea
|
||||
assertTrue(Arrays.stream(game.getBoard().getPlayerData().get(clientColor).getWaitingArea()).toList().contains(pieceClient2));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -307,7 +371,36 @@ public void testGetThrown() {
|
||||
*/
|
||||
@Test
|
||||
public void testLeaveWaitingArea() {
|
||||
// TODO: Implement test logic for a piece leaving the waiting area
|
||||
//sends the server in selectPiece
|
||||
serverGameLogic.setCurrentState(gameState);
|
||||
serverGameLogic.getGameState().setCurrentState(turnState);
|
||||
serverGameLogic.getGameState().getTurnState().setCurrentState(choosePieceState);
|
||||
serverGameLogic.getGameState().getTurnState().getChoosePieceState().setCurrentState(selectPieceState);
|
||||
|
||||
//tests if the server is in selectPieces
|
||||
assertEquals(serverGameLogic.getCurrentState(),gameState);
|
||||
assertEquals(gameState.getCurrentState(), turnState);
|
||||
assertEquals(turnState.getCurrentState(),choosePieceState);
|
||||
assertEquals(choosePieceState.getCurrentState(),selectPieceState);
|
||||
|
||||
//set active player to host
|
||||
game.setActiveColor(hostColor);
|
||||
|
||||
//set Dice to 6
|
||||
game.setDie(die6);
|
||||
|
||||
//send requestDice
|
||||
serverGameLogic.received(new RequestDieMessage(),IDHost);
|
||||
|
||||
//send requestMove-message
|
||||
serverGameLogic.received(new RequestMoveMessage(pieceHost2.getUuid()),IDHost);
|
||||
|
||||
//tests if the waitingArea does not include the piece anymore
|
||||
assertFalse(Arrays.stream(game.getBoard().getPlayerData().get(hostColor).getWaitingArea()).toList().contains(pieceHost2));
|
||||
|
||||
//tests if the pieceHost3 is at idx 30
|
||||
assertTrue(game.getBoard().getInfield()[30].isOccupied());
|
||||
assertEquals(game.getBoard().getInfield()[30].getOccupant(),pieceHost2);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -525,7 +618,41 @@ public void testOnStartingFieldWithShield() {
|
||||
*/
|
||||
@Test
|
||||
public void testThrowFigureWithShield() {
|
||||
// TODO: Implement test logic for attempting to throw a figure with a shield
|
||||
//set clientPiece2 the shield active
|
||||
pieceClient2.setShield(ShieldState.ACTIVE);
|
||||
|
||||
//set host as active player
|
||||
game.setActiveColor(hostColor);
|
||||
|
||||
//set die to 1
|
||||
game.setDie(die1);
|
||||
|
||||
//sends the server in selectPiece
|
||||
serverGameLogic.setCurrentState(gameState);
|
||||
serverGameLogic.getGameState().setCurrentState(turnState);
|
||||
serverGameLogic.getGameState().getTurnState().setCurrentState(choosePieceState);
|
||||
serverGameLogic.getGameState().getTurnState().getChoosePieceState().setCurrentState(selectPieceState);
|
||||
|
||||
//tests if the server is in selectPieces
|
||||
assertEquals(serverGameLogic.getCurrentState(),gameState);
|
||||
assertEquals(gameState.getCurrentState(), turnState);
|
||||
assertEquals(turnState.getCurrentState(),choosePieceState);
|
||||
assertEquals(choosePieceState.getCurrentState(),selectPieceState);
|
||||
|
||||
//send requestDice
|
||||
serverGameLogic.received(new RequestDieMessage(),IDHost);
|
||||
|
||||
//send requestMove of hostPiece1
|
||||
serverGameLogic.received(new RequestMoveMessage(pieceHost1.getUuid()),IDHost);
|
||||
|
||||
//tests if the clientPiece2 is still at idx 19 and hostPiece1 at idx 18 and clientPiece2 shield is still active
|
||||
assertTrue(game.getBoard().getInfield()[19].isOccupied());
|
||||
assertTrue(game.getBoard().getInfield()[18].isOccupied());
|
||||
|
||||
assertEquals(game.getBoard().getInfield()[18].getOccupant(),pieceHost1);
|
||||
assertEquals(game.getBoard().getInfield()[19].getOccupant(),pieceClient2);
|
||||
|
||||
assertEquals(pieceClient2.getShield(),ShieldState.ACTIVE);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -536,7 +663,37 @@ public void testThrowFigureWithShield() {
|
||||
*/
|
||||
@Test
|
||||
public void testUseSwap() {
|
||||
// TODO: Implement test logic for using a swap power-up
|
||||
//send the server in choosePowerCard
|
||||
serverGameLogic.setCurrentState(gameState);
|
||||
serverGameLogic.getGameState().setCurrentState(turnState);
|
||||
serverGameLogic.getGameState().getTurnState().setCurrentState(powerCardState);
|
||||
|
||||
//tests if the server is in selectPieces
|
||||
assertEquals(serverGameLogic.getCurrentState(),gameState);
|
||||
assertEquals(gameState.getCurrentState(), turnState);
|
||||
assertEquals(turnState.getCurrentState(),powerCardState);
|
||||
|
||||
//set activePlayer to Host
|
||||
game.setActiveColor(hostColor);
|
||||
|
||||
//sends the requestPlayCard
|
||||
serverGameLogic.received(new SelectCardMessage(BonusCard.SWAP),IDHost);
|
||||
|
||||
//sends the selectedPiece-message
|
||||
serverGameLogic.received(RequestPlayCardMessage.requestPlaySwap(pieceHost0.getUuid(),pieceClient0.getUuid()),IDHost);
|
||||
|
||||
//tests if the piece at idx 25 is pieceHost0 and at idx 28 is pieceClient0
|
||||
assertTrue(game.getBoard().getInfield()[25].isOccupied());
|
||||
assertEquals(game.getBoard().getInfield()[25].getOccupant(),pieceHost0);
|
||||
|
||||
assertTrue(game.getBoard().getInfield()[28].isOccupied());
|
||||
assertEquals(game.getBoard().getInfield()[28].getOccupant(),pieceClient0);
|
||||
|
||||
|
||||
//tests if the server is in playPowerCard
|
||||
assertEquals(serverGameLogic.getCurrentState(),gameState);
|
||||
assertEquals(gameState.getCurrentState(), turnState);
|
||||
assertEquals(turnState.getCurrentState(),playPowerCardState);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -547,7 +704,32 @@ public void testUseSwap() {
|
||||
*/
|
||||
@Test
|
||||
public void testUseShield() {
|
||||
// TODO: Implement test logic for using a shield power-up
|
||||
//send the server in choosePowerCard
|
||||
serverGameLogic.setCurrentState(gameState);
|
||||
serverGameLogic.getGameState().setCurrentState(turnState);
|
||||
serverGameLogic.getGameState().getTurnState().setCurrentState(powerCardState);
|
||||
|
||||
//tests if the server is in selectPieces
|
||||
assertEquals(serverGameLogic.getCurrentState(),gameState);
|
||||
assertEquals(gameState.getCurrentState(), turnState);
|
||||
assertEquals(turnState.getCurrentState(),powerCardState);
|
||||
|
||||
//set activePlayer to Host
|
||||
game.setActiveColor(hostColor);
|
||||
|
||||
//sends the requestPlayCard
|
||||
serverGameLogic.received(new SelectCardMessage(BonusCard.SHIELD),IDHost);
|
||||
|
||||
//sends the selectedPiece-message
|
||||
serverGameLogic.received(RequestPlayCardMessage.requestPlayShield(pieceHost0.getUuid()),IDHost);
|
||||
|
||||
//tests if the piece at idx 28 has a shield
|
||||
assertEquals(pieceHost0.getShield(),ShieldState.ACTIVE);
|
||||
|
||||
//tests if the server is in playPowerCard
|
||||
assertEquals(serverGameLogic.getCurrentState(),gameState);
|
||||
assertEquals(gameState.getCurrentState(), turnState);
|
||||
assertEquals(turnState.getCurrentState(),playPowerCardState);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -569,15 +751,32 @@ public void testLoseShield() {
|
||||
*/
|
||||
@Test
|
||||
public void testFinishedPiece() {
|
||||
// TODO: Implement test logic for a piece that has finished the game
|
||||
//sends the server in selectPiece
|
||||
serverGameLogic.setCurrentState(gameState);
|
||||
serverGameLogic.getGameState().setCurrentState(turnState);
|
||||
serverGameLogic.getGameState().getTurnState().setCurrentState(choosePieceState);
|
||||
serverGameLogic.getGameState().getTurnState().getChoosePieceState().setCurrentState(selectPieceState);
|
||||
|
||||
//tests if the server is in selectPieces
|
||||
assertEquals(serverGameLogic.getCurrentState(),gameState);
|
||||
assertEquals(gameState.getCurrentState(), turnState);
|
||||
assertEquals(turnState.getCurrentState(),choosePieceState);
|
||||
assertEquals(choosePieceState.getCurrentState(),selectPieceState);
|
||||
|
||||
//sets the active color to client
|
||||
game.setActiveColor(clientColor);
|
||||
|
||||
//set the dice-class seed to 2
|
||||
|
||||
//set the dice to 2
|
||||
game.setDie(die2);
|
||||
//sends the requestDie-Message
|
||||
serverGameLogic.received(new RequestDieMessage(),IDClient);
|
||||
|
||||
//sends the requestMove-Message
|
||||
serverGameLogic.received(new RequestMoveMessage(pieceClient1.getUuid()),IDClient);
|
||||
|
||||
//tests if the Piece is in the final position and is marked as home-finished
|
||||
assertTrue(game.getBoard().getPlayerData().get(clientColor).getHomeNodes()[3].isOccupied());
|
||||
assertEquals(game.getBoard().getPlayerData().get(clientColor).getHomeNodes()[3].getOccupant(),pieceClient1);
|
||||
assertEquals(pieceClient1.getState(),PieceState.HOMEFINISHED);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user