1 package net.pterodactylus.sone.web.pages
3 import net.pterodactylus.sone.data.Post
4 import net.pterodactylus.sone.test.mock
5 import net.pterodactylus.util.web.Method.POST
6 import org.hamcrest.MatcherAssert.assertThat
7 import org.hamcrest.Matchers.equalTo
9 import org.mockito.ArgumentMatchers.any
10 import org.mockito.Mockito.never
11 import org.mockito.Mockito.verify
14 * Unit test for [BookmarkPage].
16 class BookmarkPageTest: WebPageTest(::BookmarkPage) {
19 fun `path is set correctly`() {
20 assertThat(page.path, equalTo("bookmark.html"))
24 fun `get request does not bookmark anything and does not redirect`() {
26 verify(core, never()).bookmarkPost(any())
30 private fun setupBookmarkRequest() {
32 addHttpRequestPart("returnPage", "return-page.html")
33 addHttpRequestPart("post", "post-id")
37 fun `post is bookmarked correctly`() {
38 setupBookmarkRequest()
39 val post = mock<Post>()
40 addPost("post-id", post)
41 verifyRedirect("return-page.html") {
42 verify(core).bookmarkPost(post)
47 fun `non-existing post is not bookmarked`() {
48 setupBookmarkRequest()
49 verifyRedirect("return-page.html") {
50 verify(core, never()).bookmarkPost(any())