diff options
author | Joffrey BION <joffrey.bion@gmail.com> | 2017-01-17 00:39:29 +0100 |
---|---|---|
committer | Joffrey BION <joffrey.bion@gmail.com> | 2017-01-17 00:42:14 +0100 |
commit | 1f266fd7fe86597097b7f9fbf15150d5e4c2345c (patch) | |
tree | 8254201d028aacc536ba7094541069de411c33f1 /src/main/java | |
parent | Add test for LobbyRepository (diff) | |
download | seven-wonders-1f266fd7fe86597097b7f9fbf15150d5e4c2345c.tar.gz seven-wonders-1f266fd7fe86597097b7f9fbf15150d5e4c2345c.tar.bz2 seven-wonders-1f266fd7fe86597097b7f9fbf15150d5e4c2345c.zip |
Add test for GameRepository
Diffstat (limited to 'src/main/java')
-rw-r--r-- | src/main/java/org/luxons/sevenwonders/repositories/GameRepository.java | 14 |
1 files changed, 11 insertions, 3 deletions
diff --git a/src/main/java/org/luxons/sevenwonders/repositories/GameRepository.java b/src/main/java/org/luxons/sevenwonders/repositories/GameRepository.java index 59e984af..efe39b85 100644 --- a/src/main/java/org/luxons/sevenwonders/repositories/GameRepository.java +++ b/src/main/java/org/luxons/sevenwonders/repositories/GameRepository.java @@ -12,14 +12,14 @@ public class GameRepository { private Map<Long, Game> games = new HashMap<>(); - public void add(Game game) { + public void add(Game game) throws GameAlreadyExistsException { if (games.containsKey(game.getId())) { throw new GameAlreadyExistsException(game.getId()); } games.put(game.getId(), game); } - public Game find(long gameId) { + public Game find(long gameId) throws GameNotFoundException { Game game = games.get(gameId); if (game == null) { throw new GameNotFoundException(gameId); @@ -27,13 +27,21 @@ public class GameRepository { return game; } + public Game remove(long gameId) throws GameNotFoundException { + Game game = games.remove(gameId); + if (game == null) { + throw new GameNotFoundException(gameId); + } + return game; + } + public static class GameNotFoundException extends ApiMisuseException { GameNotFoundException(long id) { super("Game " + id + " doesn't exist"); } } - private static class GameAlreadyExistsException extends ApiMisuseException { + static class GameAlreadyExistsException extends ApiMisuseException { GameAlreadyExistsException(long id) { super("Game " + id + " already exists"); } |