From d4bc758681c97f67bec91b87ed9f932b4e9e12a2 Mon Sep 17 00:00:00 2001 From: fdai7736 Date: Wed, 7 Feb 2024 16:35:08 +0100 Subject: [PATCH] add removeCardFromPlayerDeck with Tests --- .../java/de/hsfulda/onses/models/Player.java | 6 ++++++ src/test/java/de/hsfulda/onses/PlayerTest.java | 17 +++++++++++++++++ 2 files changed, 23 insertions(+) diff --git a/src/main/java/de/hsfulda/onses/models/Player.java b/src/main/java/de/hsfulda/onses/models/Player.java index 09696bd..e0a9b23 100644 --- a/src/main/java/de/hsfulda/onses/models/Player.java +++ b/src/main/java/de/hsfulda/onses/models/Player.java @@ -24,6 +24,12 @@ public class Player { this.firePropertyChange(PROPERTY_PLAYER_DECK, oldplayerDeck, playerDeck); } + public void removeCardFromPlayerDeck(Card card) { + final ArrayList oldPlayerDeck = new ArrayList<>(this.playerDeck); + this.playerDeck.remove(card); + this.firePropertyChange(PROPERTY_PLAYER_DECK, oldPlayerDeck, playerDeck); + } + public PlayerService getPlayerService() { return playerService; } diff --git a/src/test/java/de/hsfulda/onses/PlayerTest.java b/src/test/java/de/hsfulda/onses/PlayerTest.java index fcdeeac..9b68f36 100644 --- a/src/test/java/de/hsfulda/onses/PlayerTest.java +++ b/src/test/java/de/hsfulda/onses/PlayerTest.java @@ -58,4 +58,21 @@ public class PlayerTest { assertEquals(expected, answer1); 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()); + } }