Browse Source

add removeCardFromPlayerDeck with Tests

main
fdai7736 11 months ago
parent
commit
d4bc758681
  1. 6
      src/main/java/de/hsfulda/onses/models/Player.java
  2. 17
      src/test/java/de/hsfulda/onses/PlayerTest.java

6
src/main/java/de/hsfulda/onses/models/Player.java

@ -24,6 +24,12 @@ public class Player {
this.firePropertyChange(PROPERTY_PLAYER_DECK, oldplayerDeck, playerDeck); this.firePropertyChange(PROPERTY_PLAYER_DECK, oldplayerDeck, playerDeck);
} }
public void removeCardFromPlayerDeck(Card card) {
final ArrayList<Card> oldPlayerDeck = new ArrayList<>(this.playerDeck);
this.playerDeck.remove(card);
this.firePropertyChange(PROPERTY_PLAYER_DECK, oldPlayerDeck, playerDeck);
}
public PlayerService getPlayerService() { public PlayerService getPlayerService() {
return playerService; return playerService;
} }

17
src/test/java/de/hsfulda/onses/PlayerTest.java

@ -58,4 +58,21 @@ public class PlayerTest {
assertEquals(expected, answer1); assertEquals(expected, answer1);
assertEquals(expected, answer2); assertEquals(expected, answer2);
} }
@Test
@DisplayName("remove card from player card deck")
void removeCardFromPlayerCardDeck() {
Player player = new Player();
Card card1 = new Card().setColor(Card.Color.RED).setValue(Card.Value.FIVE);
Card card2 = new Card().setColor(Card.Color.GREEN).setValue(Card.Value.ONE);
player.addCardToPlayerDeck(card1);
player.addCardToPlayerDeck(card2);
assertEquals(2, player.getPlayerDeck().size());
player.removeCardFromPlayerDeck(card1);
assertEquals(1, player.getPlayerDeck().size());
assertEquals(card2, player.getPlayerDeck().getFirst());
}
} }
Loading…
Cancel
Save