summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJoffrey BION <joffrey.bion@gmail.com>2017-05-16 21:06:19 +0200
committerJoffrey BION <joffrey.bion@gmail.com>2017-05-16 21:06:19 +0200
commit8175862a76a1b1d7a9a48de9dc459b26d3a1ba1a (patch)
treec9d008c14ccd9da61560e2b9a397023922b4516f
parentAdd GameBrowserController test (diff)
downloadseven-wonders-8175862a76a1b1d7a9a48de9dc459b26d3a1ba1a.tar.gz
seven-wonders-8175862a76a1b1d7a9a48de9dc459b26d3a1ba1a.tar.bz2
seven-wonders-8175862a76a1b1d7a9a48de9dc459b26d3a1ba1a.zip
Improve assertions in HomeControllerTest
-rw-r--r--backend/src/test/java/org/luxons/sevenwonders/controllers/GameBrowserControllerTest.java2
-rw-r--r--backend/src/test/java/org/luxons/sevenwonders/controllers/HomeControllerTest.java14
-rw-r--r--backend/src/test/java/org/luxons/sevenwonders/test/TestUtils.java (renamed from backend/src/test/java/org/luxons/sevenwonders/controllers/test/TestUtils.java)10
3 files changed, 14 insertions, 12 deletions
diff --git a/backend/src/test/java/org/luxons/sevenwonders/controllers/GameBrowserControllerTest.java b/backend/src/test/java/org/luxons/sevenwonders/controllers/GameBrowserControllerTest.java
index 56f54fc2..8f596434 100644
--- a/backend/src/test/java/org/luxons/sevenwonders/controllers/GameBrowserControllerTest.java
+++ b/backend/src/test/java/org/luxons/sevenwonders/controllers/GameBrowserControllerTest.java
@@ -8,7 +8,7 @@ import org.junit.Test;
import org.luxons.sevenwonders.actions.CreateGameAction;
import org.luxons.sevenwonders.actions.JoinGameAction;
import org.luxons.sevenwonders.controllers.GameBrowserController.UserAlreadyInGameException;
-import org.luxons.sevenwonders.controllers.test.TestUtils;
+import org.luxons.sevenwonders.test.TestUtils;
import org.luxons.sevenwonders.game.data.GameDefinitionLoader;
import org.luxons.sevenwonders.lobby.Lobby;
import org.luxons.sevenwonders.lobby.Player;
diff --git a/backend/src/test/java/org/luxons/sevenwonders/controllers/HomeControllerTest.java b/backend/src/test/java/org/luxons/sevenwonders/controllers/HomeControllerTest.java
index 4f2b1a44..1563e1a2 100644
--- a/backend/src/test/java/org/luxons/sevenwonders/controllers/HomeControllerTest.java
+++ b/backend/src/test/java/org/luxons/sevenwonders/controllers/HomeControllerTest.java
@@ -4,10 +4,12 @@ import java.security.Principal;
import org.junit.Test;
import org.luxons.sevenwonders.actions.ChooseNameAction;
-import org.luxons.sevenwonders.controllers.test.TestUtils;
+import org.luxons.sevenwonders.test.TestUtils;
+import org.luxons.sevenwonders.lobby.Player;
import org.luxons.sevenwonders.repositories.PlayerRepository;
-import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertSame;
public class HomeControllerTest {
@@ -21,8 +23,12 @@ public class HomeControllerTest {
Principal principal = TestUtils.createPrincipal("testuser");
- homeController.chooseName(action, principal);
+ Player player = homeController.chooseName(action, principal);
- assertTrue(playerRepository.contains("testuser"));
+ assertSame(player, playerRepository.find("testuser"));
+ assertEquals("testuser", player.getUsername());
+ assertEquals("Test User", player.getDisplayName());
+ assertEquals(null, player.getLobby());
+ assertEquals(null, player.getGame());
}
}
diff --git a/backend/src/test/java/org/luxons/sevenwonders/controllers/test/TestUtils.java b/backend/src/test/java/org/luxons/sevenwonders/test/TestUtils.java
index 05ad8b5d..46673c58 100644
--- a/backend/src/test/java/org/luxons/sevenwonders/controllers/test/TestUtils.java
+++ b/backend/src/test/java/org/luxons/sevenwonders/test/TestUtils.java
@@ -1,4 +1,4 @@
-package org.luxons.sevenwonders.controllers.test;
+package org.luxons.sevenwonders.test;
import java.security.Principal;
@@ -9,12 +9,8 @@ import org.springframework.messaging.simp.SimpMessagingTemplate;
public class TestUtils {
public static Principal createPrincipal(String username) {
- return new Principal() {
- @Override
- public String getName() {
- return username;
- }
- };
+ // the Principal interface just contains a getName() method
+ return () -> username;
}
public static SimpMessagingTemplate createSimpMessagingTemplate() {
bgstack15