2 * Sone - NotificationHandlerModuleTest.kt - Copyright © 2019 David ‘Bombe’ Roden
4 * This program is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation, either version 3 of the License, or
7 * (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program. If not, see <http://www.gnu.org/licenses/>.
18 package net.pterodactylus.sone.web.notification
20 import com.google.inject.*
21 import com.google.inject.Guice.*
22 import net.pterodactylus.sone.core.*
23 import net.pterodactylus.sone.core.event.*
24 import net.pterodactylus.sone.data.*
25 import net.pterodactylus.sone.test.*
26 import net.pterodactylus.util.notify.*
27 import org.hamcrest.MatcherAssert.*
28 import org.hamcrest.Matchers.*
29 import org.mockito.Mockito.*
34 * Unit test for [NotificationHandlerModule].
36 class NotificationHandlerModuleTest {
38 private val core = mock<Core>()
39 private val notificationManager = NotificationManager()
40 private val injector: Injector = createInjector(
41 Core::class.isProvidedBy(core),
42 NotificationManager::class.isProvidedBy(notificationManager),
43 NotificationHandlerModule()
47 fun `module can create notification handler`() {
48 assertThat(injector.getInstance<NotificationHandler>(), notNullValue())
52 fun `module can create mark-post-known-during-first-start handler`() {
53 assertThat(injector.getInstance<MarkPostKnownDuringFirstStartHandler>(), notNullValue())
57 fun `mark-post-known-during-first-start handler is created with correct action`() {
58 notificationManager.addNotification(object : AbstractNotification("first-start-notification") {
59 override fun render(writer: Writer?) = Unit
61 val handler = injector.getInstance<MarkPostKnownDuringFirstStartHandler>()
62 val post = mock<Post>()
63 handler.newPostFound(NewPostFoundEvent(post))
64 verify(core).markPostKnown(post)