🚧 Add notification manager to web interface module
authorDavid ‘Bombe’ Roden <bombe@pterodactylus.net>
Fri, 29 Nov 2019 16:30:45 +0000 (17:30 +0100)
committerDavid ‘Bombe’ Roden <bombe@pterodactylus.net>
Fri, 29 Nov 2019 17:27:14 +0000 (18:27 +0100)
src/main/java/net/pterodactylus/sone/web/WebInterface.java
src/main/kotlin/net/pterodactylus/sone/web/WebInterfaceModule.kt
src/test/kotlin/net/pterodactylus/sone/web/WebInterfaceModuleTest.kt

index e31d9a8..bcc7a11 100644 (file)
@@ -124,7 +124,7 @@ public class WebInterface implements SessionProvider {
        private final Loaders loaders;
 
        /** The notification manager. */
-       private final NotificationManager notificationManager = new NotificationManager();
+       private final NotificationManager notificationManager;
 
        /** The Sone plugin. */
        private final SonePlugin sonePlugin;
@@ -207,7 +207,8 @@ public class WebInterface implements SessionProvider {
                        ParserFilter parserFilter, ShortenFilter shortenFilter,
                        RenderFilter renderFilter,
                        LinkedElementRenderFilter linkedElementRenderFilter,
-                       PageToadletRegistry pageToadletRegistry, MetricRegistry metricRegistry, Translation translation, L10nFilter l10nFilter) {
+                       PageToadletRegistry pageToadletRegistry, MetricRegistry metricRegistry, Translation translation, L10nFilter l10nFilter,
+                       NotificationManager notificationManager) {
                this.sonePlugin = sonePlugin;
                this.loaders = loaders;
                this.listNotificationFilter = listNotificationFilter;
@@ -223,6 +224,7 @@ public class WebInterface implements SessionProvider {
                this.metricRegistry = metricRegistry;
                this.l10nFilter = l10nFilter;
                this.translation = translation;
+               this.notificationManager = notificationManager;
                formPassword = sonePlugin.pluginRespirator().getToadletContainer().getFormPassword();
                soneTextParser = new SoneTextParser(getCore(), getCore());
 
index c996e30..3d87aa7 100644 (file)
@@ -10,6 +10,7 @@ import net.pterodactylus.sone.freenet.wot.*
 import net.pterodactylus.sone.main.*
 import net.pterodactylus.sone.template.*
 import net.pterodactylus.sone.text.*
+import net.pterodactylus.util.notify.*
 import net.pterodactylus.util.template.*
 import javax.inject.*
 import javax.inject.Singleton
@@ -126,4 +127,9 @@ class WebInterfaceModule : AbstractModule() {
        @Named("toadletPathPrefix")
        fun getPathPrefix(): String = "/Sone/"
 
+       @Provides
+       @Singleton
+       fun getNotificationManager() =
+                       NotificationManager()
+
 }
index 14427ef..ec45e67 100644 (file)
@@ -15,6 +15,7 @@ import net.pterodactylus.sone.template.*
 import net.pterodactylus.sone.test.*
 import net.pterodactylus.sone.text.*
 import net.pterodactylus.sone.web.page.*
+import net.pterodactylus.util.notify.*
 import net.pterodactylus.util.template.*
 import net.pterodactylus.util.web.*
 import org.hamcrest.MatcherAssert.*
@@ -283,4 +284,11 @@ class WebInterfaceModuleTest {
            assertThat(injector.getInstance<PageToadletFactory>().createPageToadlet(page).path(), startsWith("/Sone/"))
        }
 
+       @Test
+       fun `notification manager is created as singleton`() {
+               val firstNotificationManager = injector.getInstance<NotificationManager>()
+               val secondNotificationManager = injector.getInstance<NotificationManager>()
+               assertThat(firstNotificationManager, sameInstance(secondNotificationManager))
+       }
+
 }