summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorJoffrey BION <joffrey.bion@gmail.com>2017-01-14 15:58:43 +0100
committerJoffrey BION <joffrey.bion@gmail.com>2017-01-14 15:58:43 +0100
commit9911e0cbdc0f2c930ae36b5f4e64cef38427a961 (patch)
tree116f486aa367727d66995c85671356034c3caf10 /src
parentSimplify validation errors' output (diff)
downloadseven-wonders-9911e0cbdc0f2c930ae36b5f4e64cef38427a961.tar.gz
seven-wonders-9911e0cbdc0f2c930ae36b5f4e64cef38427a961.tar.bz2
seven-wonders-9911e0cbdc0f2c930ae36b5f4e64cef38427a961.zip
Rename UserName -> Username and the likes
Diffstat (limited to 'src')
-rw-r--r--src/main/java/org/luxons/sevenwonders/controllers/GameController.java8
-rw-r--r--src/main/java/org/luxons/sevenwonders/controllers/LobbyController.java18
-rw-r--r--src/main/java/org/luxons/sevenwonders/game/Game.java18
-rw-r--r--src/main/java/org/luxons/sevenwonders/game/Lobby.java24
-rw-r--r--src/main/java/org/luxons/sevenwonders/game/Player.java10
-rw-r--r--src/main/java/org/luxons/sevenwonders/repositories/PlayerRepository.java36
-rw-r--r--src/main/java/org/luxons/sevenwonders/validation/DestinationAccessValidator.java24
-rw-r--r--src/test/java/org/luxons/sevenwonders/game/LobbyTest.java12
-rw-r--r--src/test/java/org/luxons/sevenwonders/game/test/TestUtils.java8
-rw-r--r--src/test/java/org/luxons/sevenwonders/validation/DestinationAccessValidatorTest.java8
10 files changed, 83 insertions, 83 deletions
diff --git a/src/main/java/org/luxons/sevenwonders/controllers/GameController.java b/src/main/java/org/luxons/sevenwonders/controllers/GameController.java
index 0bb3eb23..0deac4a3 100644
--- a/src/main/java/org/luxons/sevenwonders/controllers/GameController.java
+++ b/src/main/java/org/luxons/sevenwonders/controllers/GameController.java
@@ -48,16 +48,16 @@ public class GameController {
private void sendPreparedCard(PreparedCard preparedCard, Game game) {
for (Player player : game.getPlayers()) {
- String userName = player.getUserName();
- template.convertAndSendToUser(userName, "/topic/game/" + game.getId() + "/prepared", preparedCard);
+ String username = player.getUsername();
+ template.convertAndSendToUser(username, "/topic/game/" + game.getId() + "/prepared", preparedCard);
}
}
private void sendTurnInfo(Game game) {
List<PlayerTurnInfo> turnInfos = game.getTurnInfo();
for (PlayerTurnInfo turnInfo : turnInfos) {
- String userName = turnInfo.getPlayer().getUserName();
- template.convertAndSendToUser(userName, "/topic/game/" + game.getId() + "/turn", turnInfo);
+ String username = turnInfo.getPlayer().getUsername();
+ template.convertAndSendToUser(username, "/topic/game/" + game.getId() + "/turn", turnInfo);
}
}
}
diff --git a/src/main/java/org/luxons/sevenwonders/controllers/LobbyController.java b/src/main/java/org/luxons/sevenwonders/controllers/LobbyController.java
index 1664d05e..020576bc 100644
--- a/src/main/java/org/luxons/sevenwonders/controllers/LobbyController.java
+++ b/src/main/java/org/luxons/sevenwonders/controllers/LobbyController.java
@@ -52,10 +52,10 @@ public class LobbyController {
@MessageMapping("/chooseName")
@SendToUser("/queue/nameChoice")
public Player chooseName(@Validated ChooseNameAction action, Principal principal) {
- String userName = principal.getName();
- Player player = playerRepository.updateOrCreatePlayer(userName, action.getPlayerName());
+ String username = principal.getName();
+ Player player = playerRepository.updateOrCreatePlayer(username, action.getPlayerName());
- logger.info("Player '{}' chose the name '{}'", userName, player.getDisplayName());
+ logger.info("Player '{}' chose the name '{}'", username, player.getDisplayName());
return player;
}
@@ -75,7 +75,7 @@ public class LobbyController {
gameOwner.setLobby(lobby);
logger.info("Game '{}' ({}) created by {} ({})", lobby.getName(), lobby.getId(), gameOwner.getDisplayName(),
- gameOwner.getUserName());
+ gameOwner.getUsername());
return Collections.singletonList(lobby);
}
@@ -89,7 +89,7 @@ public class LobbyController {
lobby.addPlayer(newPlayer);
newPlayer.setLobby(lobby);
- logger.info("Player '{}' ({}) joined game {}", newPlayer.getDisplayName(), newPlayer.getUserName(),
+ logger.info("Player '{}' ({}) joined game {}", newPlayer.getDisplayName(), newPlayer.getUsername(),
lobby.getName());
sendLobbyUpdateToPlayers(lobby);
return lobby;
@@ -151,14 +151,14 @@ public class LobbyController {
}
private static class UserNotInLobbyException extends ApiMisuseException {
- UserNotInLobbyException(String userName) {
- super("User " + userName + " is not in a lobby, create or join a game first");
+ UserNotInLobbyException(String username) {
+ super("User " + username + " is not in a lobby, create or join a game first");
}
}
private static class UserIsNotOwnerException extends ApiMisuseException {
- UserIsNotOwnerException(String userName) {
- super("User " + userName + " does not own the lobby he's in");
+ UserIsNotOwnerException(String username) {
+ super("User " + username + " does not own the lobby he's in");
}
}
diff --git a/src/main/java/org/luxons/sevenwonders/game/Game.java b/src/main/java/org/luxons/sevenwonders/game/Game.java
index bc9c3b17..8aa7d1b9 100644
--- a/src/main/java/org/luxons/sevenwonders/game/Game.java
+++ b/src/main/java/org/luxons/sevenwonders/game/Game.java
@@ -55,8 +55,8 @@ public class Game {
return id;
}
- public boolean containsUser(String userName) {
- return players.stream().anyMatch(p -> p.getUserName().equals(userName));
+ public boolean containsUser(String username) {
+ return players.stream().anyMatch(p -> p.getUsername().equals(username));
}
public List<Player> getPlayers() {
@@ -96,8 +96,8 @@ public class Game {
}
}
- public PreparedCard prepareCard(String userName, PlayerMove playerMove) throws InvalidMoveException {
- Player player = getPlayer(userName);
+ public PreparedCard prepareCard(String username, PlayerMove playerMove) throws InvalidMoveException {
+ Player player = getPlayer(username);
Card card = decks.getCard(playerMove.getCardName());
Move move = playerMove.getType().resolve(player.getIndex(), card, playerMove);
validate(move);
@@ -105,11 +105,11 @@ public class Game {
return new PreparedCard(player, card.getBack());
}
- private Player getPlayer(String userName) {
+ private Player getPlayer(String username) {
return players.stream()
- .filter(p -> p.getUserName().equals(userName))
+ .filter(p -> p.getUsername().equals(username))
.findAny()
- .orElseThrow(() -> new UnknownPlayerException(userName));
+ .orElseThrow(() -> new UnknownPlayerException(username));
}
private void validate(Move move) throws InvalidMoveException {
@@ -222,8 +222,8 @@ public class Game {
}
private static class UnknownPlayerException extends IllegalArgumentException {
- UnknownPlayerException(String userName) {
- super(userName);
+ UnknownPlayerException(String username) {
+ super(username);
}
}
diff --git a/src/main/java/org/luxons/sevenwonders/game/Lobby.java b/src/main/java/org/luxons/sevenwonders/game/Lobby.java
index c0201438..6975349a 100644
--- a/src/main/java/org/luxons/sevenwonders/game/Lobby.java
+++ b/src/main/java/org/luxons/sevenwonders/game/Lobby.java
@@ -90,29 +90,29 @@ public class Lobby {
return players.size() >= gameDefinition.getMinPlayers();
}
- public void reorderPlayers(List<String> orderedUserNames) {
+ public void reorderPlayers(List<String> orderedUsernames) {
List<Player> formerList = new ArrayList<>(players);
players.clear();
- for (int i = 0; i < orderedUserNames.size(); i++) {
- Player player = getPlayer(formerList, orderedUserNames.get(i));
+ for (int i = 0; i < orderedUsernames.size(); i++) {
+ Player player = getPlayer(formerList, orderedUsernames.get(i));
players.add(player);
player.setIndex(i);
}
}
- private static Player getPlayer(List<Player> players, String userName) {
+ private static Player getPlayer(List<Player> players, String username) {
return players.stream()
- .filter(p -> p.getUserName().equals(userName))
+ .filter(p -> p.getUsername().equals(username))
.findAny()
- .orElseThrow(() -> new UnknownPlayerException(userName));
+ .orElseThrow(() -> new UnknownPlayerException(username));
}
- public boolean isOwner(String userName) {
- return owner.getUserName().equals(userName);
+ public boolean isOwner(String username) {
+ return owner.getUsername().equals(username);
}
- public boolean containsUser(String userName) {
- return players.stream().anyMatch(p -> p.getUserName().equals(userName));
+ public boolean containsUser(String username) {
+ return players.stream().anyMatch(p -> p.getUsername().equals(username));
}
static class GameAlreadyStartedException extends IllegalStateException {
@@ -131,8 +131,8 @@ public class Lobby {
}
static class UnknownPlayerException extends IllegalArgumentException {
- UnknownPlayerException(String userName) {
- super(userName);
+ UnknownPlayerException(String username) {
+ super(username);
}
}
}
diff --git a/src/main/java/org/luxons/sevenwonders/game/Player.java b/src/main/java/org/luxons/sevenwonders/game/Player.java
index c8c1509c..f1095049 100644
--- a/src/main/java/org/luxons/sevenwonders/game/Player.java
+++ b/src/main/java/org/luxons/sevenwonders/game/Player.java
@@ -4,7 +4,7 @@ import com.fasterxml.jackson.annotation.JsonIgnore;
public class Player {
- private final String userName;
+ private final String username;
private String displayName;
@@ -14,13 +14,13 @@ public class Player {
private transient Game game;
- public Player(String userName, String displayName) {
- this.userName = userName;
+ public Player(String username, String displayName) {
+ this.username = username;
this.displayName = displayName;
}
- public String getUserName() {
- return userName;
+ public String getUsername() {
+ return username;
}
public String getDisplayName() {
diff --git a/src/main/java/org/luxons/sevenwonders/repositories/PlayerRepository.java b/src/main/java/org/luxons/sevenwonders/repositories/PlayerRepository.java
index 76df13b4..f6c29d83 100644
--- a/src/main/java/org/luxons/sevenwonders/repositories/PlayerRepository.java
+++ b/src/main/java/org/luxons/sevenwonders/repositories/PlayerRepository.java
@@ -12,50 +12,50 @@ public class PlayerRepository {
private Map<String, Player> players = new HashMap<>();
- public Player updateOrCreatePlayer(String userName, String displayName) {
- if (players.containsKey(userName)) {
- return updatePlayerName(userName, displayName);
+ public Player updateOrCreatePlayer(String username, String displayName) {
+ if (players.containsKey(username)) {
+ return updatePlayerName(username, displayName);
} else {
- return createPlayer(userName, displayName);
+ return createPlayer(username, displayName);
}
}
- private Player createPlayer(String userName, String displayName) throws PlayerAlreadyExistsException {
- Player player = new Player(userName, displayName);
+ private Player createPlayer(String username, String displayName) throws PlayerAlreadyExistsException {
+ Player player = new Player(username, displayName);
add(player);
return player;
}
private void add(Player player) throws PlayerAlreadyExistsException {
- if (players.containsKey(player.getUserName())) {
- throw new PlayerAlreadyExistsException(player.getUserName());
+ if (players.containsKey(player.getUsername())) {
+ throw new PlayerAlreadyExistsException(player.getUsername());
}
- players.put(player.getUserName(), player);
+ players.put(player.getUsername(), player);
}
- private Player updatePlayerName(String userName, String displayName) throws PlayerNotFoundException {
- Player player = find(userName);
+ private Player updatePlayerName(String username, String displayName) throws PlayerNotFoundException {
+ Player player = find(username);
player.setDisplayName(displayName);
return player;
}
- public Player find(String userName) throws PlayerNotFoundException {
- Player player = players.get(userName);
+ public Player find(String username) throws PlayerNotFoundException {
+ Player player = players.get(username);
if (player == null) {
- throw new PlayerNotFoundException(userName);
+ throw new PlayerNotFoundException(username);
}
return player;
}
public static class PlayerNotFoundException extends ApiMisuseException {
- PlayerNotFoundException(String userName) {
- super("Player '" + userName + "' doesn't exist");
+ PlayerNotFoundException(String username) {
+ super("Player '" + username + "' doesn't exist");
}
}
private static class PlayerAlreadyExistsException extends ApiMisuseException {
- PlayerAlreadyExistsException(String userName) {
- super("Player '" + userName + "' already exists");
+ PlayerAlreadyExistsException(String username) {
+ super("Player '" + username + "' already exists");
}
}
}
diff --git a/src/main/java/org/luxons/sevenwonders/validation/DestinationAccessValidator.java b/src/main/java/org/luxons/sevenwonders/validation/DestinationAccessValidator.java
index 64f14dee..65b3623c 100644
--- a/src/main/java/org/luxons/sevenwonders/validation/DestinationAccessValidator.java
+++ b/src/main/java/org/luxons/sevenwonders/validation/DestinationAccessValidator.java
@@ -27,46 +27,46 @@ public class DestinationAccessValidator {
this.gameRepository = gameRepository;
}
- public boolean hasAccess(String userName, String destination) {
- if (userName == null) {
+ public boolean hasAccess(String username, String destination) {
+ if (username == null) {
// unnamed user cannot belong to anything
return false;
}
- if (hasForbiddenGameReference(userName, destination)) {
+ if (hasForbiddenGameReference(username, destination)) {
return false;
}
- if (hasForbiddenLobbyReference(userName, destination)) {
+ if (hasForbiddenLobbyReference(username, destination)) {
return false;
}
return true;
}
- private boolean hasForbiddenGameReference(String userName, String destination) {
+ private boolean hasForbiddenGameReference(String username, String destination) {
Matcher gameMatcher = gameDestination.matcher(destination);
if (!gameMatcher.matches()) {
return false; // no game reference is always OK
}
int gameId = extractId(gameMatcher);
- return !isUserInGame(userName, gameId);
+ return !isUserInGame(username, gameId);
}
- private boolean hasForbiddenLobbyReference(String userName, String destination) {
+ private boolean hasForbiddenLobbyReference(String username, String destination) {
Matcher lobbyMatcher = lobbyDestination.matcher(destination);
if (!lobbyMatcher.matches()) {
return false; // no lobby reference is always OK
}
int lobbyId = extractId(lobbyMatcher);
- return !isUserInLobby(userName, lobbyId);
+ return !isUserInLobby(username, lobbyId);
}
- private boolean isUserInGame(String userName, int gameId) {
+ private boolean isUserInGame(String username, int gameId) {
Game game = gameRepository.find(gameId);
- return game.containsUser(userName);
+ return game.containsUser(username);
}
- private boolean isUserInLobby(String userName, int lobbyId) {
+ private boolean isUserInLobby(String username, int lobbyId) {
Lobby lobby = lobbyRepository.find(lobbyId);
- return lobby.containsUser(userName);
+ return lobby.containsUser(username);
}
private static int extractId(Matcher matcher) {
diff --git a/src/test/java/org/luxons/sevenwonders/game/LobbyTest.java b/src/test/java/org/luxons/sevenwonders/game/LobbyTest.java
index d8a06575..4a12592e 100644
--- a/src/test/java/org/luxons/sevenwonders/game/LobbyTest.java
+++ b/src/test/java/org/luxons/sevenwonders/game/LobbyTest.java
@@ -78,15 +78,15 @@ public class LobbyTest {
}
@Test
- public void isOwner_trueWhenOwnerUserName() {
- assertTrue(lobby.isOwner(gameOwner.getUserName()));
+ 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()));
+ assertFalse(lobby.isOwner(player.getUsername()));
}
@Test
@@ -134,9 +134,9 @@ public class LobbyTest {
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());
+ 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)
diff --git a/src/test/java/org/luxons/sevenwonders/game/test/TestUtils.java b/src/test/java/org/luxons/sevenwonders/game/test/TestUtils.java
index e0b2ccd7..80236fda 100644
--- a/src/test/java/org/luxons/sevenwonders/game/test/TestUtils.java
+++ b/src/test/java/org/luxons/sevenwonders/game/test/TestUtils.java
@@ -41,9 +41,9 @@ public class TestUtils {
public static List<Player> createPlayers(int count) {
List<Player> players = new ArrayList<>(count);
for (int i = 0; i < count; i++) {
- String userName = "testUser" + i;
+ String username = "testUser" + i;
String displayName = "Test User " + i;
- Player player = new Player(userName, displayName);
+ Player player = new Player(username, displayName);
players.add(player);
}
return players;
@@ -53,9 +53,9 @@ public class TestUtils {
Settings settings = new Settings(5);
Wonder wonder = createWonder(initialResource);
- String userName = "testUser" + initialResource.getSymbol();
+ String username = "testUser" + initialResource.getSymbol();
String displayName = "Test User " + initialResource.getSymbol();
- Player player = new Player(userName, displayName);
+ Player player = new Player(username, displayName);
return new Board(wonder, player, settings);
}
diff --git a/src/test/java/org/luxons/sevenwonders/validation/DestinationAccessValidatorTest.java b/src/test/java/org/luxons/sevenwonders/validation/DestinationAccessValidatorTest.java
index 35b9f7c0..1a799ff3 100644
--- a/src/test/java/org/luxons/sevenwonders/validation/DestinationAccessValidatorTest.java
+++ b/src/test/java/org/luxons/sevenwonders/validation/DestinationAccessValidatorTest.java
@@ -28,8 +28,8 @@ public class DestinationAccessValidatorTest {
destinationAccessValidator = new DestinationAccessValidator(lobbyRepository, gameRepository);
}
- private Lobby createLobby(String gameName, String ownerUserName, String... otherPlayers) {
- Player owner = new Player(ownerUserName, ownerUserName);
+ private Lobby createLobby(String gameName, String ownerUsername, String... otherPlayers) {
+ Player owner = new Player(ownerUsername, ownerUsername);
Lobby lobby = lobbyRepository.create(gameName, owner);
for (String playerName : otherPlayers) {
Player player = new Player(playerName, playerName);
@@ -38,8 +38,8 @@ public class DestinationAccessValidatorTest {
return lobby;
}
- private void createGame(String gameName, String ownerUserName, String... otherPlayers) {
- Lobby lobby = createLobby(gameName, ownerUserName, otherPlayers);
+ private void createGame(String gameName, String ownerUsername, String... otherPlayers) {
+ Lobby lobby = createLobby(gameName, ownerUsername, otherPlayers);
Game game = lobby.startGame();
gameRepository.add(game);
}
bgstack15