Add test for DI constructability of TrustAjaxPage
[Sone.git] / src / test / kotlin / net / pterodactylus / sone / web / ajax / LikeAjaxPageTest.kt
index 9a8f2c2..c7da213 100644 (file)
@@ -2,10 +2,13 @@ package net.pterodactylus.sone.web.ajax
 
 import net.pterodactylus.sone.data.Post
 import net.pterodactylus.sone.data.PostReply
+import net.pterodactylus.sone.test.getInstance
 import net.pterodactylus.sone.test.mock
 import net.pterodactylus.sone.test.whenever
+import net.pterodactylus.sone.web.baseInjector
 import org.hamcrest.MatcherAssert.assertThat
 import org.hamcrest.Matchers.equalTo
+import org.hamcrest.Matchers.notNullValue
 import org.junit.Test
 import org.mockito.Mockito.never
 import org.mockito.Mockito.verify
@@ -19,8 +22,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 +30,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 +40,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()
        }
@@ -61,4 +63,9 @@ class LikeAjaxPageTest : JsonPageTest("like.ajax", pageSupplier = ::LikeAjaxPage
                verify(core, never()).touchConfiguration()
        }
 
+       @Test
+       fun `page can be created by dependency injection`() {
+           assertThat(baseInjector.getInstance<LikeAjaxPage>(), notNullValue())
+       }
+
 }