It will be managed in a bunch of upcoming modules.
import net.pterodactylus.sone.web.page.FreenetRequest
import net.pterodactylus.util.template.Template
import net.pterodactylus.util.template.TemplateContext
-import javax.inject.Inject
-import javax.inject.Singleton
/**
* A [SoneTemplatePage] that stores information about Sone in the [TemplateContext].
*/
-@Singleton
-class AboutPage @Inject constructor(template: Template, webInterface: WebInterface,
- private val pluginVersion: PluginVersion,
- private val pluginYear: PluginYear,
- private val pluginHomepage: PluginHomepage) : SoneTemplatePage("about.html", template, "Page.About.Title", webInterface, false) {
+class AboutPage(template: Template, webInterface: WebInterface,
+ private val pluginVersion: PluginVersion,
+ private val pluginYear: PluginYear,
+ private val pluginHomepage: PluginHomepage): SoneTemplatePage("about.html", template, "Page.About.Title", webInterface, false) {
override fun handleRequest(request: FreenetRequest, templateContext: TemplateContext) {
templateContext["version"] = pluginVersion.version
/**
* Page that lets the user bookmark a post.
*/
-@Singleton
-class BookmarkPage @Inject constructor(template: Template, webInterface: WebInterface)
+class BookmarkPage(template: Template, webInterface: WebInterface)
: SoneTemplatePage("bookmark.html", template, "Page.Bookmark.Title", webInterface) {
override fun handleRequest(freenetRequest: FreenetRequest, templateContext: TemplateContext) {
import net.pterodactylus.sone.main.SonePlugin.PluginHomepage
import net.pterodactylus.sone.main.SonePlugin.PluginVersion
import net.pterodactylus.sone.main.SonePlugin.PluginYear
-import net.pterodactylus.sone.test.getInstance
-import net.pterodactylus.sone.test.isProvidedByMock
import org.hamcrest.MatcherAssert.assertThat
import org.hamcrest.Matchers.equalTo
-import org.hamcrest.Matchers.notNullValue
-import org.hamcrest.Matchers.sameInstance
import org.junit.Test
/**
* Unit test for [AboutPage].
*/
-class AboutPageTest : WebPageTest() {
+class AboutPageTest: WebPageTest() {
private val version = "0.1.2"
private val year = 1234
private val homepage = "home://page"
private val page = AboutPage(template, webInterface, PluginVersion(version), PluginYear(year), PluginHomepage(homepage))
- private val childInjector = injector.createChildInjector(
- PluginVersion::class.isProvidedByMock(),
- PluginYear::class.isProvidedByMock(),
- PluginHomepage::class.isProvidedByMock()
- )!!
@Test
fun `page returns correct path`() {
assertThat(templateContext["year"], equalTo<Any>(year))
}
- @Test
- fun `page can be created by guice`() {
- assertThat(childInjector.getInstance<AboutPage>(), notNullValue())
- }
-
- @Test
- fun `page is created as singleton`() {
- val firstInstance = childInjector.getInstance<AboutPage>()
- val secondInstance = childInjector.getInstance<AboutPage>()
- assertThat(firstInstance, sameInstance(secondInstance))
- }
-
}
package net.pterodactylus.sone.web
-import com.google.inject.Guice
import net.pterodactylus.sone.data.Post
-import net.pterodactylus.sone.test.getInstance
import net.pterodactylus.sone.test.mock
import net.pterodactylus.util.web.Method.POST
import org.hamcrest.MatcherAssert.assertThat
import org.hamcrest.Matchers.equalTo
-import org.hamcrest.Matchers.notNullValue
-import org.hamcrest.Matchers.sameInstance
import org.junit.Test
import org.mockito.ArgumentMatchers.any
import org.mockito.Mockito.never
}
}
- @Test
- fun `bookmark page can be created by guice`() {
- assertThat(injector.getInstance<BookmarkPage>(), notNullValue())
- }
-
- @Test
- fun `bookmark page is created as singleton`() {
- val firstInstance = injector.getInstance<BookmarkPage>()
- val secondInstance = injector.getInstance<BookmarkPage>()
- assertThat(firstInstance, sameInstance(secondInstance))
- }
-
}