From 8175862a76a1b1d7a9a48de9dc459b26d3a1ba1a Mon Sep 17 00:00:00 2001 From: Joffrey BION Date: Tue, 16 May 2017 21:06:19 +0200 Subject: Improve assertions in HomeControllerTest --- .../controllers/GameBrowserControllerTest.java | 2 +- .../controllers/HomeControllerTest.java | 14 ++++++--- .../sevenwonders/controllers/test/TestUtils.java | 34 ---------------------- .../org/luxons/sevenwonders/test/TestUtils.java | 30 +++++++++++++++++++ 4 files changed, 41 insertions(+), 39 deletions(-) delete mode 100644 backend/src/test/java/org/luxons/sevenwonders/controllers/test/TestUtils.java create mode 100644 backend/src/test/java/org/luxons/sevenwonders/test/TestUtils.java (limited to 'backend/src/test/java/org/luxons') 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/controllers/test/TestUtils.java deleted file mode 100644 index 05ad8b5d..00000000 --- a/backend/src/test/java/org/luxons/sevenwonders/controllers/test/TestUtils.java +++ /dev/null @@ -1,34 +0,0 @@ -package org.luxons.sevenwonders.controllers.test; - -import java.security.Principal; - -import org.springframework.messaging.Message; -import org.springframework.messaging.MessageChannel; -import org.springframework.messaging.simp.SimpMessagingTemplate; - -public class TestUtils { - - public static Principal createPrincipal(String username) { - return new Principal() { - @Override - public String getName() { - return username; - } - }; - } - - public static SimpMessagingTemplate createSimpMessagingTemplate() { - MessageChannel messageChannel = new MessageChannel() { - @Override - public boolean send(Message message) { - return true; - } - - @Override - public boolean send(Message message, long timeout) { - return true; - } - }; - return new SimpMessagingTemplate(messageChannel); - } -} diff --git a/backend/src/test/java/org/luxons/sevenwonders/test/TestUtils.java b/backend/src/test/java/org/luxons/sevenwonders/test/TestUtils.java new file mode 100644 index 00000000..46673c58 --- /dev/null +++ b/backend/src/test/java/org/luxons/sevenwonders/test/TestUtils.java @@ -0,0 +1,30 @@ +package org.luxons.sevenwonders.test; + +import java.security.Principal; + +import org.springframework.messaging.Message; +import org.springframework.messaging.MessageChannel; +import org.springframework.messaging.simp.SimpMessagingTemplate; + +public class TestUtils { + + public static Principal createPrincipal(String username) { + // the Principal interface just contains a getName() method + return () -> username; + } + + public static SimpMessagingTemplate createSimpMessagingTemplate() { + MessageChannel messageChannel = new MessageChannel() { + @Override + public boolean send(Message message) { + return true; + } + + @Override + public boolean send(Message message, long timeout) { + return true; + } + }; + return new SimpMessagingTemplate(messageChannel); + } +} -- cgit