@JvmOverloads
fun createPageToadlet(page: Page<FreenetRequest>, menuName: String? = null) =
- PageToadlet(highLevelSimpleClient, menuName, page, pathPrefix)
+ PageToadlet(highLevelSimpleClient, menuName ?: page.menuName, page, pathPrefix)
}
+
+private val Page<*>.menuName get() = javaClass.getAnnotation(MenuName::class.java)?.value
import net.pterodactylus.sone.test.mock
import net.pterodactylus.sone.test.whenever
import net.pterodactylus.util.web.Page
+import net.pterodactylus.util.web.Response
import org.hamcrest.MatcherAssert.assertThat
import org.hamcrest.Matchers.equalTo
import org.hamcrest.Matchers.nullValue
assertThat(pageToadlet.path(), equalTo("/some/prefix/path"))
}
+ @Test
+ fun `menu name is added from annotation when no menu name is given`() {
+ val page = TestPageWithMenuName()
+ val pageToadlet = pageToadletFactory.createPageToadlet(page)
+ assertThat(pageToadlet.menuName, equalTo("testName"))
+ }
+
+ @Test
+ fun `menu name from annotation is ignored when menu name is given`() {
+ val page = TestPageWithMenuName()
+ val pageToadlet = pageToadletFactory.createPageToadlet(page, "foo")
+ assertThat(pageToadlet.menuName, equalTo("foo"))
+ }
+
+}
+
+@MenuName("testName")
+private class TestPageWithMenuName : Page<FreenetRequest> {
+
+ override fun getPath() = ""
+ override fun isPrefixPage() = false
+ override fun handleRequest(request: FreenetRequest, response: Response) = response
+
}