X-Git-Url: https://git.pterodactylus.net/?p=Sone.git;a=blobdiff_plain;f=src%2Ftest%2Fkotlin%2Fnet%2Fpterodactylus%2Fsone%2Fweb%2Fpages%2FCreatePostPageTest.kt;h=6212c90abf2cfb3161d0d42b43c5d0d49707ac17;hp=e337973c0bd28b5a1b31e9e6e02b5aeaa68c377f;hb=04709e23f38e9d447337682ba27201da5dc19bd9;hpb=6b29b49714912ff5e3e410d2484699cdf8041b90 diff --git a/src/test/kotlin/net/pterodactylus/sone/web/pages/CreatePostPageTest.kt b/src/test/kotlin/net/pterodactylus/sone/web/pages/CreatePostPageTest.kt index e337973..6212c90 100644 --- a/src/test/kotlin/net/pterodactylus/sone/web/pages/CreatePostPageTest.kt +++ b/src/test/kotlin/net/pterodactylus/sone/web/pages/CreatePostPageTest.kt @@ -1,25 +1,21 @@ package net.pterodactylus.sone.web.pages -import com.google.common.base.Optional.absent -import net.pterodactylus.sone.data.Sone -import net.pterodactylus.sone.test.asOptional -import net.pterodactylus.sone.test.mock -import net.pterodactylus.sone.web.pages.WebPageTest -import net.pterodactylus.sone.web.pages.CreatePostPage -import net.pterodactylus.util.web.Method.POST -import org.hamcrest.MatcherAssert.assertThat -import org.hamcrest.Matchers.equalTo -import org.junit.Test -import org.mockito.Mockito.verify +import com.google.common.base.Optional.* +import net.pterodactylus.sone.data.* +import net.pterodactylus.sone.test.* +import net.pterodactylus.sone.utils.* +import net.pterodactylus.sone.web.* +import net.pterodactylus.sone.web.page.* +import net.pterodactylus.util.web.Method.* +import org.hamcrest.MatcherAssert.* +import org.hamcrest.Matchers.* +import org.junit.* +import org.mockito.Mockito.* /** * Unit test for [CreatePostPage]. */ -class CreatePostPageTest: WebPageTest() { - - private val page = CreatePostPage(template, webInterface) - - override fun getPage() = page +class CreatePostPageTest : WebPageTest(::CreatePostPage) { @Test fun `page returns correct path`() { @@ -44,7 +40,7 @@ class CreatePostPageTest: WebPageTest() { addHttpRequestPart("returnPage", "return.html") addHttpRequestPart("text", "post text") verifyRedirect("return.html") { - verify(core).createPost(currentSone, absent(), "post text") + verify(core).createPost(currentSone, null, "post text") } } @@ -66,7 +62,7 @@ class CreatePostPageTest: WebPageTest() { val sender = mock() addLocalSone("sender-id", sender) verifyRedirect("return.html") { - verify(core).createPost(sender, absent(), "post text") + verify(core).createPost(sender, null, "post text") } } @@ -79,7 +75,7 @@ class CreatePostPageTest: WebPageTest() { val recipient = mock() addSone("recipient-id", recipient) verifyRedirect("return.html") { - verify(core).createPost(currentSone, recipient.asOptional(), "post text") + verify(core).createPost(currentSone, recipient, "post text") } } @@ -90,8 +86,18 @@ class CreatePostPageTest: WebPageTest() { addHttpRequestPart("text", "post http://localhost:12345/KSK@foo text") addHttpRequestHeader("Host", "localhost:12345") verifyRedirect("return.html") { - verify(core).createPost(currentSone, absent(), "post KSK@foo text") + verify(core).createPost(currentSone, null, "post KSK@foo text") } } + @Test + fun `page can be created by dependency injection`() { + assertThat(baseInjector.getInstance(), notNullValue()) + } + + @Test + fun `page is annotated with correct template path`() { + assertThat(page.templatePath, equalTo("/templates/createPost.html")) + } + }