1 package net.pterodactylus.sone.web.page
3 import freenet.client.*
4 import net.pterodactylus.sone.test.*
5 import net.pterodactylus.util.web.*
6 import org.hamcrest.MatcherAssert.*
7 import org.hamcrest.Matchers.*
10 private val highLevelSimpleClient = mock<HighLevelSimpleClient>()
11 private const val pathPrefix = "/some/prefix/"
13 class PageToadletFactoryTest {
15 private val pageToadletFactory = PageToadletFactory(highLevelSimpleClient, pathPrefix)
18 fun `page toadlet without menu name is created without menu name`() {
19 val page = mock<Page<FreenetRequest>>()
20 val pageToadlet = pageToadletFactory.createPageToadlet(page)
21 assertThat(pageToadlet.menuName, nullValue())
25 fun `page toadlet with menu name is created with menu name`() {
26 val page = mock<Page<FreenetRequest>>()
27 val pageToadlet = pageToadletFactory.createPageToadlet(page, "testName")
28 assertThat(pageToadlet.menuName, equalTo("testName"))
32 fun `path prefix is handed down correctly`() {
33 val page = mock<Page<FreenetRequest>>().apply {
34 whenever(path).thenReturn("path")
36 val pageToadlet = pageToadletFactory.createPageToadlet(page)
37 assertThat(pageToadlet.path(), equalTo("/some/prefix/path"))
41 fun `menu name is added from annotation when no menu name is given`() {
42 val page = TestPageWithMenuName()
43 val pageToadlet = pageToadletFactory.createPageToadlet(page)
44 assertThat(pageToadlet.menuName, equalTo("testName"))
48 fun `menu name from annotation is ignored when menu name is given`() {
49 val page = TestPageWithMenuName()
50 val pageToadlet = pageToadletFactory.createPageToadlet(page, "foo")
51 assertThat(pageToadlet.menuName, equalTo("foo"))
57 private class TestPageWithMenuName : Page<FreenetRequest> {
59 override fun getPath() = ""
60 override fun isPrefixPage() = false
61 override fun handleRequest(request: FreenetRequest, response: Response) = response