1 package net.pterodactylus.sone.web.page
3 import com.google.inject.*
4 import freenet.client.*
5 import net.pterodactylus.sone.test.*
6 import net.pterodactylus.util.web.*
7 import org.hamcrest.MatcherAssert.*
8 import org.hamcrest.Matchers.*
11 private val highLevelSimpleClient = mock<HighLevelSimpleClient>()
12 private const val pathPrefix = "/some/prefix/"
14 class PageToadletFactoryTest {
16 private val pageToadletFactory = PageToadletFactory(highLevelSimpleClient, pathPrefix)
19 fun `page toadlet without menu name is created without menu name`() {
20 val page = mock<Page<FreenetRequest>>()
21 val pageToadlet = pageToadletFactory.createPageToadlet(page)
22 assertThat(pageToadlet.menuName, nullValue())
26 fun `page toadlet with menu name is created with menu name`() {
27 val page = mock<Page<FreenetRequest>>()
28 val pageToadlet = pageToadletFactory.createPageToadlet(page, "testName")
29 assertThat(pageToadlet.menuName, equalTo("testName"))
33 fun `path prefix is handed down correctly`() {
34 val page = mock<Page<FreenetRequest>>().apply {
35 whenever(path).thenReturn("path")
37 val pageToadlet = pageToadletFactory.createPageToadlet(page)
38 assertThat(pageToadlet.path(), equalTo("/some/prefix/path"))
42 fun `menu name is added from annotation when no menu name is given`() {
43 val page = TestPageWithMenuName()
44 val pageToadlet = pageToadletFactory.createPageToadlet(page)
45 assertThat(pageToadlet.menuName, equalTo("testName"))
49 fun `menu name from annotation is ignored when menu name is given`() {
50 val page = TestPageWithMenuName()
51 val pageToadlet = pageToadletFactory.createPageToadlet(page, "foo")
52 assertThat(pageToadlet.menuName, equalTo("foo"))
56 fun `page toadlet factory can be created by guice`() {
57 val injector = Guice.createInjector(
58 HighLevelSimpleClient::class.isProvidedBy(highLevelSimpleClient),
59 String::class.withNameIsProvidedBy("/Sone/", "toadletPathPrefix")
61 assertThat(injector.getInstance<PageToadletFactory>(), notNullValue())
67 private class TestPageWithMenuName : Page<FreenetRequest> {
69 override fun getPath() = ""
70 override fun isPrefixPage() = false
71 override fun handleRequest(request: FreenetRequest, response: Response) = response