2 * Sone - RemotePostReplyHandlerTest.kt - Copyright © 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.notify.*
25 import net.pterodactylus.util.template.*
26 import org.hamcrest.MatcherAssert.*
27 import org.hamcrest.Matchers.*
31 * Unit test for [RemotePostReplyHandler].
33 class RemotePostReplyHandlerTest {
35 private val notification = ListNotification<PostReply>("", "", Template())
36 private val notificationHandlerTester = NotificationHandlerTester { RemotePostReplyHandler(it, notification) }
37 private val postReply = createPostReply()
40 fun `reply is added to notification on new reply`() {
41 notificationHandlerTester.sendEvent(NewPostReplyFoundEvent(postReply))
42 assertThat(notification.elements, hasItem<PostReply>(postReply))
46 fun `notification is added to manager on new reply`() {
47 notificationHandlerTester.sendEvent(NewPostReplyFoundEvent(postReply))
48 assertThat(notificationHandlerTester.notifications, hasItem<Notification>(notification))
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)))
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)))
66 fun `reply is not added to notification on new local reply`() {
67 val postReply = createPostReply(sone = localSone1)
68 notificationHandlerTester.sendEvent(NewPostReplyFoundEvent(postReply))
69 assertThat(notification.elements, not(hasItem<PostReply>(postReply)))
73 fun `notification is not added to manager on new local reply`() {
74 val postReply = createPostReply(sone = localSone1)
75 notificationHandlerTester.sendEvent(NewPostReplyFoundEvent(postReply))
76 assertThat(notificationHandlerTester.notifications, not(hasItem<Notification>(notification)))
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)))
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)))