✨ Use @TemplatePath annotations on most pages
[Sone.git] / src / test / kotlin / net / pterodactylus / sone / web / pages / DeleteReplyPageTest.kt
index 7944321..fbec0d5 100644 (file)
@@ -2,14 +2,15 @@ package net.pterodactylus.sone.web.pages
 
 import net.pterodactylus.sone.data.PostReply
 import net.pterodactylus.sone.data.Sone
+import net.pterodactylus.sone.test.getInstance
 import net.pterodactylus.sone.test.mock
 import net.pterodactylus.sone.test.whenever
-import net.pterodactylus.sone.web.pages.WebPageTest
-import net.pterodactylus.sone.web.pages.DeleteReplyPage
-import net.pterodactylus.util.web.Method.GET
+import net.pterodactylus.sone.web.baseInjector
+import net.pterodactylus.sone.web.page.*
 import net.pterodactylus.util.web.Method.POST
 import org.hamcrest.MatcherAssert.assertThat
 import org.hamcrest.Matchers.equalTo
+import org.hamcrest.Matchers.notNullValue
 import org.junit.Before
 import org.junit.Test
 import org.mockito.Mockito.never
@@ -18,15 +19,11 @@ import org.mockito.Mockito.verify
 /**
  * Unit test for [DeleteReplyPage].
  */
-class DeleteReplyPageTest : WebPageTest() {
-
-       private val page = DeleteReplyPage(template, webInterface)
+class DeleteReplyPageTest: WebPageTest(::DeleteReplyPage) {
 
        private val sone = mock<Sone>()
        private val reply = mock<PostReply>()
 
-       override fun getPage() = page
-
        @Before
        fun setupReply() {
                whenever(sone.isLocal).thenReturn(true)
@@ -45,7 +42,6 @@ class DeleteReplyPageTest : WebPageTest() {
 
        @Test
        fun `get request sets reply ID and return page in template context`() {
-               request("", GET)
                addHttpRequestParameter("reply", "reply-id")
                addHttpRequestParameter("returnPage", "return.html")
                page.processTemplate(freenetRequest, templateContext)
@@ -55,7 +51,7 @@ class DeleteReplyPageTest : WebPageTest() {
 
        @Test
        fun `post request without any action sets reply ID and return page in template context`() {
-               request("", POST)
+               setMethod(POST)
                addPostReply("reply-id", reply)
                addHttpRequestPart("reply", "reply-id")
                addHttpRequestPart("returnPage", "return.html")
@@ -66,13 +62,13 @@ class DeleteReplyPageTest : WebPageTest() {
 
        @Test
        fun `trying to delete a reply with an invalid ID results in no permission page`() {
-               request("", POST)
+               setMethod(POST)
                verifyRedirect("noPermission.html")
        }
 
        @Test
        fun `trying to delete a reply from a non-local sone results in no permission page`() {
-               request("", POST)
+               setMethod(POST)
                addHttpRequestPart("reply", "reply-id")
                whenever(sone.isLocal).thenReturn(false)
                addPostReply("reply-id", reply)
@@ -81,7 +77,7 @@ class DeleteReplyPageTest : WebPageTest() {
 
        @Test
        fun `confirming deletion of reply deletes the reply and redirects to return page`() {
-               request("", POST)
+               setMethod(POST)
                addPostReply("reply-id", reply)
                addHttpRequestPart("reply", "reply-id")
                addHttpRequestPart("returnPage", "return.html")
@@ -93,7 +89,7 @@ class DeleteReplyPageTest : WebPageTest() {
 
        @Test
        fun `aborting deletion of reply redirects to return page`() {
-               request("", POST)
+               setMethod(POST)
                addPostReply("reply-id", reply)
                addHttpRequestPart("reply", "reply-id")
                addHttpRequestPart("returnPage", "return.html")
@@ -103,4 +99,14 @@ class DeleteReplyPageTest : WebPageTest() {
                }
        }
 
+       @Test
+       fun `page can be created by dependency injection`() {
+               assertThat(baseInjector.getInstance<DeleteReplyPage>(), notNullValue())
+       }
+
+       @Test
+       fun `page is annotated with correct template path`() {
+           assertThat(page.templatePath, equalTo("/templates/deleteReply.html"))
+       }
+
 }