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

index 3d87aa7..63f3fc6 100644 (file)
@@ -1,5 +1,6 @@
 package net.pterodactylus.sone.web
 
+import com.google.common.eventbus.*
 import com.google.inject.*
 import freenet.support.api.*
 import net.pterodactylus.sone.core.*
@@ -10,6 +11,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.sone.web.notification.*
 import net.pterodactylus.util.notify.*
 import net.pterodactylus.util.template.*
 import javax.inject.*
@@ -132,4 +134,9 @@ class WebInterfaceModule : AbstractModule() {
        fun getNotificationManager() =
                        NotificationManager()
 
+       @Provides
+       @Singleton
+       fun getNotificationHandler(eventBus: EventBus, loaders: Loaders, notificationManager: NotificationManager) =
+                       NotificationHandler(eventBus, loaders, notificationManager)
+
 }
index ec45e67..2bb31c9 100644 (file)
@@ -14,6 +14,7 @@ import net.pterodactylus.sone.main.*
 import net.pterodactylus.sone.template.*
 import net.pterodactylus.sone.test.*
 import net.pterodactylus.sone.text.*
+import net.pterodactylus.sone.web.notification.*
 import net.pterodactylus.sone.web.page.*
 import net.pterodactylus.util.notify.*
 import net.pterodactylus.util.template.*
@@ -291,4 +292,16 @@ class WebInterfaceModuleTest {
                assertThat(firstNotificationManager, sameInstance(secondNotificationManager))
        }
 
+       @Test
+       fun `notification handler can be created`() {
+               assertThat(injector.getInstance<NotificationHandler>(), notNullValue())
+       }
+
+       @Test
+       fun `notification handler is created as singleton`() {
+               val firstNotificationHandler = injector.getInstance<NotificationHandler>()
+               val secondNotificationHandler = injector.getInstance<NotificationHandler>()
+               assertThat(firstNotificationHandler, sameInstance(secondNotificationHandler))
+       }
+
 }