From: David ‘Bombe’ Roden Date: Mon, 2 Dec 2019 19:56:40 +0000 (+0100) Subject: 🎨 Turn notification handler into an empty husk X-Git-Tag: v81^2~5^2~87 X-Git-Url: https://git.pterodactylus.net/?a=commitdiff_plain;h=a97cd8b63c632cf2dc21cc51fa37454baf062a99;p=Sone.git 🎨 Turn notification handler into an empty husk --- diff --git a/src/main/kotlin/net/pterodactylus/sone/web/notification/NotificationHandler.kt b/src/main/kotlin/net/pterodactylus/sone/web/notification/NotificationHandler.kt index 37df1ac..9863013 100644 --- a/src/main/kotlin/net/pterodactylus/sone/web/notification/NotificationHandler.kt +++ b/src/main/kotlin/net/pterodactylus/sone/web/notification/NotificationHandler.kt @@ -17,23 +17,13 @@ package net.pterodactylus.sone.web.notification -import com.google.common.eventbus.* -import net.pterodactylus.sone.main.* -import net.pterodactylus.util.notify.* import javax.inject.* /** - * Handler for notifications that can create notifications and register them with an event bus. + * Container that causes notification handlers to be created and (more importantly) registered + * on creation with the event bus. */ -@Suppress("UnstableApiUsage") -class NotificationHandler @Inject constructor(private val eventBus: EventBus, private val loaders: Loaders, private val notificationManager: NotificationManager) { - - fun start() { - register { SoneLockedOnStartupHandler(it, loaders.loadTemplate("/templates/notify/soneLockedOnStartupNotification.html")) } - register { NewSoneHandler(it, loaders.loadTemplate("/templates/notify/newSoneNotification.html")) } - } - - private fun register(handler: (NotificationManager) -> Any) = - handler(notificationManager).also(eventBus::register) - -} +@Suppress("UNUSED_PARAMETER") +class NotificationHandler @Inject constructor( + markPostKnownDuringFirstStartHandler: MarkPostKnownDuringFirstStartHandler +) diff --git a/src/test/kotlin/net/pterodactylus/sone/web/notification/NotificationHandlerTest.kt b/src/test/kotlin/net/pterodactylus/sone/web/notification/NotificationHandlerTest.kt deleted file mode 100644 index a0ccb9d..0000000 --- a/src/test/kotlin/net/pterodactylus/sone/web/notification/NotificationHandlerTest.kt +++ /dev/null @@ -1,106 +0,0 @@ -/** - * Sone - NotificationHandlerTest.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.common.eventbus.* -import com.google.inject.Guice.* -import net.pterodactylus.sone.main.* -import net.pterodactylus.sone.test.* -import net.pterodactylus.util.notify.* -import net.pterodactylus.util.template.* -import net.pterodactylus.util.web.* -import org.hamcrest.MatcherAssert.* -import org.hamcrest.Matchers.* -import kotlin.test.* - -/** - * Unit test for [NotificationHandler]. - */ -class NotificationHandlerTest { - - private val eventBus = TestEventBus() - private val loaders = TestLoaders() - private val notificationManager = NotificationManager() - private val handler = NotificationHandler(eventBus, loaders, notificationManager) - - @Test - fun `notification handler can be created by guice`() { - val injector = createInjector( - EventBus::class.isProvidedBy(eventBus), - NotificationManager::class.isProvidedBy(notificationManager), - Loaders::class.isProvidedBy(loaders) - ) - assertThat(injector.getInstance(), notNullValue()) - } - - @Test - fun `notification handler registers handler for sone-locked event`() { - handler.start() - assertThat(eventBus.registeredObjects, hasItem(matches { it.javaClass == SoneLockedOnStartupHandler::class.java })) - } - - @Test - fun `notification handler loads sone-locked notification template`() { - handler.start() - assertThat(loaders.requestedTemplatePaths, hasItem("/templates/notify/soneLockedOnStartupNotification.html")) - } - - @Test - fun `notification handler registers handler for new sone events`() { - handler.start() - assertThat(eventBus.registeredObjects, hasItem(matches { it.javaClass == NewSoneHandler::class.java })) - } - - @Test - fun `notification handler loads new sone notification template`() { - handler.start() - assertThat(loaders.requestedTemplatePaths, hasItem("/templates/notify/newSoneNotification.html")) - } - -} - -@Suppress("UnstableApiUsage") -private class TestEventBus : EventBus() { - private val _registeredObjects = mutableListOf() - val registeredObjects: List - get() = _registeredObjects - - override fun register(`object`: Any) { - super.register(`object`) - _registeredObjects += `object` - } - -} - -private class TestLoaders : Loaders { - val requestedTemplatePaths = mutableListOf() - - override fun loadTemplate(path: String) = - Template().also { requestedTemplatePaths += path } - - override fun loadStaticPage(basePath: String, prefix: String, mimeType: String) = object : Page { - - override fun getPath() = "" - override fun isPrefixPage() = false - override fun handleRequest(request: REQ, response: Response) = response - - } - - override fun getTemplateProvider() = TemplateProvider { _, _ -> Template() } - -}