1 package net.pterodactylus.sone.web
3 import net.pterodactylus.sone.data.Sone
4 import net.pterodactylus.sone.test.mock
5 import net.pterodactylus.util.web.Method.GET
6 import net.pterodactylus.util.web.Method.POST
8 import org.mockito.ArgumentMatchers
9 import org.mockito.ArgumentMatchers.any
10 import org.mockito.ArgumentMatchers.anyString
11 import org.mockito.Mockito.never
12 import org.mockito.Mockito.verify
15 * Unit test for [FollowSonePage].
17 class FollowSonePageTest : WebPageTest() {
19 private val page = FollowSonePage(template, webInterface)
21 override fun getPage() = page
24 fun `get request does not redirect`() {
26 page.handleRequest(freenetRequest, templateContext)
30 fun `a single sone can be followed`() {
32 val sone = mock<Sone>()
33 addSone("sone-id", sone)
34 addHttpRequestParameter("sone", "sone-id")
35 addHttpRequestParameter("returnPage", "return.html")
36 verifyRedirect("return.html") {
37 verify(core).followSone(currentSone, "sone-id")
38 verify(core).markSoneKnown(sone)
43 fun `multiple sones can be followed`() {
45 val firstSone = mock<Sone>()
46 addSone("sone-id1", firstSone)
47 val secondSone = mock<Sone>()
48 addSone("sone-id2", secondSone)
49 addHttpRequestParameter("sone", "sone-id1,sone-id2")
50 addHttpRequestParameter("returnPage", "return.html")
51 verifyRedirect("return.html") {
52 verify(core).followSone(currentSone, "sone-id1")
53 verify(core).followSone(currentSone, "sone-id2")
54 verify(core).markSoneKnown(firstSone)
55 verify(core).markSoneKnown(secondSone)
60 fun `a non-existing sone is not followed`() {
62 addHttpRequestParameter("sone", "sone-id")
63 addHttpRequestParameter("returnPage", "return.html")
64 verifyRedirect("return.html") {
65 verify(core, never()).followSone(ArgumentMatchers.eq(currentSone), anyString())
66 verify(core, never()).markSoneKnown(any<Sone>())