summaryrefslogtreecommitdiff
path: root/src/test/java/org
diff options
context:
space:
mode:
authorJoffrey BION <joffrey.bion@gmail.com>2017-01-17 00:39:29 +0100
committerJoffrey BION <joffrey.bion@gmail.com>2017-01-17 00:42:14 +0100
commit1f266fd7fe86597097b7f9fbf15150d5e4c2345c (patch)
tree8254201d028aacc536ba7094541069de411c33f1 /src/test/java/org
parentAdd test for LobbyRepository (diff)
downloadseven-wonders-1f266fd7fe86597097b7f9fbf15150d5e4c2345c.tar.gz
seven-wonders-1f266fd7fe86597097b7f9fbf15150d5e4c2345c.tar.bz2
seven-wonders-1f266fd7fe86597097b7f9fbf15150d5e4c2345c.zip
Add test for GameRepository
Diffstat (limited to 'src/test/java/org')
-rw-r--r--src/test/java/org/luxons/sevenwonders/game/test/TestUtils.java15
-rw-r--r--src/test/java/org/luxons/sevenwonders/repositories/GameRepositoryTest.java61
-rw-r--r--src/test/java/org/luxons/sevenwonders/repositories/LobbyRepositoryTest.java2
3 files changed, 77 insertions, 1 deletions
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 80236fda..b5ddb7b1 100644
--- a/src/test/java/org/luxons/sevenwonders/game/test/TestUtils.java
+++ b/src/test/java/org/luxons/sevenwonders/game/test/TestUtils.java
@@ -3,16 +3,21 @@ package org.luxons.sevenwonders.game.test;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
+import java.util.HashMap;
import java.util.List;
+import java.util.Map;
+import org.luxons.sevenwonders.game.Game;
import org.luxons.sevenwonders.game.Player;
import org.luxons.sevenwonders.game.Settings;
+import org.luxons.sevenwonders.game.api.CustomizableSettings;
import org.luxons.sevenwonders.game.api.Table;
import org.luxons.sevenwonders.game.boards.Board;
import org.luxons.sevenwonders.game.boards.Science;
import org.luxons.sevenwonders.game.boards.ScienceType;
import org.luxons.sevenwonders.game.cards.Card;
import org.luxons.sevenwonders.game.cards.Color;
+import org.luxons.sevenwonders.game.cards.Decks;
import org.luxons.sevenwonders.game.cards.Requirements;
import org.luxons.sevenwonders.game.effects.Effect;
import org.luxons.sevenwonders.game.effects.ScienceProgress;
@@ -26,6 +31,16 @@ import org.luxons.sevenwonders.game.wonders.WonderStage;
public class TestUtils {
+ public static Game createGame(int id, int nbPlayers) {
+ Settings settings = new Settings(nbPlayers, new CustomizableSettings());
+ List<Player> players = TestUtils.createPlayers(nbPlayers);
+ List<Board> boards = TestUtils.createBoards(nbPlayers);
+ List<Card> cards = TestUtils.createSampleCards(0, nbPlayers * 7);
+ Map<Integer, List<Card>> cardsPerAge = new HashMap<>();
+ cardsPerAge.put(1, cards);
+ return new Game(id, settings, players, boards, new Decks(cardsPerAge));
+ }
+
public static Table createTable(int nbPlayers) {
return new Table(createBoards(nbPlayers));
}
diff --git a/src/test/java/org/luxons/sevenwonders/repositories/GameRepositoryTest.java b/src/test/java/org/luxons/sevenwonders/repositories/GameRepositoryTest.java
new file mode 100644
index 00000000..5d7d558b
--- /dev/null
+++ b/src/test/java/org/luxons/sevenwonders/repositories/GameRepositoryTest.java
@@ -0,0 +1,61 @@
+package org.luxons.sevenwonders.repositories;
+
+import org.junit.Before;
+import org.junit.Test;
+import org.luxons.sevenwonders.game.Game;
+import org.luxons.sevenwonders.game.test.TestUtils;
+import org.luxons.sevenwonders.repositories.GameRepository.GameAlreadyExistsException;
+import org.luxons.sevenwonders.repositories.GameRepository.GameNotFoundException;
+
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertSame;
+import static org.junit.Assert.fail;
+
+public class GameRepositoryTest {
+
+ private GameRepository repository;
+
+ @Before
+ public void setUp() {
+ repository = new GameRepository();
+ }
+
+ @Test(expected = GameAlreadyExistsException.class)
+ public void add_failsOnExistingId() {
+ Game game1 = TestUtils.createGame(0, 5);
+ repository.add(game1);
+ Game game2 = TestUtils.createGame(0, 7);
+ repository.add(game2);
+ }
+
+ @Test(expected = GameNotFoundException.class)
+ public void find_failsOnUnknownId() {
+ repository.find(123);
+ }
+
+ @Test
+ public void find_returnsTheSameObject() {
+ Game game = TestUtils.createGame(0, 5);
+ repository.add(game);
+ assertSame(game, repository.find(0));
+ }
+
+ @Test(expected = GameNotFoundException.class)
+ public void remove_failsOnUnknownId() {
+ repository.remove(123);
+ }
+
+ @Test
+ public void remove_succeeds() {
+ Game game = TestUtils.createGame(0, 5);
+ repository.add(game);
+ assertNotNull(repository.find(0));
+ repository.remove(0);
+ try {
+ repository.find(0);
+ fail(); // the call to find() should have failed
+ } catch (GameNotFoundException e) {
+ // the game has been properly removed
+ }
+ }
+} \ No newline at end of file
diff --git a/src/test/java/org/luxons/sevenwonders/repositories/LobbyRepositoryTest.java b/src/test/java/org/luxons/sevenwonders/repositories/LobbyRepositoryTest.java
index 0fafebe2..f5a8d800 100644
--- a/src/test/java/org/luxons/sevenwonders/repositories/LobbyRepositoryTest.java
+++ b/src/test/java/org/luxons/sevenwonders/repositories/LobbyRepositoryTest.java
@@ -68,7 +68,7 @@ public class LobbyRepositoryTest {
assertNotNull(repository.find(lobby1.getId()));
repository.remove(lobby1.getId());
try {
- assertNotNull(repository.find(lobby1.getId()));
+ repository.find(lobby1.getId());
fail(); // the call to find() should have failed
} catch (LobbyNotFoundException e) {
// the lobby has been properly removed
bgstack15