Move assertions to base class
authorDavid ‘Bombe’ Roden <bombe@pterodactylus.net>
Fri, 6 Oct 2017 05:11:34 +0000 (07:11 +0200)
committerDavid ‘Bombe’ Roden <bombe@pterodactylus.net>
Fri, 6 Oct 2017 05:11:34 +0000 (07:11 +0200)
29 files changed:
src/test/kotlin/net/pterodactylus/sone/web/ajax/BookmarkAjaxPageTest.kt
src/test/kotlin/net/pterodactylus/sone/web/ajax/CreatePostAjaxPageTest.kt
src/test/kotlin/net/pterodactylus/sone/web/ajax/CreateReplyAjaxPageTest.kt
src/test/kotlin/net/pterodactylus/sone/web/ajax/DeletePostAjaxPageTest.kt
src/test/kotlin/net/pterodactylus/sone/web/ajax/DeleteProfileFieldAjaxPageTest.kt
src/test/kotlin/net/pterodactylus/sone/web/ajax/DeleteReplyAjaxPageTest.kt
src/test/kotlin/net/pterodactylus/sone/web/ajax/DismissNotificationAjaxPageTest.kt
src/test/kotlin/net/pterodactylus/sone/web/ajax/DistrustAjaxPageTest.kt
src/test/kotlin/net/pterodactylus/sone/web/ajax/EditAlbumAjaxPageTest.kt
src/test/kotlin/net/pterodactylus/sone/web/ajax/EditImageAjaxPageTest.kt
src/test/kotlin/net/pterodactylus/sone/web/ajax/EditProfileFieldAjaxPageTest.kt
src/test/kotlin/net/pterodactylus/sone/web/ajax/FollowSoneAjaxPageTest.kt
src/test/kotlin/net/pterodactylus/sone/web/ajax/GetLikesAjaxPageTest.kt
src/test/kotlin/net/pterodactylus/sone/web/ajax/GetNotificationsAjaxPageTest.kt
src/test/kotlin/net/pterodactylus/sone/web/ajax/GetPostAjaxPageTest.kt
src/test/kotlin/net/pterodactylus/sone/web/ajax/GetReplyAjaxPageTest.kt
src/test/kotlin/net/pterodactylus/sone/web/ajax/GetTimesAjaxPageTest.kt
src/test/kotlin/net/pterodactylus/sone/web/ajax/GetTranslationAjaxPageTest.kt
src/test/kotlin/net/pterodactylus/sone/web/ajax/JsonPageTest.kt
src/test/kotlin/net/pterodactylus/sone/web/ajax/LikeAjaxPageTest.kt
src/test/kotlin/net/pterodactylus/sone/web/ajax/LockSoneAjaxPageTest.kt
src/test/kotlin/net/pterodactylus/sone/web/ajax/MarkAsKnownAjaxPageTest.kt
src/test/kotlin/net/pterodactylus/sone/web/ajax/MoveProfileFieldAjaxPageTest.kt
src/test/kotlin/net/pterodactylus/sone/web/ajax/TrustAjaxPageTest.kt
src/test/kotlin/net/pterodactylus/sone/web/ajax/UnbookmarkAjaxPageTest.kt
src/test/kotlin/net/pterodactylus/sone/web/ajax/UnfollowSoneAjaxPageTest.kt
src/test/kotlin/net/pterodactylus/sone/web/ajax/UnlikeAjaxPageTest.kt
src/test/kotlin/net/pterodactylus/sone/web/ajax/UnlockSoneAjaxPageTest.kt
src/test/kotlin/net/pterodactylus/sone/web/ajax/UntrustAjaxPageTest.kt

index 7e72e56..17c334e 100644 (file)
@@ -15,21 +15,19 @@ class BookmarkAjaxPageTest : JsonPageTest("bookmark.ajax", requiresLogin = false
 
        @Test
        fun `missing post ID results in invalid id response`() {
-               assertThat(json.isSuccess, equalTo(false))
-               assertThat(json.error, equalTo("invalid-post-id"))
+               assertThatJsonFailed("invalid-post-id")
        }
 
        @Test
        fun `empty post ID results in invalid id response`() {
                addRequestParameter("post", "")
-               assertThat(json.isSuccess, equalTo(false))
-               assertThat(json.error, equalTo("invalid-post-id"))
+               assertThatJsonFailed("invalid-post-id")
        }
 
        @Test
        fun `invalid post ID results in success but does not bookmark anything`() {
                addRequestParameter("post", "missing")
-               assertThat(json.isSuccess, equalTo(true))
+               assertThatJsonIsSuccessful()
                verify(core, never()).bookmarkPost(any<Post>())
        }
 
@@ -37,7 +35,7 @@ class BookmarkAjaxPageTest : JsonPageTest("bookmark.ajax", requiresLogin = false
        fun `valid post ID results in success and bookmarks the post`() {
                addRequestParameter("post", "valid-post-id")
                val post = addNewPost("valid-post-id", "1", 2)
-               assertThat(json.isSuccess, equalTo(true))
+               assertThatJsonIsSuccessful()
                verify(core).bookmarkPost(post)
        }
 
index 8d7e521..8449453 100644 (file)
@@ -18,22 +18,19 @@ class CreatePostAjaxPageTest : JsonPageTest("createPost.ajax", pageSupplier = ::
 
        @Test
        fun `missing text parameter returns error`() {
-               assertThat(json.isSuccess, equalTo(false))
-               assertThat(json.error, equalTo("text-required"))
+               assertThatJsonFailed("text-required")
        }
 
        @Test
        fun `empty text returns error`() {
                addRequestParameter("text", "")
-               assertThat(json.isSuccess, equalTo(false))
-               assertThat(json.error, equalTo("text-required"))
+               assertThatJsonFailed("text-required")
        }
 
        @Test
        fun `whitespace-only text returns error`() {
                addRequestParameter("text", "  ")
-               assertThat(json.isSuccess, equalTo(false))
-               assertThat(json.error, equalTo("text-required"))
+               assertThatJsonFailed("text-required")
        }
 
        @Test
@@ -41,7 +38,7 @@ class CreatePostAjaxPageTest : JsonPageTest("createPost.ajax", pageSupplier = ::
                addRequestParameter("text", "test")
                val post = createPost()
                whenever(core.createPost(currentSone, Optional.absent(), "test")).thenReturn(post)
-               assertThat(json.isSuccess, equalTo(true))
+               assertThatJsonIsSuccessful()
                assertThat(json["postId"]?.asText(), equalTo("id"))
                assertThat(json["sone"]?.asText(), equalTo(currentSone.id))
                assertThat(json["recipient"], nullValue())
@@ -53,7 +50,7 @@ class CreatePostAjaxPageTest : JsonPageTest("createPost.ajax", pageSupplier = ::
                addRequestParameter("recipient", "invalid")
                val post = createPost()
                whenever(core.createPost(currentSone, Optional.absent(), "test")).thenReturn(post)
-               assertThat(json.isSuccess, equalTo(true))
+               assertThatJsonIsSuccessful()
                assertThat(json["postId"]?.asText(), equalTo("id"))
                assertThat(json["sone"]?.asText(), equalTo(currentSone.id))
                assertThat(json["recipient"], nullValue())
@@ -67,7 +64,7 @@ class CreatePostAjaxPageTest : JsonPageTest("createPost.ajax", pageSupplier = ::
                addSone(recipient)
                val post = createPost("valid")
                whenever(core.createPost(currentSone, Optional.of(recipient), "test")).thenReturn(post)
-               assertThat(json.isSuccess, equalTo(true))
+               assertThatJsonIsSuccessful()
                assertThat(json["postId"]?.asText(), equalTo("id"))
                assertThat(json["sone"]?.asText(), equalTo(currentSone.id))
                assertThat(json["recipient"]?.asText(), equalTo("valid"))
@@ -79,7 +76,7 @@ class CreatePostAjaxPageTest : JsonPageTest("createPost.ajax", pageSupplier = ::
                addRequestHeader("Host", "freenet.test:8888")
                val post = createPost()
                whenever(core.createPost(currentSone, Optional.absent(), "Link KSK@foo is filtered")).thenReturn(post)
-               assertThat(json.isSuccess, equalTo(true))
+               assertThatJsonIsSuccessful()
                assertThat(json["postId"]?.asText(), equalTo("id"))
                assertThat(json["sone"]?.asText(), equalTo(currentSone.id))
                assertThat(json["recipient"], nullValue())
index 6931b69..829167e 100644 (file)
@@ -16,8 +16,7 @@ class CreateReplyAjaxPageTest : JsonPageTest("createReply.ajax", pageSupplier =
 
        @Test
        fun `invalid post ID results in error message`() {
-           assertThat(json.isSuccess, equalTo(false))
-               assertThat(json.error, equalTo("invalid-post-id"))
+               assertThatJsonFailed("invalid-post-id")
        }
 
        @Test
@@ -27,7 +26,7 @@ class CreateReplyAjaxPageTest : JsonPageTest("createReply.ajax", pageSupplier =
                val reply = mock<PostReply>().apply { whenever(id).thenReturn("reply-id") }
                whenever(core.createReply(currentSone, post, "")).thenReturn(reply)
            addRequestParameter("post", "post-id")
-               assertThat(json.isSuccess, equalTo(true))
+               assertThatJsonIsSuccessful()
                assertThat(json["reply"]?.asText(), equalTo("reply-id"))
                assertThat(json["sone"]?.asText(), equalTo("soneId"))
        }
@@ -41,7 +40,7 @@ class CreateReplyAjaxPageTest : JsonPageTest("createReply.ajax", pageSupplier =
                addRequestParameter("post", "post-id")
                addRequestParameter("text", "Text with http://127.0.0.1:8888/KSK@foo.bar link")
                addRequestHeader("Host", "127.0.0.1:8888")
-               assertThat(json.isSuccess, equalTo(true))
+               assertThatJsonIsSuccessful()
                assertThat(json["reply"]?.asText(), equalTo("reply-id"))
                assertThat(json["sone"]?.asText(), equalTo("soneId"))
        }
@@ -57,7 +56,7 @@ class CreateReplyAjaxPageTest : JsonPageTest("createReply.ajax", pageSupplier =
                addRequestParameter("post", "post-id")
                addRequestParameter("text", "Text")
                addRequestParameter("sender", "local-sone")
-               assertThat(json.isSuccess, equalTo(true))
+               assertThatJsonIsSuccessful()
                assertThat(json["reply"]?.asText(), equalTo("reply-id"))
                assertThat(json["sone"]?.asText(), equalTo("local-sone"))
        }
index a57e66d..cee50b9 100644 (file)
@@ -16,8 +16,7 @@ class DeletePostAjaxPageTest : JsonPageTest("deletePost.ajax", pageSupplier = ::
 
        @Test
        fun `missing post ID results in invalid id response`() {
-               assertThat(json.isSuccess, equalTo(false))
-               assertThat(json.error, equalTo("invalid-post-id"))
+               assertThatJsonFailed("invalid-post-id")
        }
 
        @Test
@@ -27,8 +26,7 @@ class DeletePostAjaxPageTest : JsonPageTest("deletePost.ajax", pageSupplier = ::
                whenever(post.sone).thenReturn(sone)
                addPost(post, "post-id")
                addRequestParameter("post", "post-id")
-               assertThat(json.isSuccess, equalTo(false))
-               assertThat(json.error, equalTo("not-authorized"))
+               assertThatJsonFailed("not-authorized")
        }
 
        @Test
@@ -38,7 +36,7 @@ class DeletePostAjaxPageTest : JsonPageTest("deletePost.ajax", pageSupplier = ::
                whenever(post.sone).thenReturn(sone)
                addPost(post, "post-id")
                addRequestParameter("post", "post-id")
-               assertThat(json.isSuccess, equalTo(true))
+               assertThatJsonIsSuccessful()
                verify(core).deletePost(post)
        }
 
index 6ea28f3..330bedf 100644 (file)
@@ -13,8 +13,7 @@ class DeleteProfileFieldAjaxPageTest : JsonPageTest("deleteProfileField.ajax", p
 
        @Test
        fun `request without field id results in invalid field id error`() {
-               assertThat(json.isSuccess, equalTo(false))
-               assertThat(json.error, equalTo("invalid-field-id"))
+               assertThatJsonFailed("invalid-field-id")
        }
 
        @Test
@@ -22,7 +21,7 @@ class DeleteProfileFieldAjaxPageTest : JsonPageTest("deleteProfileField.ajax", p
                profile.addField("foo")
                val fieldId = profile.getFieldByName("foo")!!.id
                addRequestParameter("field", fieldId)
-               assertThat(json.isSuccess, equalTo(true))
+               assertThatJsonIsSuccessful()
                assertThat(profile.getFieldByName("foo"), nullValue())
                verify(currentSone).profile = profile
                verify(core).touchConfiguration()
index b4ad019..e39332c 100644 (file)
@@ -16,8 +16,7 @@ class DeleteReplyAjaxPageTest : JsonPageTest("deleteReply.ajax", pageSupplier =
 
        @Test
        fun `request with missing reply results in invalid id`() {
-               assertThat(json.isSuccess, equalTo(false))
-               assertThat(json.error, equalTo("invalid-reply-id"))
+               assertThatJsonFailed("invalid-reply-id")
        }
 
        @Test
@@ -27,8 +26,7 @@ class DeleteReplyAjaxPageTest : JsonPageTest("deleteReply.ajax", pageSupplier =
                whenever(reply.sone).thenReturn(sone)
                addReply(reply, "reply-id")
                addRequestParameter("reply", "reply-id")
-               assertThat(json.isSuccess, equalTo(false))
-               assertThat(json.error, equalTo("not-authorized"))
+               assertThatJsonFailed("not-authorized")
        }
 
        @Test
@@ -39,7 +37,7 @@ class DeleteReplyAjaxPageTest : JsonPageTest("deleteReply.ajax", pageSupplier =
                whenever(reply.sone).thenReturn(sone)
                addReply(reply, "reply-id")
                addRequestParameter("reply", "reply-id")
-               assertThat(json.isSuccess, equalTo(true))
+               assertThatJsonIsSuccessful()
                verify(core).deleteReply(reply)
        }
 
index a10c51c..ff603d2 100644 (file)
@@ -15,8 +15,7 @@ class DismissNotificationAjaxPageTest : JsonPageTest("dismissNotification.ajax",
 
        @Test
        fun `request without notification returns invalid-notification-id`() {
-               assertThat(json.isSuccess, equalTo(false))
-               assertThat(json.error, equalTo("invalid-notification-id"))
+               assertThatJsonFailed("invalid-notification-id")
        }
 
        @Test
@@ -24,8 +23,7 @@ class DismissNotificationAjaxPageTest : JsonPageTest("dismissNotification.ajax",
                val notification = mock<Notification>()
                addNotification(notification, "foo")
                addRequestParameter("notification", "foo")
-               assertThat(json.isSuccess, equalTo(false))
-               assertThat(json.error, equalTo("not-dismissable"))
+               assertThatJsonFailed("not-dismissable")
        }
 
        @Test
@@ -33,7 +31,7 @@ class DismissNotificationAjaxPageTest : JsonPageTest("dismissNotification.ajax",
                val notification = mock<Notification>().apply { whenever(isDismissable).thenReturn(true) }
                addNotification(notification, "foo")
                addRequestParameter("notification", "foo")
-               assertThat(json.isSuccess, equalTo(true))
+               assertThatJsonIsSuccessful()
                verify(notification).dismiss()
        }
 
index dbe2ed5..78930e5 100644 (file)
@@ -14,15 +14,13 @@ class DistrustAjaxPageTest : JsonPageTest("distrustSone.ajax", pageSupplier = ::
 
        @Test
        fun `request with missing sone results in invalid-sone-id`() {
-               assertThat(json.isSuccess, equalTo(false))
-               assertThat(json.error, equalTo("invalid-sone-id"))
+               assertThatJsonFailed("invalid-sone-id")
        }
 
        @Test
        fun `request with invalid sone results in invalid-sone-id`() {
                addRequestParameter("sone", "invalid-sone")
-               assertThat(json.isSuccess, equalTo(false))
-               assertThat(json.error, equalTo("invalid-sone-id"))
+               assertThatJsonFailed("invalid-sone-id")
        }
 
        @Test
@@ -30,7 +28,7 @@ class DistrustAjaxPageTest : JsonPageTest("distrustSone.ajax", pageSupplier = ::
                val sone = mock<Sone>()
                addSone(sone, "sone-id")
                addRequestParameter("sone", "sone-id")
-               assertThat(json.isSuccess, equalTo(true))
+               assertThatJsonIsSuccessful()
                verify(core).distrustSone(currentSone, sone)
        }
 
@@ -40,7 +38,7 @@ class DistrustAjaxPageTest : JsonPageTest("distrustSone.ajax", pageSupplier = ::
                val sone = mock<Sone>()
                addSone(sone, "sone-id")
                addRequestParameter("sone", "sone-id")
-               assertThat(json.isSuccess, equalTo(true))
+               assertThatJsonIsSuccessful()
                assertThat(json["trustValue"]?.asInt(), equalTo(-33))
        }
 
index d540344..098185b 100644 (file)
@@ -22,8 +22,7 @@ class EditAlbumAjaxPageTest : JsonPageTest("editAlbum.ajax", pageSupplier = ::Ed
 
        @Test
        fun `request without album results in invalid-album-id`() {
-               assertThat(json.isSuccess, equalTo(false))
-               assertThat(json.error, equalTo("invalid-album-id"))
+               assertThatJsonFailed("invalid-album-id")
        }
 
        @Test
@@ -31,8 +30,7 @@ class EditAlbumAjaxPageTest : JsonPageTest("editAlbum.ajax", pageSupplier = ::Ed
                whenever(album.sone).thenReturn(sone)
                addAlbum(album)
                addRequestParameter("album", "album-id")
-               assertThat(json.isSuccess, equalTo(false))
-               assertThat(json.error, equalTo("not-authorized"))
+               assertThatJsonFailed("not-authorized")
        }
 
        @Test
@@ -45,7 +43,7 @@ class EditAlbumAjaxPageTest : JsonPageTest("editAlbum.ajax", pageSupplier = ::Ed
                addAlbum(album)
                addRequestParameter("album", "album-id")
                addRequestParameter("moveLeft", "true")
-               assertThat(json.isSuccess, equalTo(true))
+               assertThatJsonIsSuccessful()
                assertThat(json["sourceAlbumId"]?.asText(), equalTo("album-id"))
                assertThat(json["destinationAlbumId"]?.asText(), equalTo("swapped"))
        }
@@ -60,7 +58,7 @@ class EditAlbumAjaxPageTest : JsonPageTest("editAlbum.ajax", pageSupplier = ::Ed
                addAlbum(album)
                addRequestParameter("album", "album-id")
                addRequestParameter("moveRight", "true")
-               assertThat(json.isSuccess, equalTo(true))
+               assertThatJsonIsSuccessful()
                assertThat(json["sourceAlbumId"]?.asText(), equalTo("album-id"))
                assertThat(json["destinationAlbumId"]?.asText(), equalTo("swapped"))
        }
@@ -72,8 +70,7 @@ class EditAlbumAjaxPageTest : JsonPageTest("editAlbum.ajax", pageSupplier = ::Ed
                whenever(album.modify().setTitle("")).thenThrow(AlbumTitleMustNotBeEmpty::class.java)
                addAlbum(album)
                addRequestParameter("album", "album-id")
-               assertThat(json.isSuccess, equalTo(false))
-               assertThat(json.error, equalTo("invalid-album-title"))
+               assertThatJsonFailed("invalid-album-title")
        }
 
        @Test
@@ -84,7 +81,7 @@ class EditAlbumAjaxPageTest : JsonPageTest("editAlbum.ajax", pageSupplier = ::Ed
                addRequestParameter("title", "new title")
                addRequestParameter("description", "foo http://127.0.0.1:8888/KSK@foo.html link")
                addRequestHeader("Host", "127.0.0.1:8888")
-               assertThat(json.isSuccess, equalTo(true))
+               assertThatJsonIsSuccessful()
                assertThat(json["albumId"]?.asText(), equalTo("album-id"))
                assertThat(json["title"]?.asText(), equalTo("new title"))
                assertThat(json["description"]?.asText(), equalTo("foo KSK@foo.html link"))
index 126fa83..dad6c02 100644 (file)
@@ -29,8 +29,7 @@ class EditImageAjaxPageTest : JsonPageTest("editImage.ajax") {
 
        @Test
        fun `request without image results in invalid-image-id`() {
-               assertThat(json.isSuccess, equalTo(false))
-               assertThat(json.error, equalTo("invalid-image-id"))
+               assertThatJsonFailed("invalid-image-id")
        }
 
        @Test
@@ -40,8 +39,7 @@ class EditImageAjaxPageTest : JsonPageTest("editImage.ajax") {
                whenever(image.sone).thenReturn(sone)
                addImage(image, "image-id")
                addRequestParameter("image", "image-id")
-               assertThat(json.isSuccess, equalTo(false))
-               assertThat(json.error, equalTo("not-authorized"))
+               assertThatJsonFailed("not-authorized")
        }
 
        @Test
@@ -56,7 +54,7 @@ class EditImageAjaxPageTest : JsonPageTest("editImage.ajax") {
                addImage(image)
                addRequestParameter("image", "image-id")
                addRequestParameter("moveLeft", "true")
-               assertThat(json.isSuccess, equalTo(true))
+               assertThatJsonIsSuccessful()
                assertThat(json["sourceImageId"]?.asText(), equalTo("image-id"))
                assertThat(json["destinationImageId"]?.asText(), equalTo("swapped"))
                verify(core).touchConfiguration()
@@ -74,7 +72,7 @@ class EditImageAjaxPageTest : JsonPageTest("editImage.ajax") {
                addImage(image)
                addRequestParameter("image", "image-id")
                addRequestParameter("moveRight", "true")
-               assertThat(json.isSuccess, equalTo(true))
+               assertThatJsonIsSuccessful()
                assertThat(json["sourceImageId"]?.asText(), equalTo("image-id"))
                assertThat(json["destinationImageId"]?.asText(), equalTo("swapped"))
                verify(core).touchConfiguration()
@@ -87,8 +85,7 @@ class EditImageAjaxPageTest : JsonPageTest("editImage.ajax") {
                whenever(image.sone).thenReturn(sone)
                addImage(image)
                addRequestParameter("image", "image-id")
-               assertThat(json.isSuccess, equalTo(false))
-               assertThat(json.error, equalTo("invalid-image-title"))
+               assertThatJsonFailed("invalid-image-title")
        }
 
        @Test
@@ -106,7 +103,7 @@ class EditImageAjaxPageTest : JsonPageTest("editImage.ajax") {
                addRequestParameter("title", "some title")
                addRequestParameter("description", "some http://127.0.0.1:8888/KSK@foo link")
                addRequestHeader("Host", "127.0.0.1:8888")
-               assertThat(json.isSuccess, equalTo(true))
+               assertThatJsonIsSuccessful()
                assertThat(json["title"]?.asText(), equalTo("some title"))
                assertThat(json["description"]?.asText(), equalTo("some KSK@foo link"))
                assertThat(json["parsedDescription"]?.asText(), equalTo("rendered description"))
index 5116090..7eed9ac 100644 (file)
@@ -12,8 +12,7 @@ class EditProfileFieldAjaxPageTest : JsonPageTest("editProfileField.ajax", pageS
 
        @Test
        fun `request without field id results in invalid-field-id`() {
-               assertThat(json.isSuccess, equalTo(false))
-               assertThat(json.error, equalTo("invalid-field-id"))
+               assertThatJsonFailed("invalid-field-id")
        }
 
        @Test
@@ -21,8 +20,7 @@ class EditProfileFieldAjaxPageTest : JsonPageTest("editProfileField.ajax", pageS
                val field = currentSone.profile.addField("test-field")
                addRequestParameter("field", field.id)
                addRequestParameter("name", "  \t ")
-               assertThat(json.isSuccess, equalTo(false))
-               assertThat(json.error, equalTo("invalid-parameter-name"))
+               assertThatJsonFailed("invalid-parameter-name")
        }
 
        @Test
@@ -31,8 +29,7 @@ class EditProfileFieldAjaxPageTest : JsonPageTest("editProfileField.ajax", pageS
                val field = currentSone.profile.addField("test-field")
                addRequestParameter("field", field.id)
                addRequestParameter("name", "other-field")
-               assertThat(json.isSuccess, equalTo(false))
-               assertThat(json.error, equalTo("duplicate-field-name"))
+               assertThatJsonFailed("duplicate-field-name")
        }
 
        @Test
@@ -41,7 +38,7 @@ class EditProfileFieldAjaxPageTest : JsonPageTest("editProfileField.ajax", pageS
                val field = profile.addField("test-field")
                addRequestParameter("field", field.id)
                addRequestParameter("name", "  new name ")
-               assertThat(json.isSuccess, equalTo(true))
+               assertThatJsonIsSuccessful()
                assertThat(field.name, equalTo("new name"))
                verify(currentSone).profile = profile
        }
index 1b40f98..c649e75 100644 (file)
@@ -15,15 +15,14 @@ class FollowSoneAjaxPageTest : JsonPageTest("followSone.ajax", pageSupplier = ::
 
        @Test
        fun `request without sone id results in invalid-sone-id`() {
-               assertThat(json.isSuccess, equalTo(false))
-               assertThat(json.error, equalTo("invalid-sone-id"))
+               assertThatJsonFailed("invalid-sone-id")
        }
 
        @Test
        fun `request with sone follows sone`() {
                addSone(mock<Sone>().apply { whenever(id).thenReturn("sone-id") })
                addRequestParameter("sone", "sone-id")
-               assertThat(json.isSuccess, equalTo(true))
+               assertThatJsonIsSuccessful()
                verify(core).followSone(currentSone, "sone-id")
        }
 
@@ -32,7 +31,7 @@ class FollowSoneAjaxPageTest : JsonPageTest("followSone.ajax", pageSupplier = ::
                val sone = mock<Sone>()
                addSone(sone, "sone-id")
                addRequestParameter("sone", "sone-id")
-               assertThat(json.isSuccess, equalTo(true))
+               assertThatJsonIsSuccessful()
                verify(core).markSoneKnown(sone)
        }
 
index 1b1255e..3a75ded 100644 (file)
@@ -25,15 +25,13 @@ class GetLikesAjaxPageTest : JsonPageTest("getLikes.ajax", needsFormPassword = f
        fun `request with invalid post id results in invalid-post-id`() {
                addRequestParameter("type", "post")
                addRequestParameter("post", "invalid")
-               assertThat(json.isSuccess, equalTo(false))
-               assertThat(json.error, equalTo("invalid-post-id"))
+               assertThatJsonFailed("invalid-post-id")
        }
 
        @Test
        fun `request with missing post id results in invalid-post-id`() {
                addRequestParameter("type", "post")
-               assertThat(json.isSuccess, equalTo(false))
-               assertThat(json.error, equalTo("invalid-post-id"))
+               assertThatJsonFailed("invalid-post-id")
        }
 
        @Test
@@ -43,7 +41,7 @@ class GetLikesAjaxPageTest : JsonPageTest("getLikes.ajax", needsFormPassword = f
                addLikes(post, createSone(2), createSone(1), createSone(3))
                addRequestParameter("type", "post")
                addRequestParameter("post", "post-id")
-               assertThat(json.isSuccess, equalTo(true))
+               assertThatJsonIsSuccessful()
                assertThat(json["likes"]?.asInt(), equalTo(3))
                assertThat(json["sones"]!!.toList().map { it["id"].asText() to it["name"].asText() }, contains(
                                "S1" to "F1 M1 L1",
@@ -56,15 +54,13 @@ class GetLikesAjaxPageTest : JsonPageTest("getLikes.ajax", needsFormPassword = f
        fun `request with invalid reply id results in invalid-reply-id`() {
                addRequestParameter("type", "reply")
                addRequestParameter("reply", "invalid")
-               assertThat(json.isSuccess, equalTo(false))
-               assertThat(json.error, equalTo("invalid-reply-id"))
+               assertThatJsonFailed("invalid-reply-id")
        }
 
        @Test
        fun `request with missing reply id results in invalid-reply-id`() {
                addRequestParameter("type", "reply")
-               assertThat(json.isSuccess, equalTo(false))
-               assertThat(json.error, equalTo("invalid-reply-id"))
+               assertThatJsonFailed("invalid-reply-id")
        }
 
        @Test
@@ -74,7 +70,7 @@ class GetLikesAjaxPageTest : JsonPageTest("getLikes.ajax", needsFormPassword = f
                addLikes(reply, createSone(2), createSone(1), createSone(3))
                addRequestParameter("type", "reply")
                addRequestParameter("reply", "reply-id")
-               assertThat(json.isSuccess, equalTo(true))
+               assertThatJsonIsSuccessful()
                assertThat(json["likes"]?.asInt(), equalTo(3))
                assertThat(json["sones"]!!.toList().map { it["id"].asText() to it["name"].asText() }, contains(
                                "S1" to "F1 M1 L1",
@@ -87,8 +83,7 @@ class GetLikesAjaxPageTest : JsonPageTest("getLikes.ajax", needsFormPassword = f
        fun `request with invalid type results in invalid-type`() {
                addRequestParameter("type", "invalid")
                addRequestParameter("invalid", "foo")
-               assertThat(json.isSuccess, equalTo(false))
-               assertThat(json.error, equalTo("invalid-type"))
+               assertThatJsonFailed("invalid-type")
        }
 
 }
index f2206e3..8084b65 100644 (file)
@@ -43,13 +43,13 @@ class GetNotificationsAjaxPageTest : JsonPageTest("getNotifications.ajax", requi
        @Test
        fun `notification hash is calculated correctly`() {
                testNotifications.forEach { addNotification(it) }
-               assertThat(json.isSuccess, equalTo(true))
+               assertThatJsonIsSuccessful()
                assertThat(json["notificationHash"]?.asInt(), equalTo(listOf(1, 0, 2).map(testNotifications::get).hashCode()))
        }
 
        @Test
        fun `options are included correctly`() {
-               assertThat(json.isSuccess, equalTo(true))
+               assertThatJsonIsSuccessful()
                assertThat(json["options"]!!["ShowNotification/NewSones"].asBoolean(), equalTo(true))
                assertThat(json["options"]!!["ShowNotification/NewPosts"].asBoolean(), equalTo(true))
                assertThat(json["options"]!!["ShowNotification/NewReplies"].asBoolean(), equalTo(true))
@@ -60,7 +60,7 @@ class GetNotificationsAjaxPageTest : JsonPageTest("getNotifications.ajax", requi
                currentSone.options.isShowNewSoneNotifications = false
                currentSone.options.isShowNewPostNotifications = false
                currentSone.options.isShowNewReplyNotifications = false
-               assertThat(json.isSuccess, equalTo(true))
+               assertThatJsonIsSuccessful()
                assertThat(json["options"]!!["ShowNotification/NewSones"].asBoolean(), equalTo(false))
                assertThat(json["options"]!!["ShowNotification/NewPosts"].asBoolean(), equalTo(false))
                assertThat(json["options"]!!["ShowNotification/NewReplies"].asBoolean(), equalTo(false))
@@ -69,14 +69,14 @@ class GetNotificationsAjaxPageTest : JsonPageTest("getNotifications.ajax", requi
        @Test
        fun `options are not included if user is not logged in`() {
                unsetCurrentSone()
-               assertThat(json.isSuccess, equalTo(true))
+               assertThatJsonIsSuccessful()
                assertThat(json["options"]?.toList(), empty())
        }
 
        @Test
        fun `notifications are rendered correctly`() {
                testNotifications.forEach { addNotification(it) }
-               assertThat(json.isSuccess, equalTo(true))
+               assertThatJsonIsSuccessful()
                assertThat(json["notifications"]!!.toList().map { node -> listOf("id", "text", "createdTime", "lastUpdatedTime", "dismissable").map { it to node.get(it).asText() }.toMap() }, containsInAnyOrder(
                                mapOf("id" to "n1", "createdTime" to "2000", "lastUpdatedTime" to "5000", "dismissable" to "true", "text" to "t1"),
                                mapOf("id" to "n2", "createdTime" to "1000", "lastUpdatedTime" to "6000", "dismissable" to "false", "text" to "t2"),
@@ -99,7 +99,7 @@ class GetNotificationsAjaxPageTest : JsonPageTest("getNotifications.ajax", requi
                }
                testNotifications.forEach { addNotification(it) }
                addNotification(templateNotification)
-               assertThat(json.isSuccess, equalTo(true))
+               assertThatJsonIsSuccessful()
                assertThat(json["notifications"]!!.last()["text"].asText(), equalTo("t4"))
                val templateContext = argumentCaptor<TemplateContext>()
                verify(templateNotification).render(templateContext.capture(), any())
index e729b24..8d33542 100644 (file)
@@ -21,8 +21,7 @@ class GetPostAjaxPageTest : JsonPageTest("getPost.ajax", needsFormPassword = fal
 
        @Test
        fun `request with missing post results in invalid-post-id`() {
-               assertThat(json.isSuccess, equalTo(false))
-               assertThat(json.error, equalTo("invalid-post-id"))
+               assertThatJsonFailed("invalid-post-id")
        }
 
        @Test
@@ -38,7 +37,7 @@ class GetPostAjaxPageTest : JsonPageTest("getPost.ajax", needsFormPassword = fal
                webInterface.templateContextFactory.addAccessor(Any::class.java, ReflectionAccessor())
                addPost(post)
                addRequestParameter("post", "post-id")
-               assertThat(json.isSuccess, equalTo(true))
+               assertThatJsonIsSuccessful()
                assertThat(json["post"]!!["id"].asText(), equalTo("post-id"))
                assertThat(json["post"]!!["time"].asLong(), equalTo(1000L))
                assertThat(json["post"]!!["sone"].asText(), equalTo("sone-id"))
index 17792e2..6af8776 100644 (file)
@@ -20,8 +20,7 @@ class GetReplyAjaxPageTest : JsonPageTest("getReply.ajax", needsFormPassword = f
 
        @Test
        fun `request without reply id results in invalid-reply-id`() {
-               assertThat(json.isSuccess, equalTo(false))
-               assertThat(json.error, equalTo("invalid-reply-id"))
+               assertThatJsonFailed("invalid-reply-id")
        }
 
        @Test
@@ -37,7 +36,7 @@ class GetReplyAjaxPageTest : JsonPageTest("getReply.ajax", needsFormPassword = f
                webInterface.templateContextFactory.addAccessor(Any::class.java, ReflectionAccessor())
                addReply(reply)
                addRequestParameter("reply", "reply-id")
-               assertThat(json.isSuccess, equalTo(true))
+               assertThatJsonIsSuccessful()
                assertThat(json["reply"]!!["id"].asText(), equalTo("reply-id"))
                assertThat(json["reply"]!!["soneId"].asText(), equalTo("sone-id"))
                assertThat(json["reply"]!!["postId"].asText(), equalTo("post-id"))
index fa86867..fff438b 100644 (file)
@@ -54,7 +54,7 @@ class GetTimesAjaxPageTest : JsonPageTest("getTimes.ajax", needsFormPassword = f
 
        @Test
        fun `request without any parameters responds with empty post and reply times`() {
-               assertThat(json.isSuccess, equalTo(true))
+               assertThatJsonIsSuccessful()
                assertThat(json["postTimes"]?.toList(), emptyIterable())
                assertThat(json["replyTimes"]?.toList(), emptyIterable())
        }
@@ -63,7 +63,7 @@ class GetTimesAjaxPageTest : JsonPageTest("getTimes.ajax", needsFormPassword = f
        fun `request with single post parameter responds with post times and empty reply times`() {
                addPost(testPosts[0])
                addRequestParameter("posts", "post1")
-               assertThat(json.isSuccess, equalTo(true))
+               assertThatJsonIsSuccessful()
                assertThat(json["postTimes"]!!.fields().asSequence().map { it.key to it.value }.toList(), containsInAnyOrder<Pair<String, JsonNode>>(
                                "post1" to jsonObject("timeText" to "1000", "refreshTime" to 2L, "tooltip" to "Jan 1, 1970, 00:00:01")
                ))
@@ -74,7 +74,7 @@ class GetTimesAjaxPageTest : JsonPageTest("getTimes.ajax", needsFormPassword = f
        fun `request with single reply parameter responds with reply times and empty post times`() {
                addReply(testReplies[0])
                addRequestParameter("replies", "reply1")
-               assertThat(json.isSuccess, equalTo(true))
+               assertThatJsonIsSuccessful()
                assertThat(json["postTimes"]?.toList(), emptyIterable())
                assertThat(json["replyTimes"]!!.fields().asSequence().map { it.key to it.value }.toList(), containsInAnyOrder<Pair<String, JsonNode>>(
                                "reply1" to jsonObject("timeText" to "1000", "refreshTime" to 2L, "tooltip" to "Jan 1, 1970, 00:00:01")
@@ -86,7 +86,7 @@ class GetTimesAjaxPageTest : JsonPageTest("getTimes.ajax", needsFormPassword = f
                addPost(testPosts[0])
                addPost(testPosts[1])
                addRequestParameter("posts", "post1,post2,post3")
-               assertThat(json.isSuccess, equalTo(true))
+               assertThatJsonIsSuccessful()
                assertThat(json["postTimes"]!!.fields().asSequence().map { it.key to it.value }.toList(), containsInAnyOrder<Pair<String, JsonNode>>(
                                "post1" to jsonObject("timeText" to "1000", "refreshTime" to 2L, "tooltip" to "Jan 1, 1970, 00:00:01"),
                                "post2" to jsonObject("timeText" to "2000", "refreshTime" to 4L, "tooltip" to "Jan 1, 1970, 00:00:02")
@@ -99,7 +99,7 @@ class GetTimesAjaxPageTest : JsonPageTest("getTimes.ajax", needsFormPassword = f
                addReply(testReplies[0])
                addReply(testReplies[1])
                addRequestParameter("replies", "reply1,reply2,reply3")
-               assertThat(json.isSuccess, equalTo(true))
+               assertThatJsonIsSuccessful()
                assertThat(json["postTimes"]?.toList(), emptyIterable())
                assertThat(json["replyTimes"]!!.fields().asSequence().map { it.key to it.value }.toList(), containsInAnyOrder<Pair<String, JsonNode>>(
                                "reply1" to jsonObject("timeText" to "1000", "refreshTime" to 2L, "tooltip" to "Jan 1, 1970, 00:00:01"),
index 87ea2c6..0d58ca2 100644 (file)
@@ -13,7 +13,7 @@ class GetTranslationAjaxPageTest : JsonPageTest("getTranslation.ajax", requiresL
        fun `translation is returned correctly`() {
                addTranslation("foo", "bar")
                addRequestParameter("key", "foo")
-               assertThat(json.isSuccess, equalTo(true))
+               assertThatJsonIsSuccessful()
                assertThat(json["value"]?.asText(), equalTo("bar"))
        }
 
index e5621f0..84fca49 100644 (file)
@@ -13,14 +13,23 @@ abstract class JsonPageTest(
                private val expectedPath: String,
                private val requiresLogin: Boolean = true,
                private val needsFormPassword: Boolean = true,
-               pageSupplier: (WebInterface) -> JsonPage = { mock() }): TestObjects() {
+               pageSupplier: (WebInterface) -> JsonPage = { mock() }) : TestObjects() {
 
        protected open val page: JsonPage by lazy { pageSupplier(webInterface) }
        protected val json by lazy {
                page.createJsonObject(freenetRequest)
        }
 
-       protected val JsonReturnObject.error get() = if (this is JsonErrorReturnObject) this.error else null
+       private val JsonReturnObject.error get() = if (this is JsonErrorReturnObject) this.error else null
+
+       protected fun assertThatJsonIsSuccessful() {
+               assertThat(json.isSuccess, equalTo(true))
+       }
+
+       protected fun assertThatJsonFailed(error: String? = null) {
+               assertThat(json.isSuccess, equalTo(false))
+               error?.run { assertThat(json.error, equalTo(this)) }
+       }
 
        @Test
        fun `page returns correct path`() {
index 9a8f2c2..457aac4 100644 (file)
@@ -19,8 +19,7 @@ class LikeAjaxPageTest : JsonPageTest("like.ajax", pageSupplier = ::LikeAjaxPage
        fun `request with invalid type results in invalid-type error`() {
                addRequestParameter("type", "invalid")
                addRequestParameter("invalid", "invalid-id")
-               assertThat(json.isSuccess, equalTo(false))
-               assertThat(json.error, equalTo("invalid-type"))
+               assertThatJsonFailed("invalid-type")
        }
 
        @Test
@@ -28,7 +27,7 @@ class LikeAjaxPageTest : JsonPageTest("like.ajax", pageSupplier = ::LikeAjaxPage
                addRequestParameter("type", "post")
                addRequestParameter("post", "post-id")
                addPost(mock<Post>().apply { whenever(id).thenReturn("post-id") })
-               assertThat(json.isSuccess, equalTo(true))
+               assertThatJsonIsSuccessful()
                verify(currentSone).addLikedPostId("post-id")
                verify(core).touchConfiguration()
        }
@@ -38,7 +37,7 @@ class LikeAjaxPageTest : JsonPageTest("like.ajax", pageSupplier = ::LikeAjaxPage
                addRequestParameter("type", "reply")
                addRequestParameter("reply", "reply-id")
                addReply(mock<PostReply>().apply { whenever(id).thenReturn("reply-id") })
-               assertThat(json.isSuccess, equalTo(true))
+               assertThatJsonIsSuccessful()
                verify(currentSone).addLikedReplyId("reply-id")
                verify(core).touchConfiguration()
        }
index 61a0c40..3a2a524 100644 (file)
@@ -14,8 +14,7 @@ class LockSoneAjaxPageTest : JsonPageTest("lockSone.ajax", requiresLogin = false
 
        @Test
        fun `request without valid sone results in invalid-sone-id`() {
-               assertThat(json.isSuccess, equalTo(false))
-               assertThat(json.error, equalTo("invalid-sone-id"))
+               assertThatJsonFailed("invalid-sone-id")
        }
 
        @Test
@@ -23,7 +22,7 @@ class LockSoneAjaxPageTest : JsonPageTest("lockSone.ajax", requiresLogin = false
                val sone = mock<Sone>()
                addLocalSone(sone, "sone-id")
                addRequestParameter("sone", "sone-id")
-               assertThat(json.isSuccess, equalTo(true))
+               assertThatJsonIsSuccessful()
                verify(core).lockSone(sone)
        }
 
index c867c96..a3ab0ff 100644 (file)
@@ -19,15 +19,14 @@ class MarkAsKnownAjaxPageTest : JsonPageTest("markAsKnown.ajax", requiresLogin =
 
        @Test
        fun `request without type results in invalid-type`() {
-               assertThat(json.isSuccess, equalTo(false))
-               assertThat(json.error, equalTo("invalid-type"))
+               assertThatJsonFailed("invalid-type")
        }
 
        @Test
        fun `request with unknown sone returns successfully`() {
                addRequestParameter("type", "sone")
                addRequestParameter("id", "invalid")
-               assertThat(json.isSuccess, equalTo(true))
+               assertThatJsonIsSuccessful()
                verify(core, never()).markSoneKnown(any())
        }
 
@@ -39,7 +38,7 @@ class MarkAsKnownAjaxPageTest : JsonPageTest("markAsKnown.ajax", requiresLogin =
                val sone2 = mock<Sone>().apply { whenever(id).thenReturn("sone-id2") }
                addSone(sone1)
                addSone(sone2)
-               assertThat(json.isSuccess, equalTo(true))
+               assertThatJsonIsSuccessful()
                verify(core).markSoneKnown(sone1)
                verify(core).markSoneKnown(sone2)
        }
@@ -52,7 +51,7 @@ class MarkAsKnownAjaxPageTest : JsonPageTest("markAsKnown.ajax", requiresLogin =
                val post2 = mock<Post>()
                addPost(post1, "post1")
                addPost(post2, "post2")
-               assertThat(json.isSuccess, equalTo(true))
+               assertThatJsonIsSuccessful()
                verify(core).markPostKnown(post1)
                verify(core).markPostKnown(post2)
        }
@@ -65,7 +64,7 @@ class MarkAsKnownAjaxPageTest : JsonPageTest("markAsKnown.ajax", requiresLogin =
                val reply2 = mock<PostReply>()
                addReply(reply1, "reply1")
                addReply(reply2, "reply2")
-               assertThat(json.isSuccess, equalTo(true))
+               assertThatJsonIsSuccessful()
                verify(core).markReplyKnown(reply1)
                verify(core).markReplyKnown(reply2)
        }
index 7524eaa..aab1bbe 100644 (file)
@@ -12,16 +12,14 @@ class MoveProfileFieldAjaxPageTest : JsonPageTest("moveProfileField.ajax", true,
 
        @Test
        fun `request without field id results in invalid-field-id`() {
-               assertThat(json.isSuccess, equalTo(false))
-               assertThat(json.error, equalTo("invalid-field-id"))
+               assertThatJsonFailed("invalid-field-id")
        }
 
        @Test
        fun `request with invalid direction results in invalid-direction`() {
                val fieldId = profile.addField("someField").id
                addRequestParameter("field", fieldId)
-               assertThat(json.isSuccess, equalTo(false))
-               assertThat(json.error, equalTo("invalid-direction"))
+               assertThatJsonFailed("invalid-direction")
        }
 
        @Test
@@ -29,8 +27,7 @@ class MoveProfileFieldAjaxPageTest : JsonPageTest("moveProfileField.ajax", true,
                val fieldId = profile.addField("someField").id
                addRequestParameter("field", fieldId)
                addRequestParameter("direction", "up")
-               assertThat(json.isSuccess, equalTo(false))
-               assertThat(json.error, equalTo("not-possible"))
+               assertThatJsonFailed("not-possible")
        }
 
        @Test
@@ -38,8 +35,7 @@ class MoveProfileFieldAjaxPageTest : JsonPageTest("moveProfileField.ajax", true,
                val fieldId = profile.addField("someField").id
                addRequestParameter("field", fieldId)
                addRequestParameter("direction", "down")
-               assertThat(json.isSuccess, equalTo(false))
-               assertThat(json.error, equalTo("not-possible"))
+               assertThatJsonFailed("not-possible")
        }
 
        @Test
@@ -48,7 +44,7 @@ class MoveProfileFieldAjaxPageTest : JsonPageTest("moveProfileField.ajax", true,
                val fieldId = profile.addField("someField").id
                addRequestParameter("field", fieldId)
                addRequestParameter("direction", "up")
-               assertThat(json.isSuccess, equalTo(true))
+               assertThatJsonIsSuccessful()
                assertThat(profile.fields[0].id, equalTo(fieldId))
                verify(core).touchConfiguration()
                verify(currentSone).profile = profile
@@ -60,7 +56,7 @@ class MoveProfileFieldAjaxPageTest : JsonPageTest("moveProfileField.ajax", true,
                profile.addField("firstField")
                addRequestParameter("field", fieldId)
                addRequestParameter("direction", "down")
-               assertThat(json.isSuccess, equalTo(true))
+               assertThatJsonIsSuccessful()
                assertThat(profile.fields.last().id, equalTo(fieldId))
                verify(core).touchConfiguration()
                verify(currentSone).profile = profile
index 7fc726a..64a66a3 100644 (file)
@@ -16,15 +16,14 @@ class TrustAjaxPageTest : JsonPageTest("trustSone.ajax", requiresLogin = true, n
 
        @Test
        fun `request with invalid sone results in invalid-sone-id`() {
-               assertThat(json.isSuccess, equalTo(false))
-               assertThat(json.error, equalTo("invalid-sone-id"))
+               assertThatJsonFailed("invalid-sone-id")
        }
 
        @Test
        fun `request with valid sone trust sone`() {
                addSone(sone, "sone-id")
                addRequestParameter("sone", "sone-id")
-               assertThat(json.isSuccess, equalTo(true))
+               assertThatJsonIsSuccessful()
                verify(core).trustSone(currentSone, sone)
        }
 
@@ -33,7 +32,7 @@ class TrustAjaxPageTest : JsonPageTest("trustSone.ajax", requiresLogin = true, n
                addSone(sone, "sone-id")
                addRequestParameter("sone", "sone-id")
                core.preferences.positiveTrust = 31
-               assertThat(json.isSuccess, equalTo(true))
+               assertThatJsonIsSuccessful()
                assertThat(json["trustValue"]?.asInt(), equalTo(31))
        }
 
index 23ebd9f..65c5beb 100644 (file)
@@ -17,15 +17,13 @@ class UnbookmarkAjaxPageTest : JsonPageTest("unbookmark.ajax", requiresLogin = f
 
        @Test
        fun `request without post id results in invalid-post-id`() {
-               assertThat(json.isSuccess, equalTo(false))
-               assertThat(json.error, equalTo("invalid-post-id"))
+               assertThatJsonFailed("invalid-post-id")
        }
 
        @Test
        fun `request with empty post id results in invalid-post-id`() {
                addRequestParameter("post", "")
-               assertThat(json.isSuccess, equalTo(false))
-               assertThat(json.error, equalTo("invalid-post-id"))
+               assertThatJsonFailed("invalid-post-id")
        }
 
        @Test
@@ -40,7 +38,7 @@ class UnbookmarkAjaxPageTest : JsonPageTest("unbookmark.ajax", requiresLogin = f
                val post = mock<Post>()
                addPost(post, "post-id")
                addRequestParameter("post", "post-id")
-               assertThat(json.isSuccess, equalTo(true))
+               assertThatJsonIsSuccessful()
                verify(core).unbookmarkPost(eq(post))
        }
 
index 99b7298..e4b53fd 100644 (file)
@@ -13,22 +13,20 @@ class UnfollowSoneAjaxPageTest : JsonPageTest("unfollowSone.ajax", pageSupplier
 
        @Test
        fun `request without sone returns invalid-sone-id`() {
-               assertThat(json.isSuccess, equalTo(false))
-               assertThat(json.error, equalTo("invalid-sone-id"))
+               assertThatJsonFailed("invalid-sone-id")
        }
 
        @Test
        fun `request with invalid sone returns invalid-sone-id`() {
                addRequestParameter("sone", "invalid")
-               assertThat(json.isSuccess, equalTo(false))
-               assertThat(json.error, equalTo("invalid-sone-id"))
+               assertThatJsonFailed("invalid-sone-id")
        }
 
        @Test
        fun `request with valid sone unfollows sone`() {
                addSone(mock(), "sone-id")
                addRequestParameter("sone", "sone-id")
-               assertThat(json.isSuccess, equalTo(true))
+               assertThatJsonIsSuccessful()
                verify(core).unfollowSone(currentSone, "sone-id")
        }
 
index ada19ba..4661892 100644 (file)
@@ -18,23 +18,21 @@ class UnlikeAjaxPageTest : JsonPageTest("unlike.ajax", pageSupplier = ::UnlikeAj
        @Test
        fun `request for post without id results in invalid-post-id`() {
                addRequestParameter("type", "post")
-               assertThat(json.isSuccess, equalTo(false))
-               assertThat(json.error, equalTo("invalid-post-id"))
+               assertThatJsonFailed("invalid-post-id")
        }
 
        @Test
        fun `request for invalid type results in invalid-type`() {
                addRequestParameter("type", "invalid")
                addRequestParameter("invalid", "invalid")
-               assertThat(json.isSuccess, equalTo(false))
-               assertThat(json.error, equalTo("invalid-type"))
+               assertThatJsonFailed("invalid-type")
        }
 
        @Test
        fun `request for post with id removes id from liked posts`() {
                addRequestParameter("type", "post")
                addRequestParameter("post", "post-id")
-               assertThat(json.isSuccess, equalTo(true))
+               assertThatJsonIsSuccessful()
                verify(currentSone).removeLikedPostId("post-id")
                verify(core).touchConfiguration()
        }
@@ -42,15 +40,14 @@ class UnlikeAjaxPageTest : JsonPageTest("unlike.ajax", pageSupplier = ::UnlikeAj
        @Test
        fun `request for reply without id results in invalid-reply-id`() {
                addRequestParameter("type", "reply")
-               assertThat(json.isSuccess, equalTo(false))
-               assertThat(json.error, equalTo("invalid-reply-id"))
+               assertThatJsonFailed("invalid-reply-id")
        }
 
        @Test
        fun `request for reply with id removes id from liked replys`() {
                addRequestParameter("type", "reply")
                addRequestParameter("reply", "reply-id")
-               assertThat(json.isSuccess, equalTo(true))
+               assertThatJsonIsSuccessful()
                verify(currentSone).removeLikedReplyId("reply-id")
                verify(core).touchConfiguration()
        }
index 1fd1df7..81a54e3 100644 (file)
@@ -14,15 +14,13 @@ class UnlockSoneAjaxPageTest : JsonPageTest("unlockSone.ajax", requiresLogin = f
 
        @Test
        fun `request without sone results in invalid-sone-id`() {
-               assertThat(json.isSuccess, equalTo(false))
-               assertThat(json.error, equalTo("invalid-sone-id"))
+               assertThatJsonFailed("invalid-sone-id")
        }
 
        @Test
        fun `request with invalid sone results in invalid-sone-id`() {
                addRequestParameter("sone", "invalid")
-               assertThat(json.isSuccess, equalTo(false))
-               assertThat(json.error, equalTo("invalid-sone-id"))
+               assertThatJsonFailed("invalid-sone-id")
        }
 
        @Test
@@ -30,7 +28,7 @@ class UnlockSoneAjaxPageTest : JsonPageTest("unlockSone.ajax", requiresLogin = f
                val sone = mock<Sone>()
                addLocalSone(sone, "sone-id")
                addRequestParameter("sone", "sone-id")
-               assertThat(json.isSuccess, equalTo(true))
+               assertThatJsonIsSuccessful()
                verify(core).unlockSone(sone)
        }
 
index cc0193b..f2de48d 100644 (file)
@@ -15,15 +15,13 @@ class UntrustAjaxPageTest : JsonPageTest("untrustSone.ajax", pageSupplier = ::Un
 
        @Test
        fun `request without sone results in invalid-sone-id`() {
-               assertThat(json.isSuccess, equalTo(false))
-               assertThat(json.error, equalTo("invalid-sone-id"))
+               assertThatJsonFailed("invalid-sone-id")
        }
 
        @Test
        fun `request with invalid sone results in invalid-sone-id`() {
                addRequestParameter("sone", "invalid")
-               assertThat(json.isSuccess, equalTo(false))
-               assertThat(json.error, equalTo("invalid-sone-id"))
+               assertThatJsonFailed("invalid-sone-id")
        }
 
        @Test
@@ -31,7 +29,7 @@ class UntrustAjaxPageTest : JsonPageTest("untrustSone.ajax", pageSupplier = ::Un
                val sone = mock<Sone>()
                addSone(sone, "sone-id")
                addRequestParameter("sone", "sone-id")
-               assertThat(json.isSuccess, equalTo(true))
+               assertThatJsonIsSuccessful()
                verify(core).untrustSone(currentSone, sone)
        }
 
@@ -40,7 +38,7 @@ class UntrustAjaxPageTest : JsonPageTest("untrustSone.ajax", pageSupplier = ::Un
                val sone = mock<Sone>()
                addSone(sone, "sone-id")
                addRequestParameter("sone", "sone-id")
-               assertThat(json.isSuccess, equalTo(true))
+               assertThatJsonIsSuccessful()
                assertThat(json["trustValue"], nullValue())
        }