2 * Sone - LocalReplyHandlerTest.kt - Copyright © 2019–2020 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 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.*
30 * Unit test for [LocalReplyHandler].
32 class LocalReplyHandlerTest {
34 private val notification = ListNotification<PostReply>("", "", Template())
35 private val localReplyHandlerTester = NotificationHandlerTester { LocalReplyHandler(it, notification) }
38 fun `handler does not add reply to notification`() {
39 localReplyHandlerTester.sendEvent(NewPostReplyFoundEvent(remoteReply))
40 assertThat(notification.elements, emptyIterable())
44 fun `handler does add local reply to notification`() {
45 localReplyHandlerTester.sendEvent(NewPostReplyFoundEvent(localReply))
46 assertThat(notification.elements, contains(localReply))
50 fun `handler adds notification to manager`() {
51 localReplyHandlerTester.sendEvent(NewPostReplyFoundEvent(localReply))
52 assertThat(localReplyHandlerTester.notifications, hasItem(notification))
56 fun `handler does not add notification to manager for remote reply`() {
57 localReplyHandlerTester.sendEvent(NewPostReplyFoundEvent(remoteReply))
58 assertThat(localReplyHandlerTester.notifications, not(hasItem(notification)))
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)))
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)))
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)))
84 private val localReply = createPostReply(sone = localSone1)
85 private val remoteReply = createPostReply()