Fix formatting
[Sone.git] / src / test / kotlin / net / pterodactylus / sone / web / pages / ViewSonePageTest.kt
index 7161684..d13575d 100644 (file)
@@ -4,9 +4,9 @@ import net.pterodactylus.sone.data.Post
 import net.pterodactylus.sone.data.PostReply
 import net.pterodactylus.sone.data.Profile
 import net.pterodactylus.sone.data.Sone
-import net.pterodactylus.sone.test.asOptional
 import net.pterodactylus.sone.test.mock
 import net.pterodactylus.sone.test.whenever
+import net.pterodactylus.sone.utils.asOptional
 import org.hamcrest.MatcherAssert.assertThat
 import org.hamcrest.Matchers.contains
 import org.hamcrest.Matchers.equalTo
@@ -17,7 +17,7 @@ import org.junit.Test
 /**
  * Unit test for [ViewSonePage].
  */
-class ViewSonePageTest : WebPageTest() {
+class ViewSonePageTest: WebPageTest() {
 
        init {
                whenever(currentSone.id).thenReturn("sone-id")
@@ -41,6 +41,16 @@ class ViewSonePageTest : WebPageTest() {
        }
 
        @Test
+       fun `page returns correct path`() {
+               assertThat(page.path, equalTo("viewSone.html"))
+       }
+
+       @Test
+       fun `page does not require login`() {
+               assertThat(page.requiresLogin(), equalTo(false))
+       }
+
+       @Test
        fun `get request without sone parameter stores null in template context`() {
                verifyNoRedirect {
                        assertThat(templateContext["sone"], nullValue())
@@ -109,14 +119,14 @@ class ViewSonePageTest : WebPageTest() {
        @Test
        @Suppress("UNCHECKED_CAST")
        fun `replies are shown correctly`() {
-           val reply1 = createReply("First Reply", 1500, foreignPost1)
+               val reply1 = createReply("First Reply", 1500, foreignPost1)
                val reply2 = createReply("Second Reply", 2500, foreignPost2)
                val reply3 = createReply("Third Reply", 1750, post1)
                val reply4 = createReply("Fourth Reply", 2250, post2)
-           val reply5 = createReply("Fifth Reply", 1600, post1)
-           val reply6 = createReply("Sixth Reply", 2100, directed1)
-           val reply7 = createReply("Seventh Reply", 2200, null)
-           val reply8 = createReply("Eigth Reply", 2300, foreignPost1)
+               val reply5 = createReply("Fifth Reply", 1600, post1)
+               val reply6 = createReply("Sixth Reply", 2100, directed1)
+               val reply7 = createReply("Seventh Reply", 2200, null)
+               val reply8 = createReply("Eigth Reply", 2300, foreignPost1)
                whenever(currentSone.replies).thenReturn(setOf(reply1, reply2, reply3, reply4, reply5, reply6, reply7, reply8))
                whenever(core.getReplies("post1")).thenReturn(listOf(reply3, reply5))
                whenever(core.getReplies("post2")).thenReturn(listOf(reply4))
@@ -126,19 +136,21 @@ class ViewSonePageTest : WebPageTest() {
                addSone("sone-id", currentSone)
                addHttpRequestParameter("sone", "sone-id")
                verifyNoRedirect {
-                       assertThat(templateContext["repliedPosts"] as Iterable<Post>, contains(foreignPost2,  foreignPost1))
+                       assertThat(templateContext["repliedPosts"] as Iterable<Post>, contains(foreignPost2, foreignPost1))
                }
        }
 
        @Test
        fun `page title is default for request without parameters`() {
-           assertThat(page.getPageTitle(freenetRequest), equalTo("Page.ViewSone.Page.TitleWithoutSone"))
+               addTranslation("Page.ViewSone.Page.TitleWithoutSone", "view sone page without sone")
+               assertThat(page.getPageTitle(freenetRequest), equalTo("view sone page without sone"))
        }
 
        @Test
        fun `page title is default for request with invalid sone parameters`() {
                addHttpRequestParameter("sone", "invalid-sone-id")
-           assertThat(page.getPageTitle(freenetRequest), equalTo("Page.ViewSone.Page.TitleWithoutSone"))
+               addTranslation("Page.ViewSone.Page.TitleWithoutSone", "view sone page without sone")
+               assertThat(page.getPageTitle(freenetRequest), equalTo("view sone page without sone"))
        }
 
        @Test
@@ -150,12 +162,13 @@ class ViewSonePageTest : WebPageTest() {
                        middleName = "M."
                        lastName = "Last"
                })
-           assertThat(page.getPageTitle(freenetRequest), equalTo("First M. Last - Page.ViewSone.Title"))
+               addTranslation("Page.ViewSone.Title", "view sone page")
+               assertThat(page.getPageTitle(freenetRequest), equalTo("First M. Last - view sone page"))
        }
 
        @Test
        fun `page is link-excepted`() {
-           assertThat(page.isLinkExcepted(null), equalTo(true))
+               assertThat(page.isLinkExcepted(null), equalTo(true))
        }
 
 }