+
+ @Test
+ fun `detector does not emit removed event when a post without mention is marked as known`() {
+ val post = createPost()
+ eventBus.post(MarkPostKnownEvent(post))
+ assertThat(capturedRemovedEvents, emptyIterable())
+ }
+
+ @Test
+ fun `detector does emit removed event when post with mention is marked as known`() {
+ val post = createPost("sone://${localSone1.id}")
+ eventBus.post(NewPostFoundEvent(post))
+ eventBus.post(MarkPostKnownEvent(post))
+ assertThat(capturedRemovedEvents, contains(MentionOfLocalSoneRemovedEvent(post)))
+ }
+
+ @Test
+ fun `detector does emit removed event when reply with mention is removed and no more mentions in that post exist`() {
+ val post = createPost()
+ val reply = emptyPostReply("sone://${localSone1.id}", post)
+ postReplyProvider.postReplies[post.id] = listOf(reply)
+ eventBus.post(NewPostReplyFoundEvent(reply))
+ eventBus.post(PostReplyRemovedEvent(reply))
+ assertThat(capturedRemovedEvents, contains(MentionOfLocalSoneRemovedEvent(post)))
+ }
+
+ @Test
+ fun `detector does not emit removed event when reply with mention is removed and post mentions local sone`() {
+ val post = createPost("sone://${localSone1.id}")
+ val reply = emptyPostReply("sone://${localSone1.id}", post)
+ eventBus.post(NewPostReplyFoundEvent(reply))
+ eventBus.post(PostReplyRemovedEvent(reply))
+ assertThat(capturedRemovedEvents, emptyIterable())
+ }
+
+ @Test
+ fun `detector does emit removed event when reply with mention is removed and post mentions local sone but is known`() {
+ val post = createPost("sone://${localSone1.id}", known = true)
+ val reply = emptyPostReply("sone://${localSone1.id}", post)
+ eventBus.post(NewPostReplyFoundEvent(reply))
+ eventBus.post(PostReplyRemovedEvent(reply))
+ assertThat(capturedRemovedEvents, contains(MentionOfLocalSoneRemovedEvent(post)))
+ }
+
+ @Test
+ fun `detector does not emit removed event when reply with mention is removed and post has other replies with mentions`() {
+ val post = createPost()
+ val reply1 = emptyPostReply("sone://${localSone1.id}", post)
+ val reply2 = emptyPostReply("sone://${localSone1.id}", post)
+ postReplyProvider.postReplies[post.id] = listOf(reply1, reply2)
+ eventBus.post(NewPostReplyFoundEvent(reply1))
+ eventBus.post(PostReplyRemovedEvent(reply1))
+ assertThat(capturedRemovedEvents, emptyIterable())
+ }
+
+ @Test
+ fun `detector does emit removed event when reply with mention is removed and post has other replies with mentions which are known`() {
+ val post = createPost()
+ val reply1 = emptyPostReply("sone://${localSone1.id}", post)
+ val reply2 = emptyPostReply("sone://${localSone1.id}", post, known = true)
+ postReplyProvider.postReplies[post.id] = listOf(reply1, reply2)
+ eventBus.post(NewPostReplyFoundEvent(reply1))
+ eventBus.post(PostReplyRemovedEvent(reply1))
+ assertThat(capturedRemovedEvents, contains(MentionOfLocalSoneRemovedEvent(post)))
+ }
+