From bf099f2ee34a3640b91e99a6d76ff086b77c2cc1 Mon Sep 17 00:00:00 2001 From: Joffrey BION Date: Thu, 2 Feb 2017 01:02:02 +0100 Subject: Decouple Lobby and Players from the Game itself --- .../org/luxons/sevenwonders/game/LobbyTest.java | 179 -------------------- .../luxons/sevenwonders/game/boards/BoardTest.java | 12 +- .../luxons/sevenwonders/game/cards/CardTest.java | 8 +- .../sevenwonders/game/data/GameDefinitionTest.java | 10 +- .../luxons/sevenwonders/game/test/TestUtils.java | 34 +--- .../org/luxons/sevenwonders/lobby/LobbyTest.java | 181 +++++++++++++++++++++ .../repositories/GameRepositoryTest.java | 61 ------- .../repositories/LobbyRepositoryTest.java | 4 +- .../repositories/PlayerRepositoryTest.java | 2 +- .../validation/DestinationAccessValidatorTest.java | 22 +-- 10 files changed, 205 insertions(+), 308 deletions(-) delete mode 100644 backend/src/test/java/org/luxons/sevenwonders/game/LobbyTest.java create mode 100644 backend/src/test/java/org/luxons/sevenwonders/lobby/LobbyTest.java delete mode 100644 backend/src/test/java/org/luxons/sevenwonders/repositories/GameRepositoryTest.java (limited to 'backend/src/test/java') diff --git a/backend/src/test/java/org/luxons/sevenwonders/game/LobbyTest.java b/backend/src/test/java/org/luxons/sevenwonders/game/LobbyTest.java deleted file mode 100644 index b959ed96..00000000 --- a/backend/src/test/java/org/luxons/sevenwonders/game/LobbyTest.java +++ /dev/null @@ -1,179 +0,0 @@ -package org.luxons.sevenwonders.game; - -import java.util.Arrays; - -import org.junit.Before; -import org.junit.BeforeClass; -import org.junit.Rule; -import org.junit.Test; -import org.junit.experimental.theories.DataPoints; -import org.junit.experimental.theories.Theories; -import org.junit.experimental.theories.Theory; -import org.junit.rules.ExpectedException; -import org.junit.runner.RunWith; -import org.luxons.sevenwonders.game.Lobby.GameAlreadyStartedException; -import org.luxons.sevenwonders.game.Lobby.PlayerNameAlreadyUsedException; -import org.luxons.sevenwonders.game.Lobby.PlayerOverflowException; -import org.luxons.sevenwonders.game.Lobby.PlayerUnderflowException; -import org.luxons.sevenwonders.game.Lobby.UnknownPlayerException; -import org.luxons.sevenwonders.game.data.GameDefinition; -import org.luxons.sevenwonders.game.data.GameDefinitionLoader; - -import static org.junit.Assert.*; -import static org.junit.Assume.*; - -@RunWith(Theories.class) -public class LobbyTest { - - @DataPoints - public static int[] nbPlayers() { - return new int[] {1, 2, 3, 4, 5, 6, 7, 8, 9, 10}; - } - - @Rule - public ExpectedException thrown = ExpectedException.none(); - - private static GameDefinition gameDefinition; - - private Player gameOwner; - - private Lobby lobby; - - @BeforeClass - public static void loadDefinition() { - gameDefinition = new GameDefinitionLoader().getGameDefinition(); - } - - @Before - public void setUp() { - gameOwner = new Player("gameowner", "Game owner"); - lobby = new Lobby(0, "Test Game", gameOwner, gameDefinition); - } - - @Test - public void testId() { - Lobby l = new Lobby(5, "Test Game", gameOwner, gameDefinition); - assertEquals(5, l.getId()); - } - - @Test - public void testName() { - Lobby l = new Lobby(5, "Test Game", gameOwner, gameDefinition); - assertEquals("Test Game", l.getName()); - } - - @Test - public void isOwner_falseWhenNull() { - assertFalse(lobby.isOwner(null)); - } - - @Test - public void isOwner_falseWhenEmptyString() { - assertFalse(lobby.isOwner("")); - } - - @Test - public void isOwner_falseWhenGarbageString() { - assertFalse(lobby.isOwner("this is garbage")); - } - - @Test - public void isOwner_trueWhenOwnerUsername() { - assertTrue(lobby.isOwner(gameOwner.getUsername())); - } - - @Test - public void isOwner_falseWhenOtherPlayerName() { - Player player = new Player("testuser", "Test User"); - lobby.addPlayer(player); - assertFalse(lobby.isOwner(player.getUsername())); - } - - @Test - public void addPlayer_success() { - Player player = new Player("testuser", "Test User"); - lobby.addPlayer(player); - assertTrue(lobby.containsUser("testuser")); - } - - @Test(expected = PlayerNameAlreadyUsedException.class) - public void addPlayer_failsOnSameName() { - Player player = new Player("testuser", "Test User"); - Player player2 = new Player("testuser2", "Test User"); - lobby.addPlayer(player); - lobby.addPlayer(player2); - } - - @Test(expected = PlayerOverflowException.class) - public void addPlayer_playerOverflowWhenTooMany() { - // the owner + the max number gives an overflow - addPlayers(gameDefinition.getMaxPlayers()); - } - - @Test(expected = GameAlreadyStartedException.class) - public void addPlayer_failWhenGameStarted() { - // total with owner is the minimum - addPlayers(gameDefinition.getMinPlayers() - 1); - lobby.startGame(); - lobby.addPlayer(new Player("soonerNextTime", "The Late Guy")); - } - - private void addPlayers(int nbPlayers) { - for (int i = 0; i < nbPlayers; i++) { - Player player = new Player("testuser" + i, "Test User " + i); - lobby.addPlayer(player); - } - } - - @Test - public void reorderPlayers_failsOnSameName() { - Player player1 = new Player("testuser1", "Test User 1"); - Player player2 = new Player("testuser2", "Test User 2"); - Player player3 = new Player("testuser3", "Test User 3"); - lobby.addPlayer(player1); - lobby.addPlayer(player2); - lobby.addPlayer(player3); - lobby.reorderPlayers(Arrays.asList("testuser3", "testuser1", "testuser2")); - assertEquals("testuser3", lobby.getPlayers().get(0).getUsername()); - assertEquals("testuser1", lobby.getPlayers().get(1).getUsername()); - assertEquals("testuser2", lobby.getPlayers().get(2).getUsername()); - } - - @Test(expected = UnknownPlayerException.class) - public void reorderPlayers_failsOnUnknownPlayer() { - Player player1 = new Player("testuser1", "Test User 1"); - Player player2 = new Player("testuser2", "Test User 2"); - Player player3 = new Player("testuser3", "Test User 3"); - lobby.addPlayer(player1); - lobby.addPlayer(player2); - lobby.addPlayer(player3); - lobby.reorderPlayers(Arrays.asList("testuser4", "testuser1", "testuser2")); - } - - @Theory - public void startGame_failsBelowMinPlayers(int nbPlayers) { - assumeTrue(nbPlayers < gameDefinition.getMinPlayers()); - thrown.expect(PlayerUnderflowException.class); - // there is already the owner - addPlayers(nbPlayers - 1); - lobby.startGame(); - } - - @Theory - public void startGame_succeedsAboveMinPlayers(int nbPlayers) { - assumeTrue(nbPlayers >= gameDefinition.getMinPlayers()); - assumeTrue(nbPlayers < gameDefinition.getMaxPlayers()); - // there is already the owner - addPlayers(nbPlayers - 1); - lobby.startGame(); - } - - @Test - public void startGame_switchesState() { - assertTrue(lobby.getState() == State.LOBBY); - // there is already the owner - addPlayers(gameDefinition.getMinPlayers() - 1); - lobby.startGame(); - assertTrue(lobby.getState() == State.PLAYING); - } -} \ No newline at end of file diff --git a/backend/src/test/java/org/luxons/sevenwonders/game/boards/BoardTest.java b/backend/src/test/java/org/luxons/sevenwonders/game/boards/BoardTest.java index 858a6e2c..1dbe7dc7 100644 --- a/backend/src/test/java/org/luxons/sevenwonders/game/boards/BoardTest.java +++ b/backend/src/test/java/org/luxons/sevenwonders/game/boards/BoardTest.java @@ -53,13 +53,13 @@ public class BoardTest { CustomizableSettings customSettings = TestUtils.createCustomizableSettings(); customSettings.setInitialGold(goldAmountInSettings); Settings settings = new Settings(5, customSettings); - Board board = new Board(TestUtils.createWonder(), null, settings); + Board board = new Board(TestUtils.createWonder(), 0, settings); assertEquals(goldAmountInSettings, board.getGold()); } @Theory public void initialProduction_containsInitialResource(ResourceType type) { - Board board = new Board(TestUtils.createWonder(type), null, new Settings(5)); + Board board = new Board(TestUtils.createWonder(type), 0, new Settings(5)); Resources resources = TestUtils.createResources(type); assertTrue(board.getProduction().contains(resources)); assertTrue(board.getPublicProduction().contains(resources)); @@ -70,7 +70,7 @@ public class BoardTest { @FromDataPoints("gold") int goldRemoved) { assumeTrue(goldRemoved >= 0); assumeTrue(initialGold >= goldRemoved); - Board board = new Board(TestUtils.createWonder(), null, new Settings(5)); + Board board = new Board(TestUtils.createWonder(), 0, new Settings(5)); board.setGold(initialGold); board.removeGold(goldRemoved); assertEquals(initialGold - goldRemoved, board.getGold()); @@ -82,7 +82,7 @@ public class BoardTest { assumeTrue(goldRemoved >= 0); assumeTrue(initialGold < goldRemoved); thrown.expect(InsufficientFundsException.class); - Board board = new Board(TestUtils.createWonder(), null, new Settings(5)); + Board board = new Board(TestUtils.createWonder(), 0, new Settings(5)); board.setGold(initialGold); board.removeGold(goldRemoved); } @@ -90,7 +90,7 @@ public class BoardTest { @Theory public void getNbCardsOfColor_properCount_singleColor(ResourceType type, @FromDataPoints("nbCards") int nbCards, @FromDataPoints("nbCards") int nbOtherCards, Color color) { - Board board = new Board(TestUtils.createWonder(type), null, new Settings(5)); + Board board = new Board(TestUtils.createWonder(type), 0, new Settings(5)); TestUtils.addCards(board, nbCards, nbOtherCards, color); assertEquals(nbCards, board.getNbCardsOfColor(Collections.singletonList(color))); } @@ -99,7 +99,7 @@ public class BoardTest { public void getNbCardsOfColor_properCount_multiColors(ResourceType type, @FromDataPoints("nbCards") int nbCards1, @FromDataPoints("nbCards") int nbCards2, @FromDataPoints("nbCards") int nbOtherCards, Color color1, Color color2) { - Board board = new Board(TestUtils.createWonder(type), null, new Settings(5)); + Board board = new Board(TestUtils.createWonder(type), 0, new Settings(5)); TestUtils.addCards(board, nbCards1, color1); TestUtils.addCards(board, nbCards2, color2); TestUtils.addCards(board, nbOtherCards, TestUtils.getDifferentColorFrom(color1, color2)); diff --git a/backend/src/test/java/org/luxons/sevenwonders/game/cards/CardTest.java b/backend/src/test/java/org/luxons/sevenwonders/game/cards/CardTest.java index 4a481442..0d40bc9a 100644 --- a/backend/src/test/java/org/luxons/sevenwonders/game/cards/CardTest.java +++ b/backend/src/test/java/org/luxons/sevenwonders/game/cards/CardTest.java @@ -25,12 +25,12 @@ public class CardTest { @Before public void initBoard() { - Settings settings = new Settings(5); + Settings settings = new Settings(3); List boards = new ArrayList<>(3); - boards.add(new Board(new Wonder("TestWonder", ResourceType.WOOD), null, settings)); - boards.add(new Board(new Wonder("TestWonder", ResourceType.STONE), null, settings)); - boards.add(new Board(new Wonder("TestWonder", ResourceType.PAPYRUS), null, settings)); + boards.add(new Board(new Wonder("TestWonder", ResourceType.WOOD), 0, settings)); + boards.add(new Board(new Wonder("TestWonder", ResourceType.STONE), 1, settings)); + boards.add(new Board(new Wonder("TestWonder", ResourceType.PAPYRUS), 2, settings)); table = new Table(boards); Requirements treeFarmRequirements = new Requirements(); diff --git a/backend/src/test/java/org/luxons/sevenwonders/game/data/GameDefinitionTest.java b/backend/src/test/java/org/luxons/sevenwonders/game/data/GameDefinitionTest.java index 5acc09df..a5b37edd 100644 --- a/backend/src/test/java/org/luxons/sevenwonders/game/data/GameDefinitionTest.java +++ b/backend/src/test/java/org/luxons/sevenwonders/game/data/GameDefinitionTest.java @@ -1,15 +1,10 @@ package org.luxons.sevenwonders.game.data; -import java.util.List; - import org.junit.Test; import org.luxons.sevenwonders.game.Game; -import org.luxons.sevenwonders.game.Player; -import org.luxons.sevenwonders.game.Settings; import org.luxons.sevenwonders.game.api.CustomizableSettings; -import org.luxons.sevenwonders.game.test.TestUtils; -import static org.junit.Assert.*; +import static org.junit.Assert.assertNotNull; public class GameDefinitionTest { @@ -18,8 +13,7 @@ public class GameDefinitionTest { GameDefinition gameDefinition = new GameDefinitionLoader().getGameDefinition(); assertNotNull(gameDefinition); - List players = TestUtils.createPlayers(7); - Game game = gameDefinition.initGame(0, new CustomizableSettings(), players); + Game game = gameDefinition.initGame(0, new CustomizableSettings(), 7); assertNotNull(game); } } \ No newline at end of file diff --git a/backend/src/test/java/org/luxons/sevenwonders/game/test/TestUtils.java b/backend/src/test/java/org/luxons/sevenwonders/game/test/TestUtils.java index b8112779..a206cfb8 100644 --- a/backend/src/test/java/org/luxons/sevenwonders/game/test/TestUtils.java +++ b/backend/src/test/java/org/luxons/sevenwonders/game/test/TestUtils.java @@ -3,12 +3,8 @@ package org.luxons.sevenwonders.game.test; import java.util.ArrayList; import java.util.Arrays; import java.util.Collections; -import java.util.HashMap; import java.util.List; -import java.util.Map; -import org.luxons.sevenwonders.game.Game; -import org.luxons.sevenwonders.game.Player; import org.luxons.sevenwonders.game.Settings; import org.luxons.sevenwonders.game.api.CustomizableSettings; import org.luxons.sevenwonders.game.api.Table; @@ -17,7 +13,6 @@ import org.luxons.sevenwonders.game.boards.Science; import org.luxons.sevenwonders.game.boards.ScienceType; import org.luxons.sevenwonders.game.cards.Card; import org.luxons.sevenwonders.game.cards.Color; -import org.luxons.sevenwonders.game.cards.Decks; import org.luxons.sevenwonders.game.cards.Requirements; import org.luxons.sevenwonders.game.effects.Effect; import org.luxons.sevenwonders.game.effects.ScienceProgress; @@ -43,16 +38,6 @@ public class TestUtils { return new Settings(nbPlayers, createCustomizableSettings()); } - public static Game createGame(int id, int nbPlayers) { - Settings settings = createSettings(nbPlayers); - List players = TestUtils.createPlayers(nbPlayers); - List boards = TestUtils.createBoards(nbPlayers); - List cards = TestUtils.createSampleCards(0, nbPlayers * 7); - Map> cardsPerAge = new HashMap<>(); - cardsPerAge.put(1, cards); - return new Game(id, settings, players, boards, new Decks(cardsPerAge)); - } - public static Table createTable(int nbPlayers) { return new Table(createBoards(nbPlayers)); } @@ -66,26 +51,9 @@ public class TestUtils { return boards; } - public static List createPlayers(int count) { - List players = new ArrayList<>(count); - for (int i = 0; i < count; i++) { - String username = "testUser" + i; - String displayName = "Test User " + i; - Player player = new Player(username, displayName); - player.setIndex(i); - players.add(player); - } - return players; - } - private static Board createBoard(Settings settings, ResourceType initialResource) { Wonder wonder = createWonder(initialResource); - - String username = "testUser" + initialResource.getSymbol(); - String displayName = "Test User " + initialResource.getSymbol(); - Player player = new Player(username, displayName); - - return new Board(wonder, player, settings); + return new Board(wonder, 0, settings); } public static Board createBoard(ResourceType initialResource) { diff --git a/backend/src/test/java/org/luxons/sevenwonders/lobby/LobbyTest.java b/backend/src/test/java/org/luxons/sevenwonders/lobby/LobbyTest.java new file mode 100644 index 00000000..adc37d3d --- /dev/null +++ b/backend/src/test/java/org/luxons/sevenwonders/lobby/LobbyTest.java @@ -0,0 +1,181 @@ +package org.luxons.sevenwonders.lobby; + +import java.util.Arrays; + +import org.junit.Before; +import org.junit.BeforeClass; +import org.junit.Rule; +import org.junit.Test; +import org.junit.experimental.theories.DataPoints; +import org.junit.experimental.theories.Theories; +import org.junit.experimental.theories.Theory; +import org.junit.rules.ExpectedException; +import org.junit.runner.RunWith; +import org.luxons.sevenwonders.game.data.GameDefinition; +import org.luxons.sevenwonders.game.data.GameDefinitionLoader; +import org.luxons.sevenwonders.lobby.Lobby.GameAlreadyStartedException; +import org.luxons.sevenwonders.lobby.Lobby.PlayerNameAlreadyUsedException; +import org.luxons.sevenwonders.lobby.Lobby.PlayerOverflowException; +import org.luxons.sevenwonders.lobby.Lobby.PlayerUnderflowException; +import org.luxons.sevenwonders.lobby.Lobby.UnknownPlayerException; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; +import static org.junit.Assume.assumeTrue; + +@RunWith(Theories.class) +public class LobbyTest { + + @DataPoints + public static int[] nbPlayers() { + return new int[] {1, 2, 3, 4, 5, 6, 7, 8, 9, 10}; + } + + @Rule + public ExpectedException thrown = ExpectedException.none(); + + private static GameDefinition gameDefinition; + + private Player gameOwner; + + private Lobby lobby; + + @BeforeClass + public static void loadDefinition() { + gameDefinition = new GameDefinitionLoader().getGameDefinition(); + } + + @Before + public void setUp() { + gameOwner = new Player("gameowner", "Game owner"); + lobby = new Lobby(0, "Test Game", gameOwner, gameDefinition); + } + + @Test + public void testId() { + Lobby l = new Lobby(5, "Test Game", gameOwner, gameDefinition); + assertEquals(5, l.getId()); + } + + @Test + public void testName() { + Lobby l = new Lobby(5, "Test Game", gameOwner, gameDefinition); + assertEquals("Test Game", l.getName()); + } + + @Test + public void isOwner_falseWhenNull() { + assertFalse(lobby.isOwner(null)); + } + + @Test + public void isOwner_falseWhenEmptyString() { + assertFalse(lobby.isOwner("")); + } + + @Test + public void isOwner_falseWhenGarbageString() { + assertFalse(lobby.isOwner("this is garbage")); + } + + @Test + public void isOwner_trueWhenOwnerUsername() { + assertTrue(lobby.isOwner(gameOwner.getUsername())); + } + + @Test + public void isOwner_falseWhenOtherPlayerName() { + Player player = new Player("testuser", "Test User"); + lobby.addPlayer(player); + assertFalse(lobby.isOwner(player.getUsername())); + } + + @Test + public void addPlayer_success() { + Player player = new Player("testuser", "Test User"); + lobby.addPlayer(player); + assertTrue(lobby.containsUser("testuser")); + } + + @Test(expected = PlayerNameAlreadyUsedException.class) + public void addPlayer_failsOnSameName() { + Player player = new Player("testuser", "Test User"); + Player player2 = new Player("testuser2", "Test User"); + lobby.addPlayer(player); + lobby.addPlayer(player2); + } + + @Test(expected = PlayerOverflowException.class) + public void addPlayer_playerOverflowWhenTooMany() { + // the owner + the max number gives an overflow + addPlayers(gameDefinition.getMaxPlayers()); + } + + @Test(expected = GameAlreadyStartedException.class) + public void addPlayer_failWhenGameStarted() { + // total with owner is the minimum + addPlayers(gameDefinition.getMinPlayers() - 1); + lobby.startGame(); + lobby.addPlayer(new Player("soonerNextTime", "The Late Guy")); + } + + private void addPlayers(int nbPlayers) { + for (int i = 0; i < nbPlayers; i++) { + Player player = new Player("testuser" + i, "Test User " + i); + lobby.addPlayer(player); + } + } + + @Test + public void reorderPlayers_failsOnSameName() { + Player player1 = new Player("testuser1", "Test User 1"); + Player player2 = new Player("testuser2", "Test User 2"); + Player player3 = new Player("testuser3", "Test User 3"); + lobby.addPlayer(player1); + lobby.addPlayer(player2); + lobby.addPlayer(player3); + lobby.reorderPlayers(Arrays.asList("testuser3", "testuser1", "testuser2")); + assertEquals("testuser3", lobby.getPlayers().get(0).getUsername()); + assertEquals("testuser1", lobby.getPlayers().get(1).getUsername()); + assertEquals("testuser2", lobby.getPlayers().get(2).getUsername()); + } + + @Test(expected = UnknownPlayerException.class) + public void reorderPlayers_failsOnUnknownPlayer() { + Player player1 = new Player("testuser1", "Test User 1"); + Player player2 = new Player("testuser2", "Test User 2"); + Player player3 = new Player("testuser3", "Test User 3"); + lobby.addPlayer(player1); + lobby.addPlayer(player2); + lobby.addPlayer(player3); + lobby.reorderPlayers(Arrays.asList("testuser4", "testuser1", "testuser2")); + } + + @Theory + public void startGame_failsBelowMinPlayers(int nbPlayers) { + assumeTrue(nbPlayers < gameDefinition.getMinPlayers()); + thrown.expect(PlayerUnderflowException.class); + // there is already the owner + addPlayers(nbPlayers - 1); + lobby.startGame(); + } + + @Theory + public void startGame_succeedsAboveMinPlayers(int nbPlayers) { + assumeTrue(nbPlayers >= gameDefinition.getMinPlayers()); + assumeTrue(nbPlayers < gameDefinition.getMaxPlayers()); + // there is already the owner + addPlayers(nbPlayers - 1); + lobby.startGame(); + } + + @Test + public void startGame_switchesState() { + assertTrue(lobby.getState() == State.LOBBY); + // there is already the owner + addPlayers(gameDefinition.getMinPlayers() - 1); + lobby.startGame(); + assertTrue(lobby.getState() == State.PLAYING); + } +} \ No newline at end of file diff --git a/backend/src/test/java/org/luxons/sevenwonders/repositories/GameRepositoryTest.java b/backend/src/test/java/org/luxons/sevenwonders/repositories/GameRepositoryTest.java deleted file mode 100644 index 5d7d558b..00000000 --- a/backend/src/test/java/org/luxons/sevenwonders/repositories/GameRepositoryTest.java +++ /dev/null @@ -1,61 +0,0 @@ -package org.luxons.sevenwonders.repositories; - -import org.junit.Before; -import org.junit.Test; -import org.luxons.sevenwonders.game.Game; -import org.luxons.sevenwonders.game.test.TestUtils; -import org.luxons.sevenwonders.repositories.GameRepository.GameAlreadyExistsException; -import org.luxons.sevenwonders.repositories.GameRepository.GameNotFoundException; - -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertSame; -import static org.junit.Assert.fail; - -public class GameRepositoryTest { - - private GameRepository repository; - - @Before - public void setUp() { - repository = new GameRepository(); - } - - @Test(expected = GameAlreadyExistsException.class) - public void add_failsOnExistingId() { - Game game1 = TestUtils.createGame(0, 5); - repository.add(game1); - Game game2 = TestUtils.createGame(0, 7); - repository.add(game2); - } - - @Test(expected = GameNotFoundException.class) - public void find_failsOnUnknownId() { - repository.find(123); - } - - @Test - public void find_returnsTheSameObject() { - Game game = TestUtils.createGame(0, 5); - repository.add(game); - assertSame(game, repository.find(0)); - } - - @Test(expected = GameNotFoundException.class) - public void remove_failsOnUnknownId() { - repository.remove(123); - } - - @Test - public void remove_succeeds() { - Game game = TestUtils.createGame(0, 5); - repository.add(game); - assertNotNull(repository.find(0)); - repository.remove(0); - try { - repository.find(0); - fail(); // the call to find() should have failed - } catch (GameNotFoundException e) { - // the game has been properly removed - } - } -} \ No newline at end of file diff --git a/backend/src/test/java/org/luxons/sevenwonders/repositories/LobbyRepositoryTest.java b/backend/src/test/java/org/luxons/sevenwonders/repositories/LobbyRepositoryTest.java index f5a8d800..35618d49 100644 --- a/backend/src/test/java/org/luxons/sevenwonders/repositories/LobbyRepositoryTest.java +++ b/backend/src/test/java/org/luxons/sevenwonders/repositories/LobbyRepositoryTest.java @@ -2,8 +2,8 @@ package org.luxons.sevenwonders.repositories; import org.junit.Before; import org.junit.Test; -import org.luxons.sevenwonders.game.Lobby; -import org.luxons.sevenwonders.game.Player; +import org.luxons.sevenwonders.lobby.Lobby; +import org.luxons.sevenwonders.lobby.Player; import org.luxons.sevenwonders.game.data.GameDefinitionLoader; import org.luxons.sevenwonders.repositories.LobbyRepository.LobbyNotFoundException; diff --git a/backend/src/test/java/org/luxons/sevenwonders/repositories/PlayerRepositoryTest.java b/backend/src/test/java/org/luxons/sevenwonders/repositories/PlayerRepositoryTest.java index d9e07b3f..8a6efe8c 100644 --- a/backend/src/test/java/org/luxons/sevenwonders/repositories/PlayerRepositoryTest.java +++ b/backend/src/test/java/org/luxons/sevenwonders/repositories/PlayerRepositoryTest.java @@ -2,7 +2,7 @@ package org.luxons.sevenwonders.repositories; import org.junit.Before; import org.junit.Test; -import org.luxons.sevenwonders.game.Player; +import org.luxons.sevenwonders.lobby.Player; import org.luxons.sevenwonders.repositories.PlayerRepository.PlayerNotFoundException; import static org.junit.Assert.assertEquals; diff --git a/backend/src/test/java/org/luxons/sevenwonders/validation/DestinationAccessValidatorTest.java b/backend/src/test/java/org/luxons/sevenwonders/validation/DestinationAccessValidatorTest.java index 1a799ff3..8623ead8 100644 --- a/backend/src/test/java/org/luxons/sevenwonders/validation/DestinationAccessValidatorTest.java +++ b/backend/src/test/java/org/luxons/sevenwonders/validation/DestinationAccessValidatorTest.java @@ -2,30 +2,25 @@ package org.luxons.sevenwonders.validation; import org.junit.Before; import org.junit.Test; -import org.luxons.sevenwonders.game.Game; -import org.luxons.sevenwonders.game.Lobby; -import org.luxons.sevenwonders.game.Player; +import org.luxons.sevenwonders.lobby.Lobby; +import org.luxons.sevenwonders.lobby.Player; import org.luxons.sevenwonders.game.data.GameDefinitionLoader; -import org.luxons.sevenwonders.repositories.GameRepository; -import org.luxons.sevenwonders.repositories.GameRepository.GameNotFoundException; import org.luxons.sevenwonders.repositories.LobbyRepository; import org.luxons.sevenwonders.repositories.LobbyRepository.LobbyNotFoundException; -import static org.junit.Assert.*; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; public class DestinationAccessValidatorTest { private LobbyRepository lobbyRepository; - private GameRepository gameRepository; - private DestinationAccessValidator destinationAccessValidator; @Before public void setup() { - gameRepository = new GameRepository(); lobbyRepository = new LobbyRepository(new GameDefinitionLoader()); - destinationAccessValidator = new DestinationAccessValidator(lobbyRepository, gameRepository); + destinationAccessValidator = new DestinationAccessValidator(lobbyRepository); } private Lobby createLobby(String gameName, String ownerUsername, String... otherPlayers) { @@ -40,8 +35,7 @@ public class DestinationAccessValidatorTest { private void createGame(String gameName, String ownerUsername, String... otherPlayers) { Lobby lobby = createLobby(gameName, ownerUsername, otherPlayers); - Game game = lobby.startGame(); - gameRepository.add(game); + lobby.startGame(); } @Test @@ -81,7 +75,7 @@ public class DestinationAccessValidatorTest { destinationAccessValidator.hasAccess("", "/lobby/0"); } - @Test(expected = GameNotFoundException.class) + @Test(expected = LobbyNotFoundException.class) public void validate_failWhenNoGameExist() { destinationAccessValidator.hasAccess("", "/game/0"); } @@ -93,7 +87,7 @@ public class DestinationAccessValidatorTest { destinationAccessValidator.hasAccess("doesNotMatter", "/lobby/3"); } - @Test(expected = GameNotFoundException.class) + @Test(expected = LobbyNotFoundException.class) public void validate_failWhenReferencedGameDoesNotExist() { createGame("Test Game 1", "user1", "user2", "user3"); createGame("Test Game 2", "user4", "user5", "user6"); -- cgit