summaryrefslogtreecommitdiff
path: root/backend/src/main/java/org/luxons
diff options
context:
space:
mode:
authorJoffrey BION <joffrey.bion@gmail.com>2017-05-20 12:31:39 +0200
committerJoffrey BION <joffrey.bion@gmail.com>2017-05-20 12:31:39 +0200
commit9c716b434925385ba7da368b5b1006695259e060 (patch)
treeb337b6f2bbb87e59e4fd4cdc9ebc4aeafe939b78 /backend/src/main/java/org/luxons
parentAdd checks on last played moves in GameTest (diff)
downloadseven-wonders-9c716b434925385ba7da368b5b1006695259e060.tar.gz
seven-wonders-9c716b434925385ba7da368b5b1006695259e060.tar.bz2
seven-wonders-9c716b434925385ba7da368b5b1006695259e060.zip
Add LobbyController tests
Diffstat (limited to 'backend/src/main/java/org/luxons')
-rw-r--r--backend/src/main/java/org/luxons/sevenwonders/controllers/LobbyController.java18
-rw-r--r--backend/src/main/java/org/luxons/sevenwonders/game/api/CustomizableSettings.java23
2 files changed, 32 insertions, 9 deletions
diff --git a/backend/src/main/java/org/luxons/sevenwonders/controllers/LobbyController.java b/backend/src/main/java/org/luxons/sevenwonders/controllers/LobbyController.java
index 2bace487..c3378149 100644
--- a/backend/src/main/java/org/luxons/sevenwonders/controllers/LobbyController.java
+++ b/backend/src/main/java/org/luxons/sevenwonders/controllers/LobbyController.java
@@ -49,7 +49,7 @@ public class LobbyController {
@ApiMethod
@MessageMapping("/lobby/reorderPlayers")
public void reorderPlayers(@Validated ReorderPlayersAction action, Principal principal) {
- Lobby lobby = getLobby(principal);
+ Lobby lobby = getOwnedLobby(principal);
lobby.reorderPlayers(action.getOrderedPlayers());
logger.info("Players in game '{}' reordered to {}", lobby.getName(), action.getOrderedPlayers());
@@ -59,7 +59,7 @@ public class LobbyController {
@ApiMethod
@MessageMapping("/lobby/updateSettings")
public void updateSettings(@Validated UpdateSettingsAction action, Principal principal) {
- Lobby lobby = getLobby(principal);
+ Lobby lobby = getOwnedLobby(principal);
lobby.setSettings(action.getSettings());
logger.info("Updated settings of game '{}'", lobby.getName());
@@ -78,13 +78,13 @@ public class LobbyController {
Game game = lobby.startGame();
logger.info("Game '{}' successfully started", game.getId());
- template.convertAndSend("/topic/lobby/" + lobby.getId() + "/started", (Object) null);
+ template.convertAndSend("/topic/lobby/" + lobby.getId() + "/started", "");
}
private Lobby getOwnedLobby(Principal principal) {
Lobby lobby = getLobby(principal);
if (!lobby.isOwner(principal.getName())) {
- throw new UserIsNotOwnerException(principal.getName());
+ throw new PlayerIsNotOwnerException(principal.getName());
}
return lobby;
}
@@ -92,7 +92,7 @@ public class LobbyController {
private Lobby getLobby(Principal principal) {
Lobby lobby = getPlayer(principal).getLobby();
if (lobby == null) {
- throw new UserNotInLobbyException(principal.getName());
+ throw new PlayerNotInLobbyException(principal.getName());
}
return lobby;
}
@@ -101,14 +101,14 @@ public class LobbyController {
return playerRepository.find(principal.getName());
}
- private static class UserNotInLobbyException extends ApiMisuseException {
- UserNotInLobbyException(String username) {
+ static class PlayerNotInLobbyException extends ApiMisuseException {
+ PlayerNotInLobbyException(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) {
+ static class PlayerIsNotOwnerException extends ApiMisuseException {
+ PlayerIsNotOwnerException(String username) {
super("User " + username + " does not own the lobby he's in");
}
}
diff --git a/backend/src/main/java/org/luxons/sevenwonders/game/api/CustomizableSettings.java b/backend/src/main/java/org/luxons/sevenwonders/game/api/CustomizableSettings.java
index ee6a7714..2cbf8727 100644
--- a/backend/src/main/java/org/luxons/sevenwonders/game/api/CustomizableSettings.java
+++ b/backend/src/main/java/org/luxons/sevenwonders/game/api/CustomizableSettings.java
@@ -2,6 +2,7 @@ package org.luxons.sevenwonders.game.api;
import java.util.HashMap;
import java.util.Map;
+import java.util.Objects;
import org.luxons.sevenwonders.game.data.definitions.WonderSidePickMethod;
@@ -102,4 +103,26 @@ public class CustomizableSettings {
public void setWonPointsPerVictoryPerAge(Map<Integer, Integer> wonPointsPerVictoryPerAge) {
this.wonPointsPerVictoryPerAge = wonPointsPerVictoryPerAge;
}
+
+ @Override
+ public boolean equals(Object o) {
+ if (this == o) {
+ return true;
+ }
+ if (o == null || getClass() != o.getClass()) {
+ return false;
+ }
+ CustomizableSettings that = (CustomizableSettings) o;
+ return randomSeedForTests == that.randomSeedForTests && timeLimitInSeconds == that.timeLimitInSeconds
+ && initialGold == that.initialGold && discardedCardGold == that.discardedCardGold
+ && defaultTradingCost == that.defaultTradingCost && pointsPer3Gold == that.pointsPer3Gold
+ && lostPointsPerDefeat == that.lostPointsPerDefeat && wonderSidePickMethod == that.wonderSidePickMethod
+ && Objects.equals(wonPointsPerVictoryPerAge, that.wonPointsPerVictoryPerAge);
+ }
+
+ @Override
+ public int hashCode() {
+ return Objects.hash(randomSeedForTests, timeLimitInSeconds, wonderSidePickMethod, initialGold,
+ discardedCardGold, defaultTradingCost, pointsPer3Gold, lostPointsPerDefeat, wonPointsPerVictoryPerAge);
+ }
}
bgstack15