From 4d5857149ecf20d472e5a26345435ee259cad831 Mon Sep 17 00:00:00 2001 From: fdai7920 Date: Fri, 2 Feb 2024 14:05:48 +0100 Subject: [PATCH 01/11] Relationship Game-GameService --- src/main/java/de/hsfulda/onses/models/Game.java | 13 +++++++++++++ .../java/de/hsfulda/onses/services/GameService.java | 1 + 2 files changed, 14 insertions(+) diff --git a/src/main/java/de/hsfulda/onses/models/Game.java b/src/main/java/de/hsfulda/onses/models/Game.java index e5066bc..0fe4eb1 100644 --- a/src/main/java/de/hsfulda/onses/models/Game.java +++ b/src/main/java/de/hsfulda/onses/models/Game.java @@ -1,8 +1,13 @@ package de.hsfulda.onses.models; +import de.hsfulda.onses.services.GameService; + import java.util.ArrayList; public class Game { + + private GameService gameService; + private final ArrayList drawCardDeck = new ArrayList<>(); private Card lastPlayedCard = null; @@ -24,4 +29,12 @@ public class Game { drawCardDeck.add(card); } + public GameService getGameService() { + return gameService; + } + + public Game setGameService(GameService gameService) { + this.gameService = gameService; + return this; + } } diff --git a/src/main/java/de/hsfulda/onses/services/GameService.java b/src/main/java/de/hsfulda/onses/services/GameService.java index df7cf87..c9acd67 100644 --- a/src/main/java/de/hsfulda/onses/services/GameService.java +++ b/src/main/java/de/hsfulda/onses/services/GameService.java @@ -10,6 +10,7 @@ public class GameService { private final Game game; public GameService(Game game) { this.game = game; + this.game.setGameService(this); } public GameService() { this(new Game()); From 0cd4f695f31c6e47dab7c68db86587995df6a8e0 Mon Sep 17 00:00:00 2001 From: fdai7920 Date: Fri, 2 Feb 2024 14:11:29 +0100 Subject: [PATCH 02/11] Test.Relationship.Game.GameService --- src/test/java/de/hsfulda/onses/GameServiceTest.java | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/test/java/de/hsfulda/onses/GameServiceTest.java b/src/test/java/de/hsfulda/onses/GameServiceTest.java index 7be6f27..02438e8 100644 --- a/src/test/java/de/hsfulda/onses/GameServiceTest.java +++ b/src/test/java/de/hsfulda/onses/GameServiceTest.java @@ -157,4 +157,16 @@ public class GameServiceTest { } } } + + @Test + @DisplayName("RelationshipGameService_Game") + public void RelationshipGameService_Game() + { + // arrange + GameService expected = new GameService(); + //act + GameService answer = expected.getGame().getGameService(); + // assert + assertEquals(expected, answer); + } } From 7bdd76cca4faf4369e921bd7bbf3836f17982338 Mon Sep 17 00:00:00 2001 From: fdai7920 Date: Fri, 2 Feb 2024 14:34:41 +0100 Subject: [PATCH 03/11] Relationship PlayerService_Game --- src/main/java/de/hsfulda/onses/models/Game.java | 16 ++++++++++++++++ .../de/hsfulda/onses/services/PlayerService.java | 10 ++++++++++ 2 files changed, 26 insertions(+) diff --git a/src/main/java/de/hsfulda/onses/models/Game.java b/src/main/java/de/hsfulda/onses/models/Game.java index 0fe4eb1..0f9a56c 100644 --- a/src/main/java/de/hsfulda/onses/models/Game.java +++ b/src/main/java/de/hsfulda/onses/models/Game.java @@ -1,12 +1,14 @@ package de.hsfulda.onses.models; import de.hsfulda.onses.services.GameService; +import de.hsfulda.onses.services.PlayerService; import java.util.ArrayList; public class Game { private GameService gameService; + private PlayerService playerService; private final ArrayList drawCardDeck = new ArrayList<>(); @@ -37,4 +39,18 @@ public class Game { this.gameService = gameService; return this; } + + public PlayerService getPlayerService() { + return playerService; + } + + public Game setPlayerService(PlayerService playerService) { + this.playerService = playerService; + return this; + } + + public Game() + { + this.playerService = new PlayerService().setGame(this); + } } diff --git a/src/main/java/de/hsfulda/onses/services/PlayerService.java b/src/main/java/de/hsfulda/onses/services/PlayerService.java index d726af8..32d1c5e 100644 --- a/src/main/java/de/hsfulda/onses/services/PlayerService.java +++ b/src/main/java/de/hsfulda/onses/services/PlayerService.java @@ -1,11 +1,13 @@ package de.hsfulda.onses.services; +import de.hsfulda.onses.models.Game; import de.hsfulda.onses.models.Player; import java.util.ArrayList; public class PlayerService { + private Game game; private boolean currentTurn = true; // true --> real player, false --> Bot private final ArrayList playerList = new ArrayList<>(); @@ -31,4 +33,12 @@ public class PlayerService { return this; } + public Game getGame() { + return game; + } + + public PlayerService setGame(Game game) { + this.game = game; + return this; + } } From b66a34bdc7f06e5067470c7db2d0c681c629f330 Mon Sep 17 00:00:00 2001 From: fdai7920 Date: Fri, 2 Feb 2024 14:39:16 +0100 Subject: [PATCH 04/11] Test.Relationship.PlayerService.Game --- src/test/java/de/hsfulda/onses/GameTest.java | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/test/java/de/hsfulda/onses/GameTest.java b/src/test/java/de/hsfulda/onses/GameTest.java index 13bb0ff..10b0dc8 100644 --- a/src/test/java/de/hsfulda/onses/GameTest.java +++ b/src/test/java/de/hsfulda/onses/GameTest.java @@ -46,4 +46,14 @@ public class GameTest { assertEquals(game.getDrawCardDeck().getFirst(), answer1); assertEquals(game.getDrawCardDeck().get(1), answer2); } + @Test + @DisplayName("RelationshipGame_PlayerService") + public void RelationshipGame_PlayerService() { + // arrange + Game expected = new Game(); + // act + Game answer = expected.getPlayerService().getGame(); + // assert + assertEquals(expected, answer); + } } From 94fcf2b0d9e01cfc97ce3dc26bd8eb70cee5f198 Mon Sep 17 00:00:00 2001 From: fdai7920 Date: Fri, 2 Feb 2024 15:06:39 +0100 Subject: [PATCH 05/11] refactoring: update AddPlayerTest --- .../de/hsfulda/onses/PlayerServiceTest.java | 24 ++++++++++++------- 1 file changed, 16 insertions(+), 8 deletions(-) diff --git a/src/test/java/de/hsfulda/onses/PlayerServiceTest.java b/src/test/java/de/hsfulda/onses/PlayerServiceTest.java index 08630c6..855ee24 100644 --- a/src/test/java/de/hsfulda/onses/PlayerServiceTest.java +++ b/src/test/java/de/hsfulda/onses/PlayerServiceTest.java @@ -15,11 +15,15 @@ public class PlayerServiceTest { void addPlayerToPlayerList() { //arrange Player input = new Player(); - Player expected = input; + boolean expected = true; + boolean answer = false; // act PlayerService playerservice = new PlayerService(); playerservice.addPlayerToList(input); - Player answer = playerservice.getPlayerList().getFirst(); + for (Player i : playerservice.getPlayerList()) + { + if (i == input) {answer = true; break;} + } // assert assertEquals(expected, answer); } @@ -28,20 +32,24 @@ public class PlayerServiceTest { @DisplayName("addMultiplePlayerToPlayerList") void addMultiplePlayerToPlayerList() { //arrange + boolean expected = true; Player input1 = new Player(); - Player expected1 = input1; + boolean answer1 = false; Player input2 = new Player(); - Player expected2 = input2; + boolean answer2 = false; // act PlayerService playerservice = new PlayerService(); playerservice.addPlayerToList(input1); playerservice.addPlayerToList(input2); - Player answer1 = playerservice.getPlayerList().getFirst(); - Player answer2 = playerservice.getPlayerList().get(1); + for (Player i : playerservice.getPlayerList()) + { + if (i == input1) {answer1 = true;} + if (i == input2) {answer2 = true;} + } // assert - assertEquals(expected1, answer1); - assertEquals(expected2, answer2); + assertEquals(expected, answer1); + assertEquals(expected, answer2); } @Test @DisplayName("checkCurrentTurnAfterNextTurn") From 196d8041fe23a863e08d4880204776ced2318fc4 Mon Sep 17 00:00:00 2001 From: fdai7920 Date: Fri, 2 Feb 2024 15:07:45 +0100 Subject: [PATCH 06/11] Relationship Player_PlayerService --- src/main/java/de/hsfulda/onses/models/Player.java | 14 ++++++++++++++ .../de/hsfulda/onses/services/PlayerService.java | 6 ++++++ 2 files changed, 20 insertions(+) diff --git a/src/main/java/de/hsfulda/onses/models/Player.java b/src/main/java/de/hsfulda/onses/models/Player.java index 77eb2b1..3f92e8d 100644 --- a/src/main/java/de/hsfulda/onses/models/Player.java +++ b/src/main/java/de/hsfulda/onses/models/Player.java @@ -1,9 +1,12 @@ package de.hsfulda.onses.models; +import de.hsfulda.onses.services.PlayerService; + import java.util.ArrayList; public class Player { + private PlayerService playerService; private final ArrayList playerDeck = new ArrayList<>(); public ArrayList getPlayerDeck() { @@ -13,4 +16,15 @@ public class Player { public void addCardToPlayerDeck(Card card) { playerDeck.add(card); } + + + + public PlayerService getPlayerService() { + return playerService; + } + + public Player setPlayerService(PlayerService playerService) { + this.playerService = playerService; + return this; + } } diff --git a/src/main/java/de/hsfulda/onses/services/PlayerService.java b/src/main/java/de/hsfulda/onses/services/PlayerService.java index 32d1c5e..61c5eff 100644 --- a/src/main/java/de/hsfulda/onses/services/PlayerService.java +++ b/src/main/java/de/hsfulda/onses/services/PlayerService.java @@ -41,4 +41,10 @@ public class PlayerService { this.game = game; return this; } + + public PlayerService() + { + addPlayerToList(new Player().setPlayerService(this)); + addPlayerToList(new Player().setPlayerService(this)); + } } From eda7a19a790e120c00461a42b3225d0b14a20eb8 Mon Sep 17 00:00:00 2001 From: fdai7920 Date: Fri, 2 Feb 2024 15:11:10 +0100 Subject: [PATCH 07/11] Test.Relationship.Player.PlayerService --- .../java/de/hsfulda/onses/PlayerServiceTest.java | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/test/java/de/hsfulda/onses/PlayerServiceTest.java b/src/test/java/de/hsfulda/onses/PlayerServiceTest.java index 855ee24..5dc2fd2 100644 --- a/src/test/java/de/hsfulda/onses/PlayerServiceTest.java +++ b/src/test/java/de/hsfulda/onses/PlayerServiceTest.java @@ -78,4 +78,16 @@ public class PlayerServiceTest { // assert assertEquals(expected, answer); } + @Test + @DisplayName("RelationShip_Player_PlayerService") + void Relationship_Player_PlayerService() { + // arrange + PlayerService expected = new PlayerService(); + // act + PlayerService answer1 = expected.getPlayerList().getFirst().getPlayerService(); + PlayerService answer2 = expected.getPlayerList().getLast().getPlayerService(); + // assert + assertEquals(expected, answer1); + assertEquals(expected, answer2); + } } From 1a0709253e64fe4e828a29e332172cd8ed37edce Mon Sep 17 00:00:00 2001 From: fdai7920 Date: Fri, 2 Feb 2024 15:14:04 +0100 Subject: [PATCH 08/11] Relationship Player_PlayerService --- src/main/java/de/hsfulda/onses/models/Player.java | 10 ++++++++++ .../java/de/hsfulda/onses/services/PlayerService.java | 4 ++-- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/src/main/java/de/hsfulda/onses/models/Player.java b/src/main/java/de/hsfulda/onses/models/Player.java index 3f92e8d..88ce707 100644 --- a/src/main/java/de/hsfulda/onses/models/Player.java +++ b/src/main/java/de/hsfulda/onses/models/Player.java @@ -7,6 +7,7 @@ import java.util.ArrayList; public class Player { private PlayerService playerService; + private Game game; private final ArrayList playerDeck = new ArrayList<>(); public ArrayList getPlayerDeck() { @@ -27,4 +28,13 @@ public class Player { this.playerService = playerService; return this; } + + public Game getGame() { + return game; + } + + public Player setGame(Game game) { + this.game = game; + return this; + } } diff --git a/src/main/java/de/hsfulda/onses/services/PlayerService.java b/src/main/java/de/hsfulda/onses/services/PlayerService.java index 61c5eff..a9f651e 100644 --- a/src/main/java/de/hsfulda/onses/services/PlayerService.java +++ b/src/main/java/de/hsfulda/onses/services/PlayerService.java @@ -44,7 +44,7 @@ public class PlayerService { public PlayerService() { - addPlayerToList(new Player().setPlayerService(this)); - addPlayerToList(new Player().setPlayerService(this)); + addPlayerToList(new Player().setPlayerService(this).setGame(this.game)); + addPlayerToList(new Player().setPlayerService(this).setGame(this.game)); } } From 32f5d0372075730412156463a635018b3746bbbd Mon Sep 17 00:00:00 2001 From: fdai7920 Date: Fri, 2 Feb 2024 15:18:31 +0100 Subject: [PATCH 09/11] Test.Relationship.Player.Game --- src/test/java/de/hsfulda/onses/PlayerTest.java | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/test/java/de/hsfulda/onses/PlayerTest.java b/src/test/java/de/hsfulda/onses/PlayerTest.java index 80c68d5..fcdeeac 100644 --- a/src/test/java/de/hsfulda/onses/PlayerTest.java +++ b/src/test/java/de/hsfulda/onses/PlayerTest.java @@ -1,6 +1,8 @@ package de.hsfulda.onses; +import de.hsfulda.onses.models.Game; +import de.hsfulda.onses.services.PlayerService; import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; import static org.junit.jupiter.api.Assertions.*; @@ -43,4 +45,17 @@ public class PlayerTest { assertEquals(testCard1, firstCardPlayerDeck); assertEquals(testCard2, secondCardPlayerDeck); } + @Test + @DisplayName("Relationship_Player_Game") + void Relationship_Player_Game() { + // arrange + PlayerService input = new PlayerService(); + Game expected = input.getGame(); + // act + Game answer1 = input.getPlayerList().getFirst().getPlayerService().getGame(); + Game answer2 = input.getPlayerList().getLast().getPlayerService().getGame(); + // assert + assertEquals(expected, answer1); + assertEquals(expected, answer2); + } } From 57763309bfa8ef382e288e4a9e70c47a67a9b83f Mon Sep 17 00:00:00 2001 From: fdai7920 Date: Fri, 2 Feb 2024 15:34:34 +0100 Subject: [PATCH 10/11] refactoring: divided function in 2 parts --- src/main/java/de/hsfulda/onses/services/PlayerService.java | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/main/java/de/hsfulda/onses/services/PlayerService.java b/src/main/java/de/hsfulda/onses/services/PlayerService.java index a9f651e..b3b4cc4 100644 --- a/src/main/java/de/hsfulda/onses/services/PlayerService.java +++ b/src/main/java/de/hsfulda/onses/services/PlayerService.java @@ -39,12 +39,14 @@ public class PlayerService { public PlayerService setGame(Game game) { this.game = game; + playerList.getFirst().setGame(this.game); + playerList.getLast().setGame(this.game); return this; } public PlayerService() { - addPlayerToList(new Player().setPlayerService(this).setGame(this.game)); - addPlayerToList(new Player().setPlayerService(this).setGame(this.game)); + addPlayerToList(new Player().setPlayerService(this)); + addPlayerToList(new Player().setPlayerService(this)); } } From 67855c0c2c40cc8fb9c94cce91efcd836f860916 Mon Sep 17 00:00:00 2001 From: fdai7920 Date: Fri, 2 Feb 2024 15:36:06 +0100 Subject: [PATCH 11/11] Test.finalRelationsTest --- .../java/de/hsfulda/onses/GameServiceTest.java | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/src/test/java/de/hsfulda/onses/GameServiceTest.java b/src/test/java/de/hsfulda/onses/GameServiceTest.java index 02438e8..c76e1d4 100644 --- a/src/test/java/de/hsfulda/onses/GameServiceTest.java +++ b/src/test/java/de/hsfulda/onses/GameServiceTest.java @@ -169,4 +169,20 @@ public class GameServiceTest { // assert assertEquals(expected, answer); } + @Test + @DisplayName("allRelationsTest") + public void allRelationsTest () + { + // arrange + GameService expected = new GameService(); + //act + Player input1 = expected.getGame().getPlayerService().getPlayerList().getFirst(); + Player input2 = expected.getGame().getPlayerService().getPlayerList().getLast(); + GameService answer1 = input1.getPlayerService().getGame().getGameService(); + GameService answer2 = input2.getGame().getGameService(); + // assert + assertEquals(expected, answer1); + assertEquals(expected, answer2); + } + }