X-Git-Url: https://git.pterodactylus.net/?a=blobdiff_plain;ds=inline;f=src%2Ftest%2Fkotlin%2Fnet%2Fpterodactylus%2Fsone%2Fweb%2Fnotification%2FLocalReplyHandlerTest.kt;fp=src%2Ftest%2Fkotlin%2Fnet%2Fpterodactylus%2Fsone%2Fweb%2Fnotification%2FLocalReplyHandlerTest.kt;h=750d08370541e2c6719e30a71357865134895f30;hb=79ef6e4644845290d9feb45a06f8588864dd0a83;hp=0000000000000000000000000000000000000000;hpb=c7a324e45e46ac629a5a3da5c3458bc66d18938f;p=Sone.git
diff --git a/src/test/kotlin/net/pterodactylus/sone/web/notification/LocalReplyHandlerTest.kt b/src/test/kotlin/net/pterodactylus/sone/web/notification/LocalReplyHandlerTest.kt
new file mode 100644
index 0000000..750d083
--- /dev/null
+++ b/src/test/kotlin/net/pterodactylus/sone/web/notification/LocalReplyHandlerTest.kt
@@ -0,0 +1,85 @@
+/**
+ * Sone - LocalReplyHandlerTest.kt - Copyright © 2019 David âBombeâ Roden
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see .
+ */
+
+package net.pterodactylus.sone.web.notification
+
+import net.pterodactylus.sone.core.event.*
+import net.pterodactylus.sone.data.*
+import net.pterodactylus.sone.notify.*
+import net.pterodactylus.sone.test.*
+import net.pterodactylus.util.template.*
+import org.hamcrest.MatcherAssert.*
+import org.hamcrest.Matchers.*
+import kotlin.test.*
+
+/**
+ * Unit test for [LocalReplyHandler].
+ */
+class LocalReplyHandlerTest {
+
+ private val notification = ListNotification("", "", Template())
+ private val localReplyHandlerTester = NotificationHandlerTester { LocalReplyHandler(it, notification) }
+
+ @Test
+ fun `handler does not add reply to notification`() {
+ localReplyHandlerTester.sendEvent(NewPostReplyFoundEvent(remoteReply))
+ assertThat(notification.elements, emptyIterable())
+ }
+
+ @Test
+ fun `handler does add local reply to notification`() {
+ localReplyHandlerTester.sendEvent(NewPostReplyFoundEvent(localReply))
+ assertThat(notification.elements, contains(localReply))
+ }
+
+ @Test
+ fun `handler adds notification to manager`() {
+ localReplyHandlerTester.sendEvent(NewPostReplyFoundEvent(localReply))
+ assertThat(localReplyHandlerTester.notifications, hasItem(notification))
+ }
+
+ @Test
+ fun `handler does not add notification to manager for remote reply`() {
+ localReplyHandlerTester.sendEvent(NewPostReplyFoundEvent(remoteReply))
+ assertThat(localReplyHandlerTester.notifications, not(hasItem(notification)))
+ }
+
+ @Test
+ fun `handler does not add notification to manager during first start`() {
+ localReplyHandlerTester.firstStart()
+ localReplyHandlerTester.sendEvent(NewPostReplyFoundEvent(localReply))
+ assertThat(localReplyHandlerTester.notifications, not(hasItem(notification)))
+ }
+
+ @Test
+ fun `handler removes reply from notification if reply is removed`() {
+ notification.add(localReply)
+ localReplyHandlerTester.sendEvent(PostReplyRemovedEvent(localReply))
+ assertThat(notification.elements, not(hasItem(localReply)))
+ }
+
+ @Test
+ fun `handler removes reply from notification if reply is marked as known`() {
+ notification.add(localReply)
+ localReplyHandlerTester.sendEvent(MarkPostReplyKnownEvent(localReply))
+ assertThat(notification.elements, not(hasItem(localReply)))
+ }
+
+}
+
+private val localReply = emptyPostReply(sone = localSone1)
+private val remoteReply = emptyPostReply()