Refactoring: make id for local Sone optional
authorDavid ‘Bombe’ Roden <bombe@pterodactylus.net>
Mon, 2 Oct 2017 13:54:04 +0000 (15:54 +0200)
committerDavid ‘Bombe’ Roden <bombe@pterodactylus.net>
Mon, 2 Oct 2017 13:54:04 +0000 (15:54 +0200)
src/test/kotlin/net/pterodactylus/sone/web/ajax/CreateReplyAjaxPageTest.kt
src/test/kotlin/net/pterodactylus/sone/web/ajax/JsonPageTest.kt
src/test/kotlin/net/pterodactylus/sone/web/ajax/LockSoneAjaxPageTest.kt

index 6b110ae..b192f84 100644 (file)
@@ -49,7 +49,7 @@ class CreateReplyAjaxPageTest : JsonPageTest("createReply.ajax", pageSupplier =
        @Test
        fun `sender can be chosen from local sones`() {
            val sone = mock<Sone>().apply { whenever(id).thenReturn("local-sone") }
-               addLocalSone("local-sone", sone)
+               addLocalSone(sone)
                val post = mock<Post>()
                addPost(post, "post-id")
                val reply = mock<PostReply>().apply { whenever(id).thenReturn("reply-id") }
index c950a31..73dba5a 100644 (file)
@@ -195,8 +195,8 @@ abstract class JsonPageTest(
                remoteSones += (soneId ?: sone.id) to sone
        }
 
-       protected fun addLocalSone(id: String, sone: Sone) {
-               localSones += id to sone
+       protected fun addLocalSone(sone: Sone, id: String? = null) {
+               localSones[id ?: sone.id] = sone
        }
 
        protected fun addPost(post: Post, id: String? = null) {
index b63be51..61a0c40 100644 (file)
@@ -21,7 +21,7 @@ class LockSoneAjaxPageTest : JsonPageTest("lockSone.ajax", requiresLogin = false
        @Test
        fun `request with valid sone id results in locked sone`() {
                val sone = mock<Sone>()
-               addLocalSone("sone-id", sone)
+               addLocalSone(sone, "sone-id")
                addRequestParameter("sone", "sone-id")
                assertThat(json.isSuccess, equalTo(true))
                verify(core).lockSone(sone)