bind(getOptionalContextTypeLiteral()).toInstance(of(context));
bind(SonePlugin.class).toInstance(SonePlugin.this);
bind(Version.class).toInstance(VERSION);
+ bind(PluginVersion.class).toInstance(new PluginVersion(getVersion()));
+ bind(PluginYear.class).toInstance(new PluginYear(getYear()));
+ bind(PluginHomepage.class).toInstance(new PluginHomepage(getHomepage()));
if (startConfiguration.getBooleanValue("Developer.LoadFromFilesystem").getValue(false)) {
String path = startConfiguration.getStringValue("Developer.FilesystemPath").getValue(null);
if (path != null) {
return VERSION.toString();
}
+ public static class PluginVersion {
+
+ private final String version;
+
+ public PluginVersion(String version) {
+ this.version = version;
+ }
+
+ public String getVersion() {
+ return version;
+ }
+
+ }
+
+ public static class PluginYear {
+
+ private final int year;
+
+ public PluginYear(int year) {
+ this.year = year;
+ }
+
+ public int getYear() {
+ return year;
+ }
+
+ }
+
+ public static class PluginHomepage {
+
+ private final String homepage;
+
+ public PluginHomepage(String homepage) {
+ this.homepage = homepage;
+ }
+
+ public String getHomepage() {
+ return homepage;
+ }
+
+ }
+
}
+++ /dev/null
-/*
- * Sone - AboutPage.java - Copyright © 2010–2016 David Roden
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-package net.pterodactylus.sone.web;
-
-import net.pterodactylus.sone.web.page.FreenetRequest;
-import net.pterodactylus.util.template.Template;
-import net.pterodactylus.util.template.TemplateContext;
-import net.pterodactylus.util.version.Version;
-
-/**
- * Shows some information about Sone.
- *
- * @author <a href="mailto:bombe@pterodactylus.net">David ‘Bombe’ Roden</a>
- */
-public class AboutPage extends SoneTemplatePage {
-
- private final String version;
- private final int year;
- private final String homepage;
-
- public AboutPage(Template template, WebInterface webInterface, String version, int year, String homepage) {
- super("about.html", template, "Page.About.Title", webInterface, false);
- this.version = version;
- this.year = year;
- this.homepage = homepage;
- }
-
- @Override
- protected void handleRequest(FreenetRequest request, TemplateContext templateContext) throws RedirectException {
- templateContext.set("version", version);
- templateContext.set("year", year);
- templateContext.set("homepage", homepage);
- }
-
-}
import net.pterodactylus.sone.main.Loaders;
import net.pterodactylus.sone.main.ReparseFilter;
import net.pterodactylus.sone.main.SonePlugin;
+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.notify.ListNotification;
import net.pterodactylus.sone.notify.ListNotificationFilter;
import net.pterodactylus.sone.notify.PostVisibilityFilter;
pageToadlets.add(pageToadletFactory.createPageToadlet(new LogoutPage(emptyTemplate, this), "Logout"));
pageToadlets.add(pageToadletFactory.createPageToadlet(new OptionsPage(optionsTemplate, this), "Options"));
pageToadlets.add(pageToadletFactory.createPageToadlet(new RescuePage(rescueTemplate, this), "Rescue"));
- pageToadlets.add(pageToadletFactory.createPageToadlet(new AboutPage(aboutTemplate, this, SonePlugin.getPluginVersion(), SonePlugin.getYear(), SonePlugin.getHomepage()), "About"));
+ pageToadlets.add(pageToadletFactory.createPageToadlet(new AboutPage(aboutTemplate, this, new PluginVersion(SonePlugin.getPluginVersion()), new PluginYear(SonePlugin.getYear()), new PluginHomepage(SonePlugin.getHomepage())), "About"));
pageToadlets.add(pageToadletFactory.createPageToadlet(new SoneTemplatePage("noPermission.html", noPermissionTemplate, "Page.NoPermission.Title", this)));
pageToadlets.add(pageToadletFactory.createPageToadlet(new SoneTemplatePage("emptyImageTitle.html", emptyImageTitleTemplate, "Page.EmptyImageTitle.Title", this)));
pageToadlets.add(pageToadletFactory.createPageToadlet(new SoneTemplatePage("emptyAlbumTitle.html", emptyAlbumTitleTemplate, "Page.EmptyAlbumTitle.Title", this)));
--- /dev/null
+package net.pterodactylus.sone.web
+
+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.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) {
+
+ override fun handleRequest(request: FreenetRequest, templateContext: TemplateContext) {
+ templateContext["version"] = pluginVersion.version
+ templateContext["year"] = pluginYear.year
+ templateContext["homepage"] = pluginHomepage.homepage
+ }
+
+}
+++ /dev/null
-package net.pterodactylus.sone.web;
-
-import static org.hamcrest.MatcherAssert.assertThat;
-import static org.hamcrest.Matchers.is;
-
-import org.junit.Test;
-
-/**
- * Unit test for {@link AboutPage}.
- *
- * @author <a href="mailto:bombe@pterodactylus.net">David ‘Bombe’ Roden</a>
- */
-public class AboutPageTest extends WebPageTest {
-
- private final String version = "0.1.2";
- private final int year = 1234;
- private final String homepage = "home://page";
- private final AboutPage page = new AboutPage(template, webInterface, version, year, homepage);
-
- @Test
- public void pageReturnsCorrectPath() {
- assertThat(page.getPath(), is("about.html"));
- }
-
- @Test
- public void pageSetsCorrectVersionInTemplateContext() throws Exception {
- page.processTemplate(freenetRequest, templateContext);
- assertThat(templateContext.get("version"), is((Object) version));
- }
-
- @Test
- public void pageSetsCorrectHomepageInTemplateContext() throws Exception {
- page.processTemplate(freenetRequest, templateContext);
- assertThat(templateContext.get("homepage"), is((Object) homepage));
- }
-
- @Test
- public void pageSetsCorrectYearInTemplateContext() throws Exception {
- page.processTemplate(freenetRequest, templateContext);
- assertThat(templateContext.get("year"), is((Object) year));
- }
-
-}
--- /dev/null
+package net.pterodactylus.sone.web
+
+import com.google.inject.Guice
+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 net.pterodactylus.util.template.Template
+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() {
+
+ 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 injector = Guice.createInjector(
+ Template::class.isProvidedByMock(),
+ WebInterface::class.isProvidedByMock(),
+ PluginVersion::class.isProvidedByMock(),
+ PluginYear::class.isProvidedByMock(),
+ PluginHomepage::class.isProvidedByMock()
+ )!!
+
+ @Test
+ fun `page returns correct path`() {
+ assertThat(page.path, equalTo("about.html"))
+ }
+
+ @Test
+ fun `page does not require login`() {
+ assertThat(page.requiresLogin(), equalTo(false))
+ }
+
+ @Test
+ fun `page sets correct version in template context`() {
+ page.processTemplate(freenetRequest, templateContext)
+ assertThat(templateContext["version"], equalTo<Any>(version))
+ }
+
+ @Test
+ fun `page sets correct homepage in template context`() {
+ page.processTemplate(freenetRequest, templateContext)
+ assertThat(templateContext["homepage"], equalTo<Any>(homepage))
+ }
+
+ @Test
+ fun `page sets correct year in template context`() {
+ page.processTemplate(freenetRequest, templateContext)
+ assertThat(templateContext["year"], equalTo<Any>(year))
+ }
+
+ @Test
+ fun `page can be created by guice`() {
+ assertThat(injector.getInstance<AboutPage>(), notNullValue())
+ }
+
+ @Test
+ fun `page is created as singleton`() {
+ val firstInstance = injector.getInstance<AboutPage>()
+ val secondInstance = injector.getInstance<AboutPage>()
+ assertThat(firstInstance, sameInstance(secondInstance))
+ }
+
+}