✨ Add notification handler module
authorDavid ‘Bombe’ Roden <bombe@pterodactylus.net>
Mon, 2 Dec 2019 19:55:51 +0000 (20:55 +0100)
committerDavid ‘Bombe’ Roden <bombe@pterodactylus.net>
Wed, 11 Dec 2019 15:58:54 +0000 (16:58 +0100)
src/main/kotlin/net/pterodactylus/sone/web/notification/NotificationHandlerModule.kt [new file with mode: 0644]
src/test/kotlin/net/pterodactylus/sone/web/notification/NotificationHandlerModuleTest.kt [new file with mode: 0644]

diff --git a/src/main/kotlin/net/pterodactylus/sone/web/notification/NotificationHandlerModule.kt b/src/main/kotlin/net/pterodactylus/sone/web/notification/NotificationHandlerModule.kt
new file mode 100644 (file)
index 0000000..5f3af43
--- /dev/null
@@ -0,0 +1,33 @@
+/**
+ * Sone - NotificationHandlerModuleTest.kt - Copyright © 2019 David ‘Bombe’ 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.notification
+
+import com.google.inject.*
+import net.pterodactylus.sone.core.*
+import net.pterodactylus.util.notify.*
+
+/**
+ * Guice module for creating all notification handlers.
+ */
+class NotificationHandlerModule : AbstractModule() {
+
+       @Provides
+       fun getMarkPostKnownDuringFirstStartHandler(core: Core, notificationManager: NotificationManager) =
+                       MarkPostKnownDuringFirstStartHandler(notificationManager, core::markPostKnown)
+
+}
diff --git a/src/test/kotlin/net/pterodactylus/sone/web/notification/NotificationHandlerModuleTest.kt b/src/test/kotlin/net/pterodactylus/sone/web/notification/NotificationHandlerModuleTest.kt
new file mode 100644 (file)
index 0000000..d2106d8
--- /dev/null
@@ -0,0 +1,67 @@
+/**
+ * Sone - NotificationHandlerModuleTest.kt - Copyright © 2019 David ‘Bombe’ 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.notification
+
+import com.google.inject.*
+import com.google.inject.Guice.*
+import net.pterodactylus.sone.core.*
+import net.pterodactylus.sone.core.event.*
+import net.pterodactylus.sone.data.*
+import net.pterodactylus.sone.test.*
+import net.pterodactylus.util.notify.*
+import org.hamcrest.MatcherAssert.*
+import org.hamcrest.Matchers.*
+import org.mockito.Mockito.*
+import java.io.*
+import kotlin.test.*
+
+/**
+ * Unit test for [NotificationHandlerModule].
+ */
+class NotificationHandlerModuleTest {
+
+       private val core = mock<Core>()
+       private val notificationManager = NotificationManager()
+       private val injector: Injector = createInjector(
+                       Core::class.isProvidedBy(core),
+                       NotificationManager::class.isProvidedBy(notificationManager),
+                       NotificationHandlerModule()
+       )
+
+       @Test
+       fun `module can create notification handler`() {
+               assertThat(injector.getInstance<NotificationHandler>(), notNullValue())
+       }
+
+       @Test
+       fun `module can create mark-post-known-during-first-start handler`() {
+               assertThat(injector.getInstance<MarkPostKnownDuringFirstStartHandler>(), notNullValue())
+       }
+
+       @Test
+       fun `mark-post-known-during-first-start handler is created with correct action`() {
+               notificationManager.addNotification(object : AbstractNotification("first-start-notification") {
+                       override fun render(writer: Writer?) = Unit
+               })
+               val handler = injector.getInstance<MarkPostKnownDuringFirstStartHandler>()
+               val post = mock<Post>()
+               handler.newPostFound(NewPostFoundEvent(post))
+               verify(core).markPostKnown(post)
+       }
+
+}