From abeef6f40c92fd3a14da85af5d160ab7bb7c5102 Mon Sep 17 00:00:00 2001 From: =?utf8?q?David=20=E2=80=98Bombe=E2=80=99=20Roden?= Date: Mon, 2 Dec 2019 20:55:51 +0100 Subject: [PATCH] =?utf8?q?=E2=9C=A8=20Add=20notification=20handler=20modul?= =?utf8?q?e?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- .../web/notification/NotificationHandlerModule.kt | 33 +++++++++++ .../notification/NotificationHandlerModuleTest.kt | 67 ++++++++++++++++++++++ 2 files changed, 100 insertions(+) create mode 100644 src/main/kotlin/net/pterodactylus/sone/web/notification/NotificationHandlerModule.kt create mode 100644 src/test/kotlin/net/pterodactylus/sone/web/notification/NotificationHandlerModuleTest.kt 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) + } + +} -- 2.7.4