✅ Add test for PageToadletFactory
authorDavid ‘Bombe’ Roden <bombe@pterodactylus.net>
Fri, 12 Apr 2019 13:55:01 +0000 (15:55 +0200)
committerDavid ‘Bombe’ Roden <bombe@pterodactylus.net>
Fri, 12 Apr 2019 14:00:23 +0000 (16:00 +0200)
src/test/kotlin/net/pterodactylus/sone/web/page/PageToadletFactoryTest.kt [new file with mode: 0644]

diff --git a/src/test/kotlin/net/pterodactylus/sone/web/page/PageToadletFactoryTest.kt b/src/test/kotlin/net/pterodactylus/sone/web/page/PageToadletFactoryTest.kt
new file mode 100644 (file)
index 0000000..93047cb
--- /dev/null
@@ -0,0 +1,42 @@
+package net.pterodactylus.sone.web.page
+
+import freenet.client.HighLevelSimpleClient
+import net.pterodactylus.sone.test.mock
+import net.pterodactylus.sone.test.whenever
+import net.pterodactylus.util.web.Page
+import org.hamcrest.MatcherAssert.assertThat
+import org.hamcrest.Matchers.equalTo
+import org.hamcrest.Matchers.nullValue
+import org.junit.Test
+
+private val highLevelSimpleClient = mock<HighLevelSimpleClient>()
+private const val pathPrefix = "/some/prefix/"
+
+class PageToadletFactoryTest {
+
+       private val pageToadletFactory = PageToadletFactory(highLevelSimpleClient, pathPrefix)
+
+       @Test
+       fun `page toadlet without menu name is created without menu name`() {
+               val page = mock<Page<FreenetRequest>>()
+               val pageToadlet = pageToadletFactory.createPageToadlet(page)
+               assertThat(pageToadlet.menuName, nullValue())
+       }
+
+       @Test
+       fun `page toadlet with menu name is created with menu name`() {
+               val page = mock<Page<FreenetRequest>>()
+               val pageToadlet = pageToadletFactory.createPageToadlet(page, "testName")
+               assertThat(pageToadlet.menuName, equalTo("testName"))
+       }
+
+       @Test
+       fun `path prefix is handed down correctly`() {
+               val page = mock<Page<FreenetRequest>>().apply {
+                       whenever(path).thenReturn("path")
+               }
+               val pageToadlet = pageToadletFactory.createPageToadlet(page)
+               assertThat(pageToadlet.path(), equalTo("/some/prefix/path"))
+       }
+
+}