From: David ‘Bombe’ Roden Date: Mon, 2 Dec 2019 19:55:51 +0000 (+0100) Subject: ✨ Add notification handler module X-Git-Tag: v81^2~5^2~88 X-Git-Url: https://git.pterodactylus.net/?a=commitdiff_plain;h=abeef6f40c92fd3a14da85af5d160ab7bb7c5102;p=Sone.git ✨ Add notification handler module --- 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 index 0000000..5f3af43 --- /dev/null +++ b/src/main/kotlin/net/pterodactylus/sone/web/notification/NotificationHandlerModule.kt @@ -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 . + */ + +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 index 0000000..d2106d8 --- /dev/null +++ b/src/test/kotlin/net/pterodactylus/sone/web/notification/NotificationHandlerModuleTest.kt @@ -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 . + */ + +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() + 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(), notNullValue()) + } + + @Test + fun `module can create mark-post-known-during-first-start handler`() { + assertThat(injector.getInstance(), 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() + val post = mock() + handler.newPostFound(NewPostFoundEvent(post)) + verify(core).markPostKnown(post) + } + +}