📄 Update year in file headers
[Sone.git] / src / test / kotlin / net / pterodactylus / sone / text / SoneMentionDetectorTest.kt
index 6ae437b..552b7ee 100644 (file)
@@ -1,5 +1,5 @@
 /**
- * Sone - SoneMentionDetectorTest.kt - Copyright Â© 2019 David â€˜Bombe’ Roden
+ * Sone - SoneMentionDetectorTest.kt - Copyright Â© 2019–2020 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
@@ -32,7 +32,8 @@ import kotlin.test.*
 @Suppress("UnstableApiUsage")
 class SoneMentionDetectorTest {
 
-       private val eventBus = EventBus()
+       private val caughtExceptions = mutableListOf<Throwable>()
+       private val eventBus = EventBus { exception, _ -> caughtExceptions += exception }
        private val soneProvider = TestSoneProvider()
        private val postProvider = TestPostProvider()
        private val soneTextParser = SoneTextParser(soneProvider, postProvider)
@@ -143,6 +144,14 @@ class SoneMentionDetectorTest {
        }
 
        @Test
+       fun `detector does not emit event for reply without post`() {
+               val reply = emptyPostReply("text mentions sone://${localSone1.id} and sone://${localSone2.id}.", post = null)
+               eventBus.post(NewPostReplyFoundEvent(reply))
+               assertThat(caughtExceptions, emptyIterable())
+               assertThat(capturedFoundEvents, emptyIterable())
+       }
+
+       @Test
        fun `detector does not emit removed event when a post without mention is removed`() {
                val post = createPost()
                eventBus.post(PostRemovedEvent(post))