summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorjbion <joffrey.bion@amadeus.com>2016-12-20 20:10:58 +0100
committerjbion <joffrey.bion@amadeus.com>2016-12-21 01:29:28 +0100
commit221579f0c899a180de5a39346d738a32211b00a3 (patch)
treefb8dfbd56aff2e3fb09043e0254caa6dd3eb302e /src
parentFix json not parsing errors (diff)
downloadseven-wonders-221579f0c899a180de5a39346d738a32211b00a3.tar.gz
seven-wonders-221579f0c899a180de5a39346d738a32211b00a3.tar.bz2
seven-wonders-221579f0c899a180de5a39346d738a32211b00a3.zip
Add missing tests to DestinationAccessValidatorTest
Diffstat (limited to 'src')
-rw-r--r--src/main/java/org/luxons/sevenwonders/repositories/GameRepository.java2
-rw-r--r--src/main/java/org/luxons/sevenwonders/validation/DestinationAccessValidator.java3
-rw-r--r--src/test/java/org/luxons/sevenwonders/validation/DestinationAccessValidatorTest.java48
3 files changed, 37 insertions, 16 deletions
diff --git a/src/main/java/org/luxons/sevenwonders/repositories/GameRepository.java b/src/main/java/org/luxons/sevenwonders/repositories/GameRepository.java
index 0e0f6db8..59e984af 100644
--- a/src/main/java/org/luxons/sevenwonders/repositories/GameRepository.java
+++ b/src/main/java/org/luxons/sevenwonders/repositories/GameRepository.java
@@ -27,7 +27,7 @@ public class GameRepository {
return game;
}
- private static class GameNotFoundException extends ApiMisuseException {
+ public static class GameNotFoundException extends ApiMisuseException {
GameNotFoundException(long id) {
super("Game " + id + " doesn't exist");
}
diff --git a/src/main/java/org/luxons/sevenwonders/validation/DestinationAccessValidator.java b/src/main/java/org/luxons/sevenwonders/validation/DestinationAccessValidator.java
index bc7e52ce..64f14dee 100644
--- a/src/main/java/org/luxons/sevenwonders/validation/DestinationAccessValidator.java
+++ b/src/main/java/org/luxons/sevenwonders/validation/DestinationAccessValidator.java
@@ -71,9 +71,6 @@ public class DestinationAccessValidator {
private static int extractId(Matcher matcher) {
String id = matcher.group("id");
- if (id == null) {
- throw new IllegalArgumentException("No id matched in the destination");
- }
return Integer.parseInt(id);
}
}
diff --git a/src/test/java/org/luxons/sevenwonders/validation/DestinationAccessValidatorTest.java b/src/test/java/org/luxons/sevenwonders/validation/DestinationAccessValidatorTest.java
index 1ae0b3fc..75839f16 100644
--- a/src/test/java/org/luxons/sevenwonders/validation/DestinationAccessValidatorTest.java
+++ b/src/test/java/org/luxons/sevenwonders/validation/DestinationAccessValidatorTest.java
@@ -8,6 +8,7 @@ import org.luxons.sevenwonders.game.Player;
import org.luxons.sevenwonders.game.Settings;
import org.luxons.sevenwonders.game.data.GameDefinitionLoader;
import org.luxons.sevenwonders.repositories.GameRepository;
+import org.luxons.sevenwonders.repositories.GameRepository.GameNotFoundException;
import org.luxons.sevenwonders.repositories.LobbyRepository;
import org.luxons.sevenwonders.repositories.LobbyRepository.LobbyNotFoundException;
@@ -46,6 +47,11 @@ public class DestinationAccessValidatorTest {
}
@Test
+ public void validate_failsOnNullUser() {
+ assertFalse(destinationAccessValidator.hasAccess(null, "doesNotMatter"));
+ }
+
+ @Test
public void validate_successWhenNoReference() {
assertTrue(destinationAccessValidator.hasAccess("", ""));
assertTrue(destinationAccessValidator.hasAccess("", "test"));
@@ -77,17 +83,35 @@ public class DestinationAccessValidatorTest {
destinationAccessValidator.hasAccess("", "/lobby/0");
}
+ @Test(expected = GameNotFoundException.class)
+ public void validate_failWhenNoGameExist() {
+ destinationAccessValidator.hasAccess("", "/game/0");
+ }
+
@Test(expected = LobbyNotFoundException.class)
public void validate_failWhenReferencedLobbyDoesNotExist() {
createLobby("Test Game", "ownerUser1");
createLobby("Test Game 2", "ownerUser2");
- destinationAccessValidator.hasAccess("", "/lobby/3");
+ destinationAccessValidator.hasAccess("doesNotMatter", "/lobby/3");
+ }
+
+ @Test(expected = GameNotFoundException.class)
+ public void validate_failWhenReferencedGameDoesNotExist() {
+ createGame("Test Game 1", "user1", "user2", "user3");
+ createGame("Test Game 2", "user4", "user5", "user6");
+ destinationAccessValidator.hasAccess("doesNotMatter", "/game/3");
}
@Test
public void validate_failWhenUserIsNotPartOfReferencedLobby() {
createLobby("Test Game", "ownerUser");
- destinationAccessValidator.hasAccess("", "/lobby/0");
+ destinationAccessValidator.hasAccess("userNotInLobby", "/lobby/0");
+ }
+
+ @Test
+ public void validate_failWhenUserIsNotPartOfReferencedGame() {
+ createGame("Test Game", "ownerUser", "otherUser1", "otherUser2");
+ destinationAccessValidator.hasAccess("userNotInGame", "/game/0");
}
@Test
@@ -107,19 +131,19 @@ public class DestinationAccessValidatorTest {
}
@Test
- public void validate_successWhenUserIsMemberOfReferencedGame() {
- createGame("Test Game 1", "user1", "user2", "user3");
- assertTrue(destinationAccessValidator.hasAccess("user2", "/game/0"));
- createGame("Test Game 2", "user4", "user5", "user6");
- assertTrue(destinationAccessValidator.hasAccess("user6", "/game/1"));
+ public void validate_successWhenUserIsOwnerOfReferencedGame() {
+ createGame("Test Game 1", "owner1", "user2", "user3");
+ assertTrue(destinationAccessValidator.hasAccess("owner1", "/game/0"));
+ createGame("Test Game 2", "owner4", "user5", "user6");
+ assertTrue(destinationAccessValidator.hasAccess("owner4", "/game/1"));
}
@Test
- public void validate_failsWhenUserPartOfReferencedGame() {
-// lobbyRepository.create("Test Game Name");
-// gameRepository.add();
- assertTrue(destinationAccessValidator.hasAccess("", "/game/notAnId"));
- assertTrue(destinationAccessValidator.hasAccess("", "/lobby/notAnId"));
+ public void validate_successWhenUserIsMemberOfReferencedGame() {
+ createGame("Test Game 1", "owner1", "user2", "user3");
+ assertTrue(destinationAccessValidator.hasAccess("user2", "/game/0"));
+ createGame("Test Game 2", "owner4", "user5", "user6");
+ assertTrue(destinationAccessValidator.hasAccess("user6", "/game/1"));
}
} \ No newline at end of file
bgstack15