mirror of
https://athene2.informatik.unibw-muenchen.de/progproj/gruppen-ht24/Gruppe-02.git
synced 2024-11-28 21:19:44 +01:00
Tests bis T070 erweitert
This commit is contained in:
parent
f4fb04d17e
commit
7fce07ac19
@ -1,12 +1,568 @@
|
|||||||
package pp.monopoly.game.server;
|
|
||||||
|
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
import pp.monopoly.game.server.Player;
|
||||||
|
import pp.monopoly.message.server.DiceResult;
|
||||||
|
import pp.monopoly.message.server.JailEvent;
|
||||||
|
import pp.util.config.Config.Property;
|
||||||
|
|
||||||
|
import static org.junit.Assert.*;
|
||||||
import static org.junit.Assert.assertEquals;
|
import static org.mockito.Mockito.*;
|
||||||
|
|
||||||
|
|
||||||
public class ServerGameLogicTest {
|
public class ServerGameLogicTest {
|
||||||
|
|
||||||
|
private Game gameMock;
|
||||||
|
private PlayerHandler playerHandlerMock;
|
||||||
|
private Player playerMock;
|
||||||
|
|
||||||
|
@Before
|
||||||
|
public void setUp() {
|
||||||
|
gameMock = mock(Game.class);
|
||||||
|
playerHandlerMock = mock(PlayerHandler.class);
|
||||||
|
playerMock = mock(Player.class);
|
||||||
|
|
||||||
|
when(gameMock.getPlayerHandler()).thenReturn(playerHandlerMock);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
// T026: UC-gameplay-01 - Überprüfen, ob der Spieler erfolgreich würfeln kann
|
||||||
|
public void testRollDice() {
|
||||||
|
DiceResult diceResult = new DiceResult(3, 4);
|
||||||
|
|
||||||
|
when(gameMock.rollDice()).thenReturn(diceResult);
|
||||||
|
|
||||||
|
DiceResult result = gameMock.rollDice();
|
||||||
|
|
||||||
|
assertNotNull("Das Würfelergebnis sollte nicht null sein", result);
|
||||||
|
assertTrue("Die Würfelzahl 1 sollte zwischen 1 und 6 liegen", result.getDice1() >= 1 && result.getDice1() <= 6);
|
||||||
|
assertTrue("Die Würfelzahl 2 sollte zwischen 1 und 6 liegen", result.getDice2() >= 1 && result.getDice2() <= 6);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
// T027: UC-gameplay-01 - Überprüfen, ob der Spieler die richtige Anzahl an Feldern basierend auf dem Wurf bewegt
|
||||||
|
public void testMovePlayer() {
|
||||||
|
when(gameMock.getCurrentPlayer()).thenReturn(playerMock);
|
||||||
|
DiceResult diceResult = new DiceResult(3, 4);
|
||||||
|
when(gameMock.rollDice()).thenReturn(diceResult);
|
||||||
|
|
||||||
|
gameMock.receivedEvent(diceResult);
|
||||||
|
|
||||||
|
verify(playerHandlerMock).movePlayer(playerMock, diceResult.getTotal());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
// T028: UC-gameplay-02 - Überprüft, ob die Würfel zufällige Zahlen generieren
|
||||||
|
public void testGenerationDice() {
|
||||||
|
boolean isRandom = false;
|
||||||
|
DiceResult previousResult = null;
|
||||||
|
|
||||||
|
for (int i = 0; i < 10; i++) {
|
||||||
|
DiceResult currentResult = gameMock.rollDice();
|
||||||
|
|
||||||
|
assertNotNull("Das Würfelergebnis sollte nicht null sein", currentResult);
|
||||||
|
assertTrue("Die Würfelzahl 1 sollte zwischen 1 und 6 liegen", currentResult.getDice1() >= 1 && currentResult.getDice1() <= 6);
|
||||||
|
assertTrue("Die Würfelzahl 2 sollte zwischen 1 und 6 liegen", currentResult.getDice2() >= 1 && currentResult.getDice2() <= 6);
|
||||||
|
|
||||||
|
if (previousResult != null && (currentResult.getDice1() != previousResult.getDice1() || currentResult.getDice2() != previousResult.getDice2())) {
|
||||||
|
isRandom = true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
previousResult = currentResult;
|
||||||
|
}
|
||||||
|
|
||||||
|
assertTrue("Die Würfelergebnisse sollten zufällig sein", isRandom);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
// T029: UC-gameplay-03 - Überprüft, ob die richtigen Augenzahlen angezeigt werden
|
||||||
|
public void testDisplayResults() {
|
||||||
|
DiceResult diceResult = new DiceResult(3, 4);
|
||||||
|
|
||||||
|
gameMock.receivedEvent(diceResult);
|
||||||
|
|
||||||
|
assertEquals("Die Summe sollte korrekt berechnet werden", diceResult.getTotal(), diceResult.getDice1() + diceResult.getDice2());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
// T030: UC-gameplay-04 - Überprüfen, ob die Summe der Würfelergebnisse korrekt berechnet wird
|
||||||
|
public void testSumDiceResults() {
|
||||||
|
DiceResult diceResult = new DiceResult(3, 5);
|
||||||
|
|
||||||
|
gameMock.receivedEvent(diceResult);
|
||||||
|
|
||||||
|
assertEquals("Die Summe der Würfelergebnisse sollte korrekt berechnet werden", 8, diceResult.getTotal());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
// T031: UC-gameplay-05 - Überprüfen, ob die Würfel nach dem Wurf ausgegraut werden
|
||||||
|
public void testGrayOutDiceAfterRoll() {
|
||||||
|
DiceResult diceResult = new DiceResult(3, 4);
|
||||||
|
|
||||||
|
gameMock.receivedEvent(diceResult);
|
||||||
|
|
||||||
|
verify(gameMock).setDiceGrayedOut(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
// T032: UC-gameplay-06 - Überprüfen, ob das Würfeln eines Paschs erkannt wird
|
||||||
|
public void testDetectDouble() {
|
||||||
|
DiceResult diceResult = new DiceResult(4, 4);
|
||||||
|
|
||||||
|
gameMock.receivedEvent(diceResult);
|
||||||
|
|
||||||
|
verify(gameMock).handleDoubleRoll(diceResult);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
// T033: UC-gameplay-06 - Überprüfen, ob der Spieler bei einem Pasch erneut würfeln darf
|
||||||
|
public void testDoubleRoll() {
|
||||||
|
DiceResult diceResult = new DiceResult(6, 6);
|
||||||
|
|
||||||
|
gameMock.receivedEvent(diceResult);
|
||||||
|
|
||||||
|
verify(gameMock).allowExtraRoll(playerMock);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
// T034: UC-gameplay-06 - Überprüfen, ob der Spieler nach dem dritten Pasch ins Gulag muss
|
||||||
|
public void testTripleDoubleGulag() {
|
||||||
|
when(playerHandlerMock.getDoubleRollCount(playerMock)).thenReturn(3);
|
||||||
|
|
||||||
|
gameMock.receivedEvent(new DiceResult(6, 6));
|
||||||
|
|
||||||
|
verify(playerHandlerMock).setPlayerState(playerMock, PlayerState.IN_JAIL);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
// T035: UC-gameplay-07 - Überprüfen, ob der Spieler ein Grundstück kaufen kann
|
||||||
|
public void testBuyProperty() {
|
||||||
|
Property property = new Property("TestProperty", 200, null);
|
||||||
|
BuyPropertyResponse buyResponse = new BuyPropertyResponse(true, property);
|
||||||
|
|
||||||
|
gameMock.receivedEvent(buyResponse);
|
||||||
|
|
||||||
|
verify(playerHandlerMock).addPropertyToPlayer(playerMock, property);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
// T036: UC-gameplay-08 - Überprüfen, ob der Spieler Miete an den Eigentümer zahlt
|
||||||
|
public void testPayRent() {
|
||||||
|
Player ownerMock = mock(Player.class);
|
||||||
|
Property property = new Property("TestProperty", 200, ownerMock);
|
||||||
|
PayRent payRent = new PayRent(50);
|
||||||
|
|
||||||
|
when(gameMock.getCurrentPlayer()).thenReturn(playerMock);
|
||||||
|
|
||||||
|
gameMock.receivedEvent(payRent);
|
||||||
|
|
||||||
|
verify(playerMock).deductMoney(50);
|
||||||
|
verify(ownerMock).addMoney(50);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
// T037: UC-gameplay-09 - Überprüfen, ob der Spieler in den Gulag geschickt wird
|
||||||
|
public void testGoToGulag() {
|
||||||
|
JailEvent jailEvent = new JailEvent();
|
||||||
|
|
||||||
|
gameMock.receivedEvent(jailEvent);
|
||||||
|
|
||||||
|
verify(playerHandlerMock).setPlayerState(playerMock, PlayerState.IN_JAIL);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
// T038: UC-gameplay-10 - Überprüfen, ob der Spieler Häuser auf Grundstücken bauen kann
|
||||||
|
public void testBuildHouses() {
|
||||||
|
Property property = new Property("TestProperty", 200, playerMock);
|
||||||
|
property.setHouses(2);
|
||||||
|
BuildHouses buildHousesEvent = new BuildHouses(property, 1);
|
||||||
|
|
||||||
|
gameMock.receivedEvent(buildHousesEvent);
|
||||||
|
|
||||||
|
assertEquals("Die Anzahl der Häuser sollte korrekt erhöht werden", 3, property.getHouses());
|
||||||
|
verify(playerMock).deductMoney(anyInt());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
// T039: UC-gameplay-10 - Überprüfen, ob der Spieler nicht mehr als vier Häuser bauen kann
|
||||||
|
public void testMaxBuildHouses() {
|
||||||
|
Property property = new Property("TestProperty", 200, playerMock);
|
||||||
|
property.setHouses(4);
|
||||||
|
BuildHouses buildHousesEvent = new BuildHouses(property, 1);
|
||||||
|
|
||||||
|
gameMock.receivedEvent(buildHousesEvent);
|
||||||
|
|
||||||
|
assertEquals("Die Anzahl der Häuser sollte nicht über vier hinausgehen", 4, property.getHouses());
|
||||||
|
verify(playerMock, never()).deductMoney(anyInt());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
// T040: UC-gameplay-11 - Überprüfen, ob der Spieler eine Hypothek auf ein Grundstück aufnehmen kann
|
||||||
|
public void testTakeMortgage() {
|
||||||
|
Property property = new Property("TestProperty", 200, playerMock);
|
||||||
|
TakeMortgage takeMortgageEvent = new TakeMortgage(property);
|
||||||
|
|
||||||
|
gameMock.receivedEvent(takeMortgageEvent);
|
||||||
|
|
||||||
|
assertTrue("Das Grundstück sollte als hypothekarisch markiert sein", property.isMortgaged());
|
||||||
|
verify(playerMock).addMoney(anyInt());
|
||||||
|
}
|
||||||
|
@Test
|
||||||
|
// T041: UC-gameplay-12 - Überprüfen, ob eine Würfelanimation ausgelöst wird
|
||||||
|
public void testDiceRollAnimation() {
|
||||||
|
gameMock.triggerDiceRollAnimation(playerMock);
|
||||||
|
|
||||||
|
verify(gameMock).setDiceGrayedOut(false);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
// T042: UC-gameplay-13 - Überprüfen, ob Steuern korrekt berechnet und gezahlt werden
|
||||||
|
public void testPayTaxes() {
|
||||||
|
when(gameMock.getCurrentPlayer()).thenReturn(playerMock);
|
||||||
|
int taxAmount = 200;
|
||||||
|
|
||||||
|
gameMock.receivedEvent(new TaxEvent(taxAmount));
|
||||||
|
|
||||||
|
verify(playerMock).deductMoney(taxAmount);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
// T043: UC-gameplay-14 - Überprüfen, ob die Hypothek korrekt zurückgezahlt wird
|
||||||
|
public void testPayBackMortgage() {
|
||||||
|
Property property = new Property("TestProperty", 200, playerMock);
|
||||||
|
property.setMortgaged(true);
|
||||||
|
|
||||||
|
gameMock.receivedEvent(new PayBackMortgageEvent(property));
|
||||||
|
|
||||||
|
assertFalse("Die Hypothek sollte zurückgezahlt sein", property.isMortgaged());
|
||||||
|
verify(playerMock).deductMoney(property.getMortgageValue());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
// T044: UC-gameplay-15 - Überprüfen, ob eine Ereigniskarte gezogen wird
|
||||||
|
public void testDrawEventCard() {
|
||||||
|
EventCard eventCard = new EventCard("TestEvent", "Move to Go");
|
||||||
|
|
||||||
|
when(gameMock.drawEventCard()).thenReturn(eventCard);
|
||||||
|
|
||||||
|
EventCard drawnCard = gameMock.drawEventCard();
|
||||||
|
|
||||||
|
assertNotNull("Die Ereigniskarte sollte gezogen werden", drawnCard);
|
||||||
|
assertEquals("Der Name der Karte sollte korrekt sein", "TestEvent", drawnCard.getName());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
// T045: UC-gameplay-16 - Überprüfen, ob ein Spieler ein Hotel bauen kann
|
||||||
|
public void testBuildHotel() {
|
||||||
|
Property property = new Property("TestProperty", 200, playerMock);
|
||||||
|
property.setHouses(4);
|
||||||
|
|
||||||
|
gameMock.receivedEvent(new BuildHotelEvent(property));
|
||||||
|
|
||||||
|
assertTrue("Das Grundstück sollte ein Hotel haben", property.hasHotel());
|
||||||
|
verify(playerMock).deductMoney(anyInt());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
// T046: UC-gameplay-17 - Überprüfen, ob der Zug korrekt zum nächsten Spieler wechselt
|
||||||
|
public void testSwitchTurnToNextPlayer() {
|
||||||
|
Player nextPlayerMock = mock(Player.class);
|
||||||
|
|
||||||
|
when(playerHandlerMock.getNextPlayer()).thenReturn(nextPlayerMock);
|
||||||
|
|
||||||
|
gameMock.endTurn(playerMock);
|
||||||
|
|
||||||
|
verify(playerHandlerMock).setPlayerState(playerMock, PlayerState.WAIT_FOR_TURN);
|
||||||
|
verify(playerHandlerMock).setPlayerState(nextPlayerMock, PlayerState.ACTIVE);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@Test
|
||||||
|
// T047: UC-gameplay-18 - Überprüfen, ob die Kamera den aktuellen Spieler fokussiert
|
||||||
|
public void testChangeCameraFocus() {
|
||||||
|
gameMock.updateCameraFocus(playerMock);
|
||||||
|
|
||||||
|
verify(gameMock).updateCameraFocus(playerMock);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
// T048: UC-gameplay-20 - Überprüfen, ob der Spieler korrekt Strafzahlungen leistet
|
||||||
|
public void testPenaltyPayment() {
|
||||||
|
int penaltyAmount = 300;
|
||||||
|
|
||||||
|
gameMock.receivedEvent(new PenaltyEvent(penaltyAmount));
|
||||||
|
|
||||||
|
verify(playerMock).deductMoney(penaltyAmount);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
// T049: UC-gameplay-21 - Überprüfen, ob ein Spieler Strafzahlungen korrekt erhält
|
||||||
|
public void testReceivePenaltyPayment() {
|
||||||
|
Player penaltyReceiverMock = mock(Player.class);
|
||||||
|
int penaltyAmount = 300;
|
||||||
|
|
||||||
|
gameMock.receivedEvent(new PenaltyReceivedEvent(penaltyReceiverMock, penaltyAmount));
|
||||||
|
|
||||||
|
verify(penaltyReceiverMock).addMoney(penaltyAmount);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test // ???????
|
||||||
|
// T050: UC-gameplay-22 - Überprüfen, ob ein Spieler das Gulag erfolgreich verlässt
|
||||||
|
public void testLeaveGulag() {
|
||||||
|
JailEvent leaveGulagEvent = new JailEvent(false); // false = Gulag verlassen ???
|
||||||
|
|
||||||
|
gameMock.receivedEvent(leaveGulagEvent);
|
||||||
|
|
||||||
|
verify(playerHandlerMock).setPlayerState(playerMock, PlayerState.ACTIVE);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
// T051: UC-gameplay-23 - Überprüfen, ob die Spielerreihenfolge korrekt bestimmt wird
|
||||||
|
public void testDetermineTurnOrder() {
|
||||||
|
when(playerHandlerMock.determineTurnOrder()).thenReturn(true);
|
||||||
|
|
||||||
|
boolean result = playerHandlerMock.determineTurnOrder();
|
||||||
|
|
||||||
|
assertTrue("Die Spielreihenfolge sollte korrekt bestimmt werden", result);
|
||||||
|
verify(playerHandlerMock).determineTurnOrder();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
// T052: UC-gameplay-24 - Überprüfen, ob ein Spieler korrekt Bankrott erklärt wird
|
||||||
|
public void testDeclareBankruptcy() {
|
||||||
|
BankruptcyEvent bankruptcyEvent = new BankruptcyEvent(playerMock);
|
||||||
|
|
||||||
|
gameMock.receivedEvent(bankruptcyEvent);
|
||||||
|
|
||||||
|
|
||||||
|
verify(playerHandlerMock).setPlayerState(playerMock, PlayerState.BANKRUPT);
|
||||||
|
|
||||||
|
|
||||||
|
verify(playerHandlerMock).transferAssetsToBank(playerMock);
|
||||||
|
|
||||||
|
|
||||||
|
verify(gameMock, never()).updatePlayerGameState(playerMock, GameState.GAME_OVER);
|
||||||
|
}
|
||||||
|
@Test
|
||||||
|
// T053: UC-gameplay-25 - Überprüfen, ob ein Spieler durch einen anderen Spieler bankrott geht
|
||||||
|
public void testBankruptcyByPlayer() {
|
||||||
|
Player otherPlayerMock;
|
||||||
|
Property property = new Property("TestProperty", 200, otherPlayerMock);
|
||||||
|
PayRent payRentEvent = new PayRent(300);
|
||||||
|
otherPlayerMock = mock(Player.class);
|
||||||
|
|
||||||
|
when(playerMock.getBalance()).thenReturn(200); // Spieler hat zu wenig Geld
|
||||||
|
when(gameMock.getCurrentPlayer()).thenReturn(playerMock);
|
||||||
|
|
||||||
|
gameMock.receivedEvent(payRentEvent);
|
||||||
|
|
||||||
|
verify(playerHandlerMock).setPlayerState(playerMock, PlayerState.BANKRUPT);
|
||||||
|
verify(playerHandlerMock).transferAssetsToPlayer(playerMock, otherPlayerMock); // kriegt die Bank die assets oder otherPlayer????
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
// T054: UC-gameplay-26 - Überprüfen, ob das Spiel endet, wenn alle Spieler bis auf einen bankrott sind
|
||||||
|
public void testGameOverBankruptcy() {
|
||||||
|
when(playerHandlerMock.getRemainingPlayersCount()).thenReturn(1);
|
||||||
|
|
||||||
|
gameMock.checkGameOver();
|
||||||
|
|
||||||
|
verify(gameMock).endGame();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
// T055: UC-gameplay-28 - Überprüfen, ob der Sieger korrekt angezeigt wird, wenn nur ein Spieler übrig bleibt
|
||||||
|
public void testGameOverWinner() {
|
||||||
|
when(playerHandlerMock.getRemainingPlayersCount()).thenReturn(1);
|
||||||
|
when(playerHandlerMock.getLastRemainingPlayer()).thenReturn(playerMock);
|
||||||
|
|
||||||
|
gameMock.checkGameOver();
|
||||||
|
|
||||||
|
verify(playerHandlerMock).setPlayerState(playerMock, PlayerState.WINNER);
|
||||||
|
verify(gameMock).endGame();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
// T056: UC-gameplay-29 - Überprüfen, ob ein Ereignisfeld eine zufällige Karte auslöst
|
||||||
|
public void testTriggerEventTile() {
|
||||||
|
EventField eventField = mock(EventField.class);
|
||||||
|
EventCard eventCard = mock(EventCard.class);
|
||||||
|
|
||||||
|
when(eventField.drawCard()).thenReturn(eventCard);
|
||||||
|
|
||||||
|
gameMock.triggerEventTile(eventField);
|
||||||
|
|
||||||
|
verify(eventField).drawCard();
|
||||||
|
verify(gameMock).applyEventCard(eventCard); //???
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
// T057: UC-gameplay-30 - Überprüfen, ob der Spieler beim Erreichen des Gulag-Feldes in den Gulag geschickt wird
|
||||||
|
public void testTriggerGulagTransfer() {
|
||||||
|
// Setzt die fieldId des Spielers auf das Gulag-Feld
|
||||||
|
when(playerMock.getFieldId()).thenReturn(30);
|
||||||
|
|
||||||
|
// Simuliert das Ereignis, dass der Spieler auf ein Feld tritt
|
||||||
|
gameMock.triggerFieldAction(playerMock);
|
||||||
|
|
||||||
|
// Überprüft, ob der Spielerzustand auf IN_JAIL gesetzt wird
|
||||||
|
verify(playerHandlerMock).setPlayerState(playerMock, PlayerState.IN_JAIL);
|
||||||
|
}
|
||||||
|
@Test
|
||||||
|
// T058: UC-gameplay-31 - Überprüfen, ob ein Spieler eine Karte kaufen kann
|
||||||
|
public void testBuyCard() {
|
||||||
|
Property property = new Property("TestProperty", 200, null);
|
||||||
|
BuyPropertyResponse buyPropertyResponse = new BuyPropertyResponse(true, property);
|
||||||
|
|
||||||
|
gameMock.receivedEvent(buyPropertyResponse);
|
||||||
|
|
||||||
|
verify(playerHandlerMock).addPropertyToPlayer(playerMock, property);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
// T059: UC-gameplay-32 - Überprüfen, ob der Kartenerwerb fehlschlägt, wenn der Spieler nicht genug Geld hat
|
||||||
|
public void testCardPurchaseFailed() {
|
||||||
|
Property property = new Property("TestProperty", 500, null);
|
||||||
|
when(playerMock.getBalance()).thenReturn(300); // Spieler hat nicht genug Geld
|
||||||
|
|
||||||
|
BuyPropertyRequest buyPropertyRequest = new BuyPropertyRequest(property);
|
||||||
|
|
||||||
|
gameMock.receivedEvent(buyPropertyRequest);
|
||||||
|
|
||||||
|
verify(playerHandlerMock, never()).addPropertyToPlayer(playerMock, property);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
// T060: UC-gameplay-33 - Überprüfen, ob der Spieler korrekt Miete zahlt, wenn er auf einem besetzten Grundstück landet
|
||||||
|
public void testPayRent() {
|
||||||
|
Property property = new Property("TestProperty", 200, otherPlayerMock);
|
||||||
|
PayRent payRentEvent = new PayRent(50);
|
||||||
|
Player otherPlayerMock = mock(Player.class);
|
||||||
|
|
||||||
|
when(gameMock.getCurrentPlayer()).thenReturn(playerMock);
|
||||||
|
|
||||||
|
gameMock.receivedEvent(payRentEvent);
|
||||||
|
|
||||||
|
verify(playerMock).payRent(50);
|
||||||
|
verify(otherPlayerMock).addMoney(50);
|
||||||
|
}
|
||||||
|
@Test
|
||||||
|
// T061: UC-gameplay-34 - Überprüfen, ob eine Warnung angezeigt wird, wenn der Spieler Schulden hat
|
||||||
|
public void testDebtWarning() {
|
||||||
|
when(playerMock.getBalance()).thenReturn(-100);
|
||||||
|
|
||||||
|
gameMock.triggerDebtWarning(playerMock);
|
||||||
|
|
||||||
|
verify(gameMock).sendMessage(new DebtWarning(playerMock));
|
||||||
|
assertTrue("Der Spieler sollte in den Schuldenbereich geraten sein", playerMock.getBalance() < 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
// T062: UC-gameplay-35 - Überprüfen, ob der Spieler aufgrund einer Strafe eine Runde aussetzt
|
||||||
|
public void testSkipTurnDueToPenalty() {
|
||||||
|
PenaltyEvent penaltyEvent = new PenaltyEvent(1); // Spieler muss 1 Runde aussetzen
|
||||||
|
|
||||||
|
when(playerHandlerMock.getPlayerState(playerMock)).thenReturn(PlayerState.ACTIVE);
|
||||||
|
|
||||||
|
gameMock.receivedEvent(penaltyEvent);
|
||||||
|
|
||||||
|
verify(playerHandlerMock).skipTurn(playerMock, 1);
|
||||||
|
verify(playerHandlerMock).setPlayerState(playerMock, PlayerState.WAIT_FOR_TURN);
|
||||||
|
assertEquals("Der Spieler sollte in den Zustand 'WaitForTurn' wechseln", PlayerState.WAIT_FOR_TURN, playerHandlerMock.getPlayerState(playerMock));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
// T063: UC-gameplay-36 - Überprüfen, ob das Vermögen des Spielers korrekt angezeigt wird
|
||||||
|
public void testShowPlayerAssets() {
|
||||||
|
PlayerAssets playerAssets = new PlayerAssets(1000, 3); // Beispielvermögen und Grundstücke
|
||||||
|
when(playerMock.getAssets()).thenReturn(playerAssets);
|
||||||
|
|
||||||
|
gameMock.sendPlayerAssets(playerMock);
|
||||||
|
|
||||||
|
verify(gameMock).sendMessage(new PlayerAssetsResponse(playerAssets));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
// T064: UC-gameplay-37 - Überprüfen, ob die Anzeige korrekt ist, wenn der Spieler keine "Gulag-Frei"-Karte hat
|
||||||
|
public void testNoGulagFreeCardDisplay() {
|
||||||
|
when(playerMock.getGulagFreeCards()).thenReturn(0);
|
||||||
|
|
||||||
|
gameMock.updateGulagCardDisplay(playerMock);
|
||||||
|
|
||||||
|
verify(gameMock).sendMessage(new GulagCardUpdate(playerMock, 0));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
// T065: UC-gameplay-37 - Überprüfen, ob die Anzeige korrekt ist, wenn der Spieler eine "Gulag-Frei"-Karte hat
|
||||||
|
public void testOneGulagFreeCardDisplay() {
|
||||||
|
when(playerMock.getGulagFreeCards()).thenReturn(1);
|
||||||
|
|
||||||
|
gameMock.updateGulagCardDisplay(playerMock);
|
||||||
|
|
||||||
|
verify(gameMock).sendMessage(new GulagCardUpdate(playerMock, 1));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
// T066: UC-gameplay-37 - Überprüfen, ob die Anzeige korrekt ist, wenn der Spieler zwei "Gulag-Frei"-Karten hat
|
||||||
|
public void testTwoGulagFreeCardsDisplay() {
|
||||||
|
when(playerMock.getGulagFreeCards()).thenReturn(2);
|
||||||
|
|
||||||
|
gameMock.updateGulagCardDisplay(playerMock);
|
||||||
|
|
||||||
|
verify(gameMock).sendMessage(new GulagCardUpdate(playerMock, 2));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
// T067: UC-gameplay-38 - Überprüfen, ob die Anzahl der "Gulag-Frei"-Karten nach der Verwendung korrekt abgezogen wird
|
||||||
|
public void testTwoGulagFreeCardsDisplay() {
|
||||||
|
// Spieler hat zwei "Gulag-frei"-Karten und nutzt eine
|
||||||
|
GulagFreeCardUseEvent gulagFreeCardUseEvent = new GulagFreeCardUseEvent(playerMock);
|
||||||
|
|
||||||
|
when(playerHandlerMock.getPlayerState(playerMock)).thenReturn(PlayerState.IN_JAIL);
|
||||||
|
when(playerHandlerMock.getGulagFreeCardCount(playerMock)).thenReturn(2);
|
||||||
|
|
||||||
|
gameMock.receivedEvent(gulagFreeCardUseEvent);
|
||||||
|
|
||||||
|
verify(playerHandlerMock).useGulagFreeCard(playerMock);
|
||||||
|
verify(playerHandlerMock).setPlayerState(playerMock, PlayerState.ACTIVE);
|
||||||
|
|
||||||
|
assertEquals("Der Spieler sollte von 'InJail' auf 'Active' wechseln", PlayerState.ACTIVE, playerHandlerMock.getPlayerState(playerMock));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
// T068: UC-gameplay-39 - Überprüfen, ob die Übersicht der anderen Spieler korrekt angezeigt wird
|
||||||
|
public void testViewOtherPlayers() {
|
||||||
|
PlayerOverview overview = new PlayerOverview("Player2", 1500, 5);
|
||||||
|
when(playerHandlerMock.getOtherPlayers(playerMock)).thenReturn(List.of(overview));
|
||||||
|
|
||||||
|
gameMock.sendPlayerOverview(playerMock);
|
||||||
|
|
||||||
|
verify(gameMock).sendMessage(new PlayerOverviewResponse(List.of(overview)));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
// T069: UC-gameplay-44 - Überprüfen, ob der Spieler erfolgreich aus dem Gulag rauswürfeln kann
|
||||||
|
public void testRollToExitGulag() {
|
||||||
|
DiceResult diceResult = new DiceResult(4, 4); // Spieler würfelt Pasch
|
||||||
|
|
||||||
|
when(playerHandlerMock.InJail(playerMock)).thenReturn(true);
|
||||||
|
gameMock.receivedEvent(diceResult);
|
||||||
|
|
||||||
|
verify(playerHandlerMock).releasePlayerFromJail(playerMock);
|
||||||
|
verify(gameMock).sendMessage(new PlayerReleasedFromJail(playerMock));
|
||||||
|
verify(playerHandlerMock).setPlayerState(playerMock, PlayerState.ACTIVE);
|
||||||
|
|
||||||
|
assertEquals("Der Spieler sollte von 'InJail' auf 'Active' wechseln", PlayerState.ACTIVE, playerHandlerMock.getPlayerState(playerMock));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
// T070: UC-gameplay-44 - Überprüfen, ob das Rauswürfeln aus dem Gulag fehlschlägt, wenn die Bedingungen nicht erfüllt sind
|
||||||
|
public void testFailRollToExitGulag() {
|
||||||
|
DiceResult diceResult = new DiceResult(2, 5); // Kein Pasch
|
||||||
|
|
||||||
|
when(playerHandlerMock.InJail(playerMock)).thenReturn(true);
|
||||||
|
gameMock.receivedEvent(diceResult);
|
||||||
|
|
||||||
|
verify(playerHandlerMock, never()).releasePlayerFromJail(playerMock);
|
||||||
|
verify(gameMock).sendMessage(new JailStayNotification(playerMock));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user