summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--backend/src/test/java/org/luxons/sevenwonders/controllers/HomeControllerTest.java28
-rw-r--r--backend/src/test/java/org/luxons/sevenwonders/controllers/test/TestUtils.java15
2 files changed, 43 insertions, 0 deletions
diff --git a/backend/src/test/java/org/luxons/sevenwonders/controllers/HomeControllerTest.java b/backend/src/test/java/org/luxons/sevenwonders/controllers/HomeControllerTest.java
new file mode 100644
index 00000000..4f2b1a44
--- /dev/null
+++ b/backend/src/test/java/org/luxons/sevenwonders/controllers/HomeControllerTest.java
@@ -0,0 +1,28 @@
+package org.luxons.sevenwonders.controllers;
+
+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.repositories.PlayerRepository;
+
+import static org.junit.Assert.assertTrue;
+
+public class HomeControllerTest {
+
+ @Test
+ public void chooseName() {
+ PlayerRepository playerRepository = new PlayerRepository();
+ HomeController homeController = new HomeController(playerRepository);
+
+ ChooseNameAction action = new ChooseNameAction();
+ action.setPlayerName("Test User");
+
+ Principal principal = TestUtils.createPrincipal("testuser");
+
+ homeController.chooseName(action, principal);
+
+ assertTrue(playerRepository.contains("testuser"));
+ }
+}
diff --git a/backend/src/test/java/org/luxons/sevenwonders/controllers/test/TestUtils.java b/backend/src/test/java/org/luxons/sevenwonders/controllers/test/TestUtils.java
new file mode 100644
index 00000000..e5186fcc
--- /dev/null
+++ b/backend/src/test/java/org/luxons/sevenwonders/controllers/test/TestUtils.java
@@ -0,0 +1,15 @@
+package org.luxons.sevenwonders.controllers.test;
+
+import java.security.Principal;
+
+public class TestUtils {
+
+ public static Principal createPrincipal(String username) {
+ return new Principal() {
+ @Override
+ public String getName() {
+ return username;
+ }
+ };
+ }
+}
bgstack15