summaryrefslogtreecommitdiff
path: root/backend/src/test/kotlin/org/luxons
diff options
context:
space:
mode:
authorjbion <joffrey.bion@amadeus.com>2019-02-21 00:52:51 +0100
committerjbion <joffrey.bion@amadeus.com>2019-02-21 00:52:51 +0100
commit548dd277dd8ad1ab9828f6ab1b548e962ce6530a (patch)
treecd1653a7648a5df63cf910d532458d89196c7229 /backend/src/test/kotlin/org/luxons
parentSimplify playability further (diff)
downloadseven-wonders-548dd277dd8ad1ab9828f6ab1b548e962ce6530a.tar.gz
seven-wonders-548dd277dd8ad1ab9828f6ab1b548e962ce6530a.tar.bz2
seven-wonders-548dd277dd8ad1ab9828f6ab1b548e962ce6530a.zip
Remove non idiomatic usages of lists
Diffstat (limited to 'backend/src/test/kotlin/org/luxons')
-rw-r--r--backend/src/test/kotlin/org/luxons/sevenwonders/controllers/LobbyControllerTest.kt7
-rw-r--r--backend/src/test/kotlin/org/luxons/sevenwonders/lobby/LobbyTest.kt39
2 files changed, 31 insertions, 15 deletions
diff --git a/backend/src/test/kotlin/org/luxons/sevenwonders/controllers/LobbyControllerTest.kt b/backend/src/test/kotlin/org/luxons/sevenwonders/controllers/LobbyControllerTest.kt
index 2d37b0f4..6e417970 100644
--- a/backend/src/test/kotlin/org/luxons/sevenwonders/controllers/LobbyControllerTest.kt
+++ b/backend/src/test/kotlin/org/luxons/sevenwonders/controllers/LobbyControllerTest.kt
@@ -15,7 +15,6 @@ import org.luxons.sevenwonders.repositories.LobbyRepository
import org.luxons.sevenwonders.repositories.PlayerNotFoundException
import org.luxons.sevenwonders.repositories.PlayerRepository
import org.luxons.sevenwonders.test.mockSimpMessagingTemplate
-import java.util.Arrays
import java.util.HashMap
import kotlin.test.assertEquals
import kotlin.test.assertFalse
@@ -99,10 +98,10 @@ class LobbyControllerTest {
val player3 = addPlayer(lobby, "testuser3")
val player4 = addPlayer(lobby, "testuser4")
- val players = Arrays.asList(player, player2, player3, player4)
+ val players = listOf(player, player2, player3, player4)
assertEquals(players, lobby.getPlayers())
- val reorderedPlayers = Arrays.asList(player3, player, player2, player4)
+ val reorderedPlayers = listOf(player3, player, player2, player4)
val playerNames = reorderedPlayers.map { it.username }
val reorderPlayersAction = ReorderPlayersAction(playerNames)
@@ -120,7 +119,7 @@ class LobbyControllerTest {
val player2 = addPlayer(lobby, "testuser2")
val player3 = addPlayer(lobby, "testuser3")
- val reorderedPlayers = Arrays.asList(player3, player, player2)
+ val reorderedPlayers = listOf(player3, player, player2)
val playerNames = reorderedPlayers.map { it.username }
val reorderPlayersAction = ReorderPlayersAction(playerNames)
diff --git a/backend/src/test/kotlin/org/luxons/sevenwonders/lobby/LobbyTest.kt b/backend/src/test/kotlin/org/luxons/sevenwonders/lobby/LobbyTest.kt
index 85c89595..98e154da 100644
--- a/backend/src/test/kotlin/org/luxons/sevenwonders/lobby/LobbyTest.kt
+++ b/backend/src/test/kotlin/org/luxons/sevenwonders/lobby/LobbyTest.kt
@@ -13,11 +13,11 @@ import org.junit.runner.RunWith
import org.luxons.sevenwonders.game.api.CustomizableSettings
import org.luxons.sevenwonders.game.data.GameDefinition
import org.luxons.sevenwonders.lobby.Lobby.GameAlreadyStartedException
+import org.luxons.sevenwonders.lobby.Lobby.PlayerListMismatchException
import org.luxons.sevenwonders.lobby.Lobby.PlayerNameAlreadyUsedException
import org.luxons.sevenwonders.lobby.Lobby.PlayerOverflowException
import org.luxons.sevenwonders.lobby.Lobby.PlayerUnderflowException
import org.luxons.sevenwonders.lobby.Lobby.UnknownPlayerException
-import java.util.Arrays
import kotlin.test.assertEquals
import kotlin.test.assertFalse
import kotlin.test.assertNotNull
@@ -150,21 +150,38 @@ class LobbyTest {
lobby.addPlayer(player1)
lobby.addPlayer(player2)
lobby.addPlayer(player3)
- lobby.reorderPlayers(Arrays.asList("testuser3", "testuser1", "testuser2"))
- assertEquals("testuser3", lobby.getPlayers()[0].username)
- assertEquals("testuser1", lobby.getPlayers()[1].username)
- assertEquals("testuser2", lobby.getPlayers()[2].username)
+
+ val reorderedUsernames = listOf("testuser3", "gameowner", "testuser1", "testuser2")
+ lobby.reorderPlayers(reorderedUsernames)
+
+ assertEquals(reorderedUsernames, lobby.getPlayers().map { it.username })
}
- @Test(expected = UnknownPlayerException::class)
+ @Test(expected = PlayerListMismatchException::class)
fun reorderPlayers_failsOnUnknownPlayer() {
val player1 = Player("testuser1", "Test User 1")
val player2 = Player("testuser2", "Test User 2")
- val player3 = Player("testuser3", "Test User 3")
lobby.addPlayer(player1)
lobby.addPlayer(player2)
- lobby.addPlayer(player3)
- lobby.reorderPlayers(Arrays.asList("unknown", "testuser1", "testuser2"))
+ lobby.reorderPlayers(listOf("unknown", "testuser2", "gameowner"))
+ }
+
+ @Test(expected = PlayerListMismatchException::class)
+ fun reorderPlayers_failsOnExtraPlayer() {
+ val player1 = Player("testuser1", "Test User 1")
+ val player2 = Player("testuser2", "Test User 2")
+ lobby.addPlayer(player1)
+ lobby.addPlayer(player2)
+ lobby.reorderPlayers(listOf("testuser2", "onemore", "testuser1", "gameowner"))
+ }
+
+ @Test(expected = PlayerListMismatchException::class)
+ fun reorderPlayers_failsOnMissingPlayer() {
+ val player1 = Player("testuser1", "Test User 1")
+ val player2 = Player("testuser2", "Test User 2")
+ lobby.addPlayer(player1)
+ lobby.addPlayer(player2)
+ lobby.reorderPlayers(listOf("testuser2", "gameowner"))
}
@Theory
@@ -203,11 +220,11 @@ class LobbyTest {
@Test
fun startGame_switchesState() {
- assertTrue(lobby.state === State.LOBBY)
+ assertEquals(State.LOBBY, lobby.state)
// there is already the owner
addPlayers(gameDefinition.minPlayers - 1)
lobby.startGame()
- assertTrue(lobby.state === State.PLAYING)
+ assertEquals(State.PLAYING, lobby.state)
}
@Test
bgstack15