From 4a80d5d3e9b28f08080ee9dddb84517f6a9e6b01 Mon Sep 17 00:00:00 2001 From: fdai7920 Date: Wed, 24 Jan 2024 13:52:29 +0100 Subject: [PATCH] Test.playCard --- .../hsfulda/onses/services/GameService.java | 5 +++ .../de/hsfulda/onses/GameServiceTest.java | 38 +++++++++++++++++++ 2 files changed, 43 insertions(+) create mode 100644 src/test/java/de/hsfulda/onses/GameServiceTest.java diff --git a/src/main/java/de/hsfulda/onses/services/GameService.java b/src/main/java/de/hsfulda/onses/services/GameService.java index 26aa2c2..b50422a 100644 --- a/src/main/java/de/hsfulda/onses/services/GameService.java +++ b/src/main/java/de/hsfulda/onses/services/GameService.java @@ -13,6 +13,10 @@ public class GameService { this(new Game()); } + public Game getGame() { + return game; + } + public void playCard(Player player, Card card) { // add lastPlayedCard back to drawCardDeck @@ -20,4 +24,5 @@ public class GameService { // check for special rules (draw, colorchoose, skip,...) } + } diff --git a/src/test/java/de/hsfulda/onses/GameServiceTest.java b/src/test/java/de/hsfulda/onses/GameServiceTest.java new file mode 100644 index 0000000..2d7f904 --- /dev/null +++ b/src/test/java/de/hsfulda/onses/GameServiceTest.java @@ -0,0 +1,38 @@ + +package de.hsfulda.onses; + +import org.junit.jupiter.api.DisplayName; +import org.junit.jupiter.api.Test; +import static org.junit.jupiter.api.Assertions.*; + +import de.hsfulda.onses.models.Card; +import de.hsfulda.onses.models.Player; +import de.hsfulda.onses.models.Game; +import de.hsfulda.onses.services.GameService; + +public class GameServiceTest { + @Test + @DisplayName("playCardRedEight") + public void playCardRedEight() { + // arrange + Card input = new Card().setColor(Card.Color.RED).setValue(Card.Value.EIGHT); + // act + GameService gameService = new GameService(); + gameService.playCard(new Player(), input); + Card answer = gameService.getGame().getLastPlayedCard(); + // assert + assertEquals(input, answer); + } + @Test + @DisplayName("playCardBlackChoose") + public void playCardBlackChoose() { + // arrange + Card input = new Card().setColor(Card.Color.BLACK).setValue(Card.Value.CHOOSE); + // act + GameService gameService = new GameService(); + gameService.playCard(new Player(), input); + Card answer = gameService.getGame().getLastPlayedCard(); + // assert + assertEquals(input, answer); + } +}