Simplify expression
[Sone.git] / src / test / kotlin / net / pterodactylus / sone / web / ajax / BookmarkAjaxPageTest.kt
1 package net.pterodactylus.sone.web.ajax
2
3 import net.pterodactylus.sone.data.Post
4 import org.hamcrest.MatcherAssert.assertThat
5 import org.hamcrest.Matchers.equalTo
6 import org.junit.Test
7 import org.mockito.ArgumentMatchers.any
8 import org.mockito.Mockito.never
9 import org.mockito.Mockito.verify
10
11 /**
12  * Unit test for [BookmarkAjaxPage].
13  */
14 class BookmarkAjaxPageTest : JsonPageTest("bookmark.ajax", requiresLogin = false, pageSupplier = ::BookmarkAjaxPage) {
15
16         @Test
17         fun `missing post ID results in invalid id response`() {
18                 assertThatJsonFailed("invalid-post-id")
19         }
20
21         @Test
22         fun `empty post ID results in invalid id response`() {
23                 addRequestParameter("post", "")
24                 assertThatJsonFailed("invalid-post-id")
25         }
26
27         @Test
28         fun `invalid post ID results in success but does not bookmark anything`() {
29                 addRequestParameter("post", "missing")
30                 assertThatJsonIsSuccessful()
31                 verify(core, never()).bookmarkPost(any<Post>())
32         }
33
34         @Test
35         fun `valid post ID results in success and bookmarks the post`() {
36                 addRequestParameter("post", "valid-post-id")
37                 val post = addNewPost("valid-post-id", "1", 2)
38                 assertThatJsonIsSuccessful()
39                 verify(core).bookmarkPost(post)
40         }
41
42 }