🔀 Merge “release/v81” into “master”
[Sone.git] / src / test / kotlin / net / pterodactylus / sone / web / notification / RemotePostReplyHandlerTest.kt
1 /**
2  * Sone - RemotePostReplyHandlerTest.kt - Copyright © 2020 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 net.pterodactylus.sone.core.event.*
21 import net.pterodactylus.sone.data.*
22 import net.pterodactylus.sone.notify.*
23 import net.pterodactylus.sone.test.*
24 import net.pterodactylus.util.notify.*
25 import net.pterodactylus.util.template.*
26 import org.hamcrest.MatcherAssert.*
27 import org.hamcrest.Matchers.*
28 import kotlin.test.*
29
30 /**
31  * Unit test for [RemotePostReplyHandler].
32  */
33 class RemotePostReplyHandlerTest {
34
35         private val notification = ListNotification<PostReply>("", "", Template())
36         private val notificationHandlerTester = NotificationHandlerTester { RemotePostReplyHandler(it, notification) }
37         private val postReply = emptyPostReply()
38
39         @Test
40         fun `reply is added to notification on new reply`() {
41                 notificationHandlerTester.sendEvent(NewPostReplyFoundEvent(postReply))
42                 assertThat(notification.elements, hasItem<PostReply>(postReply))
43         }
44
45         @Test
46         fun `notification is added to manager on new reply`() {
47                 notificationHandlerTester.sendEvent(NewPostReplyFoundEvent(postReply))
48                 assertThat(notificationHandlerTester.notifications, hasItem<Notification>(notification))
49         }
50
51         @Test
52         fun `reply is not added to notification on new reply during first start`() {
53                 notificationHandlerTester.firstStart()
54                 notificationHandlerTester.sendEvent(NewPostReplyFoundEvent(postReply))
55                 assertThat(notification.elements, not(hasItem<PostReply>(postReply)))
56         }
57
58         @Test
59         fun `notification is not added to manager on new reply during first start`() {
60                 notificationHandlerTester.firstStart()
61                 notificationHandlerTester.sendEvent(NewPostReplyFoundEvent(postReply))
62                 assertThat(notificationHandlerTester.notifications, not(hasItem<Notification>(notification)))
63         }
64
65         @Test
66         fun `reply is not added to notification on new local reply`() {
67                 val postReply = emptyPostReply(sone = localSone1)
68                 notificationHandlerTester.sendEvent(NewPostReplyFoundEvent(postReply))
69                 assertThat(notification.elements, not(hasItem<PostReply>(postReply)))
70         }
71
72         @Test
73         fun `notification is not added to manager on new local reply`() {
74                 val postReply = emptyPostReply(sone = localSone1)
75                 notificationHandlerTester.sendEvent(NewPostReplyFoundEvent(postReply))
76                 assertThat(notificationHandlerTester.notifications, not(hasItem<Notification>(notification)))
77         }
78
79         @Test
80         fun `reply is removed from notification when removed`() {
81                 notification.add(postReply)
82                 notificationHandlerTester.sendEvent(PostReplyRemovedEvent(postReply))
83                 assertThat(notification.elements, not(hasItem<PostReply>(postReply)))
84         }
85
86         @Test
87         fun `reply is removed from notification when marked as known`() {
88                 notification.add(postReply)
89                 notificationHandlerTester.sendEvent(MarkPostReplyKnownEvent(postReply))
90                 assertThat(notification.elements, not(hasItem<PostReply>(postReply)))
91         }
92
93 }