summaryrefslogtreecommitdiff
path: root/backend
diff options
context:
space:
mode:
authorjbion <joffrey.bion@amadeus.com>2017-05-25 03:28:44 +0200
committerjbion <joffrey.bion@amadeus.com>2017-05-25 03:29:03 +0200
commit09fe76b255fa55d3b923e798388a03fc35b44ce1 (patch)
tree32c71559ee4a38834df00ce2eadb0fd4d6ce4feb /backend
parentAdd a java API for SevenWonders using the simple JSON/STOMP client (diff)
downloadseven-wonders-09fe76b255fa55d3b923e798388a03fc35b44ce1.tar.gz
seven-wonders-09fe76b255fa55d3b923e798388a03fc35b44ce1.tar.bz2
seven-wonders-09fe76b255fa55d3b923e798388a03fc35b44ce1.zip
Create TestPrincipal for Controller unit tests
Diffstat (limited to 'backend')
-rw-r--r--backend/src/test/java/org/luxons/sevenwonders/controllers/GameBrowserControllerTest.java24
-rw-r--r--backend/src/test/java/org/luxons/sevenwonders/controllers/HomeControllerTest.java4
-rw-r--r--backend/src/test/java/org/luxons/sevenwonders/controllers/LobbyControllerTest.java30
-rw-r--r--backend/src/test/java/org/luxons/sevenwonders/controllers/TestPrincipal.java17
4 files changed, 55 insertions, 20 deletions
diff --git a/backend/src/test/java/org/luxons/sevenwonders/controllers/GameBrowserControllerTest.java b/backend/src/test/java/org/luxons/sevenwonders/controllers/GameBrowserControllerTest.java
index 8f596434..9ebcfd2b 100644
--- a/backend/src/test/java/org/luxons/sevenwonders/controllers/GameBrowserControllerTest.java
+++ b/backend/src/test/java/org/luxons/sevenwonders/controllers/GameBrowserControllerTest.java
@@ -39,7 +39,8 @@ public class GameBrowserControllerTest {
@Test
public void listGames_initiallyEmpty() {
- Principal principal = TestUtils.createPrincipal("testuser");
+ // the Principal interface just contains a getName() method
+ Principal principal = new TestPrincipal("testuser");
Collection<Lobby> games = gameBrowserController.listGames(principal);
assertTrue(games.isEmpty());
}
@@ -47,7 +48,8 @@ public class GameBrowserControllerTest {
@Test
public void createGame_success() {
Player player = playerRepository.createOrUpdate("testuser", "Test User");
- Principal principal = TestUtils.createPrincipal("testuser");
+ // the Principal interface just contains a getName() method
+ Principal principal = new TestPrincipal("testuser");
CreateGameAction action = new CreateGameAction();
action.setGameName("Test Game");
@@ -65,7 +67,8 @@ public class GameBrowserControllerTest {
@Test(expected = PlayerNotFoundException.class)
public void createGame_failsForUnknownPlayer() {
- Principal principal = TestUtils.createPrincipal("unknown");
+ // the Principal interface just contains a getName() method
+ Principal principal = new TestPrincipal("unknown");
CreateGameAction action = new CreateGameAction();
action.setGameName("Test Game");
@@ -76,7 +79,8 @@ public class GameBrowserControllerTest {
@Test(expected = UserAlreadyInGameException.class)
public void createGame_failsWhenAlreadyInGame() {
playerRepository.createOrUpdate("testuser", "Test User");
- Principal principal = TestUtils.createPrincipal("testuser");
+ // the Principal interface just contains a getName() method
+ Principal principal = new TestPrincipal("testuser");
CreateGameAction createGameAction1 = new CreateGameAction();
createGameAction1.setGameName("Test Game 1");
@@ -94,14 +98,16 @@ public class GameBrowserControllerTest {
@Test
public void joinGame_success() {
Player owner = playerRepository.createOrUpdate("testowner", "Test User Owner");
- Principal ownerPrincipal = TestUtils.createPrincipal("testowner");
+ // the Principal interface just contains a getName() method
+ Principal ownerPrincipal = new TestPrincipal("testowner");
CreateGameAction createGameAction = new CreateGameAction();
createGameAction.setGameName("Test Game");
Lobby createdLobby = gameBrowserController.createGame(createGameAction, ownerPrincipal);
Player joiner = playerRepository.createOrUpdate("testjoiner", "Test User Joiner");
- Principal joinerPrincipal = TestUtils.createPrincipal("testjoiner");
+ // the Principal interface just contains a getName() method
+ Principal joinerPrincipal = new TestPrincipal("testjoiner");
JoinGameAction joinGameAction = new JoinGameAction();
joinGameAction.setGameId(createdLobby.getId());
@@ -115,14 +121,16 @@ public class GameBrowserControllerTest {
@Test(expected = UserAlreadyInGameException.class)
public void joinGame_failsWhenAlreadyInGame() {
playerRepository.createOrUpdate("testowner", "Test User Owner");
- Principal ownerPrincipal = TestUtils.createPrincipal("testowner");
+ // the Principal interface just contains a getName() method
+ Principal ownerPrincipal = new TestPrincipal("testowner");
CreateGameAction createGameAction = new CreateGameAction();
createGameAction.setGameName("Test Game");
Lobby createdLobby = gameBrowserController.createGame(createGameAction, ownerPrincipal);
playerRepository.createOrUpdate("testjoiner", "Test User Joiner");
- Principal joinerPrincipal = TestUtils.createPrincipal("testjoiner");
+ // the Principal interface just contains a getName() method
+ Principal joinerPrincipal = new TestPrincipal("testjoiner");
JoinGameAction joinGameAction = new JoinGameAction();
joinGameAction.setGameId(createdLobby.getId());
diff --git a/backend/src/test/java/org/luxons/sevenwonders/controllers/HomeControllerTest.java b/backend/src/test/java/org/luxons/sevenwonders/controllers/HomeControllerTest.java
index 1563e1a2..0e9cfadf 100644
--- a/backend/src/test/java/org/luxons/sevenwonders/controllers/HomeControllerTest.java
+++ b/backend/src/test/java/org/luxons/sevenwonders/controllers/HomeControllerTest.java
@@ -4,7 +4,6 @@ import java.security.Principal;
import org.junit.Test;
import org.luxons.sevenwonders.actions.ChooseNameAction;
-import org.luxons.sevenwonders.test.TestUtils;
import org.luxons.sevenwonders.lobby.Player;
import org.luxons.sevenwonders.repositories.PlayerRepository;
@@ -21,7 +20,8 @@ public class HomeControllerTest {
ChooseNameAction action = new ChooseNameAction();
action.setPlayerName("Test User");
- Principal principal = TestUtils.createPrincipal("testuser");
+ // the Principal interface just contains a getName() method
+ Principal principal = new TestPrincipal("testuser");
Player player = homeController.chooseName(action, principal);
diff --git a/backend/src/test/java/org/luxons/sevenwonders/controllers/LobbyControllerTest.java b/backend/src/test/java/org/luxons/sevenwonders/controllers/LobbyControllerTest.java
index 9377f885..bee3110b 100644
--- a/backend/src/test/java/org/luxons/sevenwonders/controllers/LobbyControllerTest.java
+++ b/backend/src/test/java/org/luxons/sevenwonders/controllers/LobbyControllerTest.java
@@ -48,14 +48,16 @@ public class LobbyControllerTest {
@Test(expected = PlayerNotFoundException.class)
public void leave_failsWhenPlayerDoesNotExist() {
- Principal principal = TestUtils.createPrincipal("testuser");
+ // the Principal interface just contains a getName() method
+ Principal principal = new TestPrincipal("testuser");
lobbyController.leave(principal);
}
@Test(expected = PlayerNotInLobbyException.class)
public void leave_failsWhenNotInLobby() {
playerRepository.createOrUpdate("testuser", "Test User");
- Principal principal = TestUtils.createPrincipal("testuser");
+ // the Principal interface just contains a getName() method
+ Principal principal = new TestPrincipal("testuser");
lobbyController.leave(principal);
}
@@ -67,7 +69,8 @@ public class LobbyControllerTest {
assertTrue(lobby.getPlayers().contains(player));
assertSame(lobby, player.getLobby());
- Principal principal = TestUtils.createPrincipal("testuser");
+ // the Principal interface just contains a getName() method
+ Principal principal = new TestPrincipal("testuser");
lobbyController.leave(principal);
assertFalse(lobby.getPlayers().contains(player));
@@ -83,7 +86,8 @@ public class LobbyControllerTest {
assertTrue(lobby.getPlayers().contains(player2));
assertSame(lobby, player2.getLobby());
- Principal principal = TestUtils.createPrincipal("testuser2");
+ // the Principal interface just contains a getName() method
+ Principal principal = new TestPrincipal("testuser2");
lobbyController.leave(principal);
assertFalse(lobby.getPlayers().contains(player2));
@@ -107,7 +111,8 @@ public class LobbyControllerTest {
List<String> playerNames = reorderedPlayers.stream().map(Player::getUsername).collect(Collectors.toList());
reorderPlayersAction.setOrderedPlayers(playerNames);
- Principal principal = TestUtils.createPrincipal("testuser");
+ // the Principal interface just contains a getName() method
+ Principal principal = new TestPrincipal("testuser");
lobbyController.reorderPlayers(reorderPlayersAction, principal);
assertEquals(reorderedPlayers, lobby.getPlayers());
@@ -126,7 +131,8 @@ public class LobbyControllerTest {
List<String> playerNames = reorderedPlayers.stream().map(Player::getUsername).collect(Collectors.toList());
reorderPlayersAction.setOrderedPlayers(playerNames);
- Principal principal = TestUtils.createPrincipal("testuser2");
+ // the Principal interface just contains a getName() method
+ Principal principal = new TestPrincipal("testuser2");
lobbyController.reorderPlayers(reorderPlayersAction, principal);
}
@@ -153,7 +159,8 @@ public class LobbyControllerTest {
newSettings.setWonPointsPerVictoryPerAge(new HashMap<>());
updateSettingsAction.setSettings(newSettings);
- Principal principal = TestUtils.createPrincipal("testuser");
+ // the Principal interface just contains a getName() method
+ Principal principal = new TestPrincipal("testuser");
lobbyController.updateSettings(updateSettingsAction, principal);
assertEquals(newSettings, lobby.getSettings());
@@ -170,7 +177,8 @@ public class LobbyControllerTest {
UpdateSettingsAction updateSettingsAction = new UpdateSettingsAction();
updateSettingsAction.setSettings(new CustomizableSettings());
- Principal principal = TestUtils.createPrincipal("testuser2");
+ // the Principal interface just contains a getName() method
+ Principal principal = new TestPrincipal("testuser2");
lobbyController.updateSettings(updateSettingsAction, principal);
}
@@ -183,7 +191,8 @@ public class LobbyControllerTest {
addPlayer(lobby, "testuser3");
addPlayer(lobby, "testuser4");
- Principal principal = TestUtils.createPrincipal("testuser");
+ // the Principal interface just contains a getName() method
+ Principal principal = new TestPrincipal("testuser");
lobbyController.startGame(principal);
assertSame(State.PLAYING, lobby.getState());
@@ -197,7 +206,8 @@ public class LobbyControllerTest {
addPlayer(lobby, "testuser2");
addPlayer(lobby, "testuser3");
- Principal principal = TestUtils.createPrincipal("testuser2");
+ // the Principal interface just contains a getName() method
+ Principal principal = new TestPrincipal("testuser2");
lobbyController.startGame(principal);
}
diff --git a/backend/src/test/java/org/luxons/sevenwonders/controllers/TestPrincipal.java b/backend/src/test/java/org/luxons/sevenwonders/controllers/TestPrincipal.java
new file mode 100644
index 00000000..db601cd2
--- /dev/null
+++ b/backend/src/test/java/org/luxons/sevenwonders/controllers/TestPrincipal.java
@@ -0,0 +1,17 @@
+package org.luxons.sevenwonders.controllers;
+
+import java.security.Principal;
+
+public class TestPrincipal implements Principal {
+
+ private final String name;
+
+ TestPrincipal(String name) {
+ this.name = name;
+ }
+
+ @Override
+ public String getName() {
+ return name;
+ }
+}
bgstack15