From b7eefa589b49115fdada88669601b93370bd42d6 Mon Sep 17 00:00:00 2001 From: jbion Date: Wed, 28 Dec 2016 14:18:18 +0100 Subject: Add player reordering support in Lobby --- .../org/luxons/sevenwonders/game/LobbyTest.java | 28 ++++++++++++++++++++++ 1 file changed, 28 insertions(+) (limited to 'src/test/java/org/luxons') diff --git a/src/test/java/org/luxons/sevenwonders/game/LobbyTest.java b/src/test/java/org/luxons/sevenwonders/game/LobbyTest.java index 8e59dea1..65069b88 100644 --- a/src/test/java/org/luxons/sevenwonders/game/LobbyTest.java +++ b/src/test/java/org/luxons/sevenwonders/game/LobbyTest.java @@ -1,5 +1,7 @@ package org.luxons.sevenwonders.game; +import java.util.Arrays; + import org.junit.Before; import org.junit.BeforeClass; import org.junit.Rule; @@ -13,6 +15,7 @@ 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; @@ -110,6 +113,31 @@ public class LobbyTest { } } + @Test + public void reorderPlayers_failsOnSameName() { + Player player1 = new Player("Test User 1", "testuser1"); + Player player2 = new Player("Test User 2", "testuser2"); + Player player3 = new Player("Test User 3", "testuser3"); + 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("Test User 1", "testuser1"); + Player player2 = new Player("Test User 2", "testuser2"); + Player player3 = new Player("Test User 3", "testuser3"); + 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()); -- cgit