0e8e6b3540607537e59fcdddc85aa3402ae82c6d
[Sone.git] / src / test / kotlin / net / pterodactylus / sone / web / AboutPageTest.kt
1 package net.pterodactylus.sone.web
2
3 import net.pterodactylus.sone.main.SonePlugin.PluginHomepage
4 import net.pterodactylus.sone.main.SonePlugin.PluginVersion
5 import net.pterodactylus.sone.main.SonePlugin.PluginYear
6 import net.pterodactylus.sone.test.getInstance
7 import net.pterodactylus.sone.test.isProvidedByMock
8 import org.hamcrest.MatcherAssert.assertThat
9 import org.hamcrest.Matchers.equalTo
10 import org.hamcrest.Matchers.notNullValue
11 import org.hamcrest.Matchers.sameInstance
12 import org.junit.Test
13
14 /**
15  * Unit test for [AboutPage].
16  */
17 class AboutPageTest : WebPageTest() {
18
19         private val version = "0.1.2"
20         private val year = 1234
21         private val homepage = "home://page"
22         private val page = AboutPage(template, webInterface, PluginVersion(version), PluginYear(year), PluginHomepage(homepage))
23         private val childInjector = injector.createChildInjector(
24                         PluginVersion::class.isProvidedByMock(),
25                         PluginYear::class.isProvidedByMock(),
26                         PluginHomepage::class.isProvidedByMock()
27         )!!
28
29         @Test
30         fun `page returns correct path`() {
31                 assertThat(page.path, equalTo("about.html"))
32         }
33
34         @Test
35         fun `page does not require login`() {
36                 assertThat(page.requiresLogin(), equalTo(false))
37         }
38
39         @Test
40         fun `page sets correct version in template context`() {
41                 page.processTemplate(freenetRequest, templateContext)
42                 assertThat(templateContext["version"], equalTo<Any>(version))
43         }
44
45         @Test
46         fun `page sets correct homepage in template context`() {
47                 page.processTemplate(freenetRequest, templateContext)
48                 assertThat(templateContext["homepage"], equalTo<Any>(homepage))
49         }
50
51         @Test
52         fun `page sets correct year in template context`() {
53                 page.processTemplate(freenetRequest, templateContext)
54                 assertThat(templateContext["year"], equalTo<Any>(year))
55         }
56
57         @Test
58         fun `page can be created by guice`() {
59                 assertThat(childInjector.getInstance<AboutPage>(), notNullValue())
60         }
61
62         @Test
63         fun `page is created as singleton`() {
64             val firstInstance = childInjector.getInstance<AboutPage>()
65                 val secondInstance = childInjector.getInstance<AboutPage>()
66                 assertThat(firstInstance, sameInstance(secondInstance))
67         }
68
69 }