d2106d8cedf4a28e01497392c597f52a1098a7fd
[Sone.git] / src / test / kotlin / net / pterodactylus / sone / web / notification / NotificationHandlerModuleTest.kt
1 /**
2  * Sone - NotificationHandlerModuleTest.kt - Copyright © 2019 David ‘Bombe’ Roden
3  *
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.
8  *
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.
13  *
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/>.
16  */
17
18 package net.pterodactylus.sone.web.notification
19
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.*
30 import java.io.*
31 import kotlin.test.*
32
33 /**
34  * Unit test for [NotificationHandlerModule].
35  */
36 class NotificationHandlerModuleTest {
37
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()
44         )
45
46         @Test
47         fun `module can create notification handler`() {
48                 assertThat(injector.getInstance<NotificationHandler>(), notNullValue())
49         }
50
51         @Test
52         fun `module can create mark-post-known-during-first-start handler`() {
53                 assertThat(injector.getInstance<MarkPostKnownDuringFirstStartHandler>(), notNullValue())
54         }
55
56         @Test
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
60                 })
61                 val handler = injector.getInstance<MarkPostKnownDuringFirstStartHandler>()
62                 val post = mock<Post>()
63                 handler.newPostFound(NewPostFoundEvent(post))
64                 verify(core).markPostKnown(post)
65         }
66
67 }