summaryrefslogtreecommitdiff
path: root/src/test/java/org/luxons/sevenwonders
diff options
context:
space:
mode:
authorJoffrey BION <joffrey.bion@gmail.com>2017-01-16 23:44:11 +0100
committerJoffrey BION <joffrey.bion@gmail.com>2017-01-16 23:44:11 +0100
commit37ae284808621312c4c3b49105d3b0efd02f53ca (patch)
tree8dbde24bdfeffc73790d32d5c8c3a8a32b781606 /src/test/java/org/luxons/sevenwonders
parentStandardize PlayerRepository's API (diff)
downloadseven-wonders-37ae284808621312c4c3b49105d3b0efd02f53ca.tar.gz
seven-wonders-37ae284808621312c4c3b49105d3b0efd02f53ca.tar.bz2
seven-wonders-37ae284808621312c4c3b49105d3b0efd02f53ca.zip
Add test for PlayerRepository
Diffstat (limited to 'src/test/java/org/luxons/sevenwonders')
-rw-r--r--src/test/java/org/luxons/sevenwonders/repositories/PlayerRepositoryTest.java68
1 files changed, 68 insertions, 0 deletions
diff --git a/src/test/java/org/luxons/sevenwonders/repositories/PlayerRepositoryTest.java b/src/test/java/org/luxons/sevenwonders/repositories/PlayerRepositoryTest.java
index a8a7643c..d9e07b3f 100644
--- a/src/test/java/org/luxons/sevenwonders/repositories/PlayerRepositoryTest.java
+++ b/src/test/java/org/luxons/sevenwonders/repositories/PlayerRepositoryTest.java
@@ -1,5 +1,73 @@
package org.luxons.sevenwonders.repositories;
+import org.junit.Before;
+import org.junit.Test;
+import org.luxons.sevenwonders.game.Player;
+import org.luxons.sevenwonders.repositories.PlayerRepository.PlayerNotFoundException;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertSame;
+import static org.junit.Assert.assertTrue;
+
public class PlayerRepositoryTest {
+ private PlayerRepository repository;
+
+ @Before
+ public void setUp() {
+ repository = new PlayerRepository();
+ }
+
+ @Test
+ public void contains_falseIfNoUserAdded() {
+ assertFalse(repository.contains("anyUsername"));
+ }
+
+ @Test
+ public void contains_trueForCreatedPlayer() {
+ repository.createOrUpdate("player1", "Player 1");
+ assertTrue(repository.contains("player1"));
+ }
+
+ @Test
+ public void createOrUpdate_createsProperly() {
+ Player player1 = repository.createOrUpdate("player1", "Player 1");
+ assertEquals("player1", player1.getUsername());
+ assertEquals("Player 1", player1.getDisplayName());
+ }
+
+ @Test
+ public void createOrUpdate_updatesDisplayName() {
+ Player player1 = repository.createOrUpdate("player1", "Player 1");
+ Player player1Updated = repository.createOrUpdate("player1", "Much Better Name");
+ assertSame(player1, player1Updated);
+ assertEquals("Much Better Name", player1Updated.getDisplayName());
+ }
+
+ @Test(expected = PlayerNotFoundException.class)
+ public void find_failsOnUnknownUsername() {
+ repository.find("anyUsername");
+ }
+
+ @Test
+ public void find_returnsTheSameObject() {
+ Player player1 = repository.createOrUpdate("player1", "Player 1");
+ Player player2 = repository.createOrUpdate("player2", "Player 2");
+ assertSame(player1, repository.find("player1"));
+ assertSame(player2, repository.find("player2"));
+ }
+
+ @Test(expected = PlayerNotFoundException.class)
+ public void remove_failsOnUnknownUsername() {
+ repository.remove("anyUsername");
+ }
+
+ @Test
+ public void remove_succeeds() {
+ repository.createOrUpdate("player1", "Player 1");
+ assertTrue(repository.contains("player1"));
+ repository.remove("player1");
+ assertFalse(repository.contains("player1"));
+ }
} \ No newline at end of file
bgstack15