Add test for DI constructability of FollowSoneAjaxPage
[Sone.git] / src / test / kotlin / net / pterodactylus / sone / web / ajax / FollowSoneAjaxPageTest.kt
1 package net.pterodactylus.sone.web.ajax
2
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 org.hamcrest.MatcherAssert.assertThat
9 import org.hamcrest.Matchers.equalTo
10 import org.hamcrest.Matchers.notNullValue
11 import org.junit.Test
12 import org.mockito.Mockito.verify
13
14 /**
15  * Unit test for [FollowSoneAjaxPage].
16  */
17 class FollowSoneAjaxPageTest : JsonPageTest("followSone.ajax", pageSupplier = ::FollowSoneAjaxPage) {
18
19         @Test
20         fun `request without sone id results in invalid-sone-id`() {
21                 assertThatJsonFailed("invalid-sone-id")
22         }
23
24         @Test
25         fun `request with sone follows sone`() {
26                 addSone(mock<Sone>().apply { whenever(id).thenReturn("sone-id") })
27                 addRequestParameter("sone", "sone-id")
28                 assertThatJsonIsSuccessful()
29                 verify(core).followSone(currentSone, "sone-id")
30         }
31
32         @Test
33         fun `request with sone makes sone as known`() {
34                 val sone = mock<Sone>()
35                 addSone(sone, "sone-id")
36                 addRequestParameter("sone", "sone-id")
37                 assertThatJsonIsSuccessful()
38                 verify(core).markSoneKnown(sone)
39         }
40
41         @Test
42         fun `page can be created by dependency injection`() {
43                 assertThat(baseInjector.getInstance<FollowSoneAjaxPage>(), notNullValue())
44         }
45
46 }