1 package net.pterodactylus.sone.web.pages
3 import net.pterodactylus.sone.data.*
4 import net.pterodactylus.sone.test.*
5 import net.pterodactylus.sone.web.*
6 import net.pterodactylus.util.web.Method.*
7 import org.hamcrest.MatcherAssert.*
8 import org.hamcrest.Matchers.*
10 import org.mockito.ArgumentMatchers.any
11 import org.mockito.Mockito.never
12 import org.mockito.Mockito.verify
15 * Unit test for [BookmarkPage].
17 class BookmarkPageTest : WebPageTest(::BookmarkPage) {
20 fun `path is set correctly`() {
21 assertThat(page.path, equalTo("bookmark.html"))
25 fun `get request does not bookmark anything and does not redirect`() {
27 verify(core, never()).bookmarkPost(any())
31 private fun setupBookmarkRequest() {
33 addHttpRequestPart("returnPage", "return-page.html")
34 addHttpRequestPart("post", "post-id")
38 fun `post is bookmarked correctly`() {
39 setupBookmarkRequest()
40 val post = mock<Post>()
41 addPost("post-id", post)
42 verifyRedirect("return-page.html") {
43 verify(core).bookmarkPost(post)
48 fun `non-existing post is not bookmarked`() {
49 setupBookmarkRequest()
50 verifyRedirect("return-page.html") {
51 verify(core, never()).bookmarkPost(any())
56 fun `bookmark page can be created by dependency injection`() {
57 assertThat(baseInjector.getInstance<BookmarkPage>(), notNullValue())