🔀 Merge branch 'release/v82'
[Sone.git] / src / test / kotlin / net / pterodactylus / sone / web / notification / LocalReplyHandlerTest.kt
1 /**
2  * Sone - LocalReplyHandlerTest.kt - Copyright Â© 2019–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.template.*
25 import org.hamcrest.MatcherAssert.*
26 import org.hamcrest.Matchers.*
27 import kotlin.test.*
28
29 /**
30  * Unit test for [LocalReplyHandler].
31  */
32 class LocalReplyHandlerTest {
33
34         private val notification = ListNotification<PostReply>("", "", Template())
35         private val localReplyHandlerTester = NotificationHandlerTester { LocalReplyHandler(it, notification) }
36
37         @Test
38         fun `handler does not add reply to notification`() {
39                 localReplyHandlerTester.sendEvent(NewPostReplyFoundEvent(remoteReply))
40                 assertThat(notification.elements, emptyIterable())
41         }
42
43         @Test
44         fun `handler does add local reply to notification`() {
45                 localReplyHandlerTester.sendEvent(NewPostReplyFoundEvent(localReply))
46                 assertThat(notification.elements, contains(localReply))
47         }
48
49         @Test
50         fun `handler adds notification to manager`() {
51                 localReplyHandlerTester.sendEvent(NewPostReplyFoundEvent(localReply))
52                 assertThat(localReplyHandlerTester.notifications, hasItem(notification))
53         }
54
55         @Test
56         fun `handler does not add notification to manager for remote reply`() {
57                 localReplyHandlerTester.sendEvent(NewPostReplyFoundEvent(remoteReply))
58                 assertThat(localReplyHandlerTester.notifications, not(hasItem(notification)))
59         }
60
61         @Test
62         fun `handler does not add notification to manager during first start`() {
63                 localReplyHandlerTester.firstStart()
64                 localReplyHandlerTester.sendEvent(NewPostReplyFoundEvent(localReply))
65                 assertThat(localReplyHandlerTester.notifications, not(hasItem(notification)))
66         }
67
68         @Test
69         fun `handler removes reply from notification if reply is removed`() {
70                 notification.add(localReply)
71                 localReplyHandlerTester.sendEvent(PostReplyRemovedEvent(localReply))
72                 assertThat(notification.elements, not(hasItem(localReply)))
73         }
74
75         @Test
76         fun `handler removes reply from notification if reply is marked as known`() {
77                 notification.add(localReply)
78                 localReplyHandlerTester.sendEvent(MarkPostReplyKnownEvent(localReply))
79                 assertThat(notification.elements, not(hasItem(localReply)))
80         }
81
82 }
83
84 private val localReply = emptyPostReply(sone = localSone1)
85 private val remoteReply = emptyPostReply()