1 package net.pterodactylus.sone.web.pages
3 import net.pterodactylus.sone.data.Sone
4 import net.pterodactylus.sone.test.getInstance
5 import net.pterodactylus.sone.test.mock
6 import net.pterodactylus.sone.test.whenever
7 import net.pterodactylus.sone.web.baseInjector
8 import net.pterodactylus.util.web.Method.POST
9 import org.hamcrest.MatcherAssert.assertThat
10 import org.hamcrest.Matchers.equalTo
11 import org.hamcrest.Matchers.notNullValue
13 import org.mockito.ArgumentMatchers
14 import org.mockito.ArgumentMatchers.any
15 import org.mockito.ArgumentMatchers.anyString
16 import org.mockito.Mockito.never
17 import org.mockito.Mockito.verify
20 * Unit test for [FollowSonePage].
22 class FollowSonePageTest: WebPageTest(::FollowSonePage) {
25 fun `page returns correct path`() {
26 assertThat(page.path, equalTo("followSone.html"))
30 fun `page requires login`() {
31 assertThat(page.requiresLogin(), equalTo(true))
35 fun `page returns correct title`() {
36 whenever(l10n.getString("Page.FollowSone.Title")).thenReturn("follow sone page title")
37 assertThat(page.getPageTitle(soneRequest), equalTo("follow sone page title"))
41 fun `get request does not redirect`() {
42 page.processTemplate(freenetRequest, templateContext)
46 fun `a single sone can be followed`() {
48 val sone = mock<Sone>()
49 addSone("sone-id", sone)
50 addHttpRequestPart("sone", "sone-id")
51 addHttpRequestPart("returnPage", "return.html")
52 verifyRedirect("return.html") {
53 verify(core).followSone(currentSone, "sone-id")
54 verify(core).markSoneKnown(sone)
59 fun `multiple sones can be followed`() {
61 val firstSone = mock<Sone>()
62 addSone("sone-id1", firstSone)
63 val secondSone = mock<Sone>()
64 addSone("sone-id2", secondSone)
65 addHttpRequestPart("sone", "sone-id1,sone-id2")
66 addHttpRequestPart("returnPage", "return.html")
67 verifyRedirect("return.html") {
68 verify(core).followSone(currentSone, "sone-id1")
69 verify(core).followSone(currentSone, "sone-id2")
70 verify(core).markSoneKnown(firstSone)
71 verify(core).markSoneKnown(secondSone)
76 fun `a non-existing sone is not followed`() {
78 addHttpRequestPart("sone", "sone-id")
79 addHttpRequestPart("returnPage", "return.html")
80 verifyRedirect("return.html") {
81 verify(core, never()).followSone(ArgumentMatchers.eq(currentSone), anyString())
82 verify(core, never()).markSoneKnown(any<Sone>())
87 fun `page can be created by dependency injection`() {
88 assertThat(baseInjector.getInstance<FollowSonePage>(), notNullValue())