}
}
-fun emptyPostReply(text: String = "", post: Post = createPost(), sone: Sone = remoteSone1, known: Boolean = false) = object : PostReply {
+fun emptyPostReply(text: String = "", post: Post? = createPost(), sone: Sone = remoteSone1, known: Boolean = false) = object : PostReply {
override val id = "reply-id"
override fun getSone() = sone
- override fun getPostId() = post.id
- override fun getPost(): Optional<Post> = Optional.of(post)
+ override fun getPostId() = post!!.id
+ override fun getPost(): Optional<Post> = Optional.fromNullable(post)
override fun getTime() = 1L
override fun getText() = text
override fun isKnown() = known
@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)
}
@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))