fixed failing test, due to wrong assertions or missing messages, as well as rewriting the 'addBonusCards()' method in Game to not use duplicates
This commit is contained in:
@@ -5,6 +5,8 @@
|
|||||||
import pp.mdga.game.card.SwapCard;
|
import pp.mdga.game.card.SwapCard;
|
||||||
import pp.mdga.game.card.TurboCard;
|
import pp.mdga.game.card.TurboCard;
|
||||||
|
|
||||||
|
import java.lang.reflect.Constructor;
|
||||||
|
import java.lang.reflect.InvocationTargetException;
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -134,7 +136,20 @@ public PowerCard draw() {
|
|||||||
* @param count the number of cards to add
|
* @param count the number of cards to add
|
||||||
*/
|
*/
|
||||||
private void addBonusCards(PowerCard card, int count) {
|
private void addBonusCards(PowerCard card, int count) {
|
||||||
drawPile.addAll(Collections.nCopies(count, card));
|
Class<? extends PowerCard> cardClass = card.getClass();
|
||||||
|
try {
|
||||||
|
// Get the constructor for the PowerCard class
|
||||||
|
Constructor<? extends PowerCard> constructor = cardClass.getDeclaredConstructor();
|
||||||
|
constructor.setAccessible(true); // Necessary if the constructor is not public
|
||||||
|
|
||||||
|
for (int i = 0; i < count; i++) {
|
||||||
|
// Create a new instance of the PowerCard
|
||||||
|
PowerCard newCard = constructor.newInstance();
|
||||||
|
this.drawPile.add(newCard);
|
||||||
|
}
|
||||||
|
} catch (InstantiationException | IllegalAccessException | InvocationTargetException | NoSuchMethodException e) {
|
||||||
|
e.printStackTrace(); // Log any issues with reflection
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -145,6 +145,7 @@ public void testDeselectTSK() {
|
|||||||
serverGameLogic.setCurrentState(lobbyState);
|
serverGameLogic.setCurrentState(lobbyState);
|
||||||
assertEquals(lobbyState, serverGameLogic.getCurrentState());
|
assertEquals(lobbyState, serverGameLogic.getCurrentState());
|
||||||
|
|
||||||
|
serverGameLogic.received(selectTSKMessage, IDClient);
|
||||||
assertEquals(Color.CYBER, serverGameLogic.getGame().getPlayerById(IDClient).getColor());
|
assertEquals(Color.CYBER, serverGameLogic.getGame().getPlayerById(IDClient).getColor());
|
||||||
serverGameLogic.received(deselectTSKMessage, IDClient);
|
serverGameLogic.received(deselectTSKMessage, IDClient);
|
||||||
assertEquals(Color.NONE, serverGameLogic.getGame().getPlayerById(IDClient).getColor());
|
assertEquals(Color.NONE, serverGameLogic.getGame().getPlayerById(IDClient).getColor());
|
||||||
@@ -189,7 +190,7 @@ public void testReady() {
|
|||||||
|
|
||||||
// Send a LobbyReadyMessage and validate the player is marked as ready
|
// Send a LobbyReadyMessage and validate the player is marked as ready
|
||||||
serverGameLogic.received(readyMessage, IDClient);
|
serverGameLogic.received(readyMessage, IDClient);
|
||||||
assertFalse(serverGameLogic.getGame().getPlayerById(IDClient).isReady());
|
assertTrue(serverGameLogic.getGame().getPlayerById(IDClient).isReady());
|
||||||
|
|
||||||
serverGameLogic.received(readyMessage, IDHost);
|
serverGameLogic.received(readyMessage, IDHost);
|
||||||
assertTrue(serverGameLogic.getGame().getPlayerById(IDHost).isReady());
|
assertTrue(serverGameLogic.getGame().getPlayerById(IDHost).isReady());
|
||||||
|
|||||||
@@ -684,6 +684,8 @@ public void testReachBonusField() {
|
|||||||
|
|
||||||
//gets the top bonusCard
|
//gets the top bonusCard
|
||||||
PowerCard card = game.getDrawPile().get(0);
|
PowerCard card = game.getDrawPile().get(0);
|
||||||
|
System.out.println(card);
|
||||||
|
System.out.println(game.getDrawPile().get(1));
|
||||||
|
|
||||||
//sets the dice-seed to 4
|
//sets the dice-seed to 4
|
||||||
game.setDie(die4);
|
game.setDie(die4);
|
||||||
@@ -700,8 +702,8 @@ public void testReachBonusField() {
|
|||||||
assertEquals(game.getBoard().getInfield()[4].getOccupant(),pieceHost3);
|
assertEquals(game.getBoard().getInfield()[4].getOccupant(),pieceHost3);
|
||||||
|
|
||||||
//tests if the player has received a bonusCard
|
//tests if the player has received a bonusCard
|
||||||
assertNotEquals(card, game.getDrawPile().get(0));
|
|
||||||
assertTrue(game.getPlayers().get(IDHost).getHandCards().stream().toList().contains(card));
|
assertTrue(game.getPlayers().get(IDHost).getHandCards().stream().toList().contains(card));
|
||||||
|
assertNotEquals(card, game.getDrawPile().get(0));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
Reference in New Issue
Block a user