🚚 Rename local-sone-mentioned event
authorDavid ‘Bombe’ Roden <bombe@pterodactylus.net>
Sat, 4 Jan 2020 21:50:00 +0000 (22:50 +0100)
committerDavid ‘Bombe’ Roden <bombe@pterodactylus.net>
Sat, 4 Jan 2020 21:50:00 +0000 (22:50 +0100)
src/main/kotlin/net/pterodactylus/sone/core/event/LocalSoneMentionedInPostEvent.kt [deleted file]
src/main/kotlin/net/pterodactylus/sone/core/event/MentionOfLocalSoneFoundEvent.kt [new file with mode: 0644]
src/main/kotlin/net/pterodactylus/sone/text/SoneMentionDetector.kt
src/test/kotlin/net/pterodactylus/sone/text/SoneMentionDetectorTest.kt

diff --git a/src/main/kotlin/net/pterodactylus/sone/core/event/LocalSoneMentionedInPostEvent.kt b/src/main/kotlin/net/pterodactylus/sone/core/event/LocalSoneMentionedInPostEvent.kt
deleted file mode 100644 (file)
index 3e644e0..0000000
+++ /dev/null
@@ -1,27 +0,0 @@
-/**
- * Sone - LocalSoneMentionedInPostEvent.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 <http://www.gnu.org/licenses/>.
- */
-
-package net.pterodactylus.sone.core.event
-
-import net.pterodactylus.sone.data.*
-
-/**
- * Event that signals that a new post or reply was found that mentioned a local
- * Sone, which happens if the [SoneTextParser] locates a [SonePart] in a post
- * or reply.
- */
-data class LocalSoneMentionedInPostEvent(val post: Post)
diff --git a/src/main/kotlin/net/pterodactylus/sone/core/event/MentionOfLocalSoneFoundEvent.kt b/src/main/kotlin/net/pterodactylus/sone/core/event/MentionOfLocalSoneFoundEvent.kt
new file mode 100644 (file)
index 0000000..b63203b
--- /dev/null
@@ -0,0 +1,27 @@
+/**
+ * Sone - MentionOfLocalSoneFoundEvent.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 <http://www.gnu.org/licenses/>.
+ */
+
+package net.pterodactylus.sone.core.event
+
+import net.pterodactylus.sone.data.*
+
+/**
+ * Event that signals that a new post or reply was found that mentioned a local
+ * Sone, which happens if the [SoneTextParser] locates a [SonePart] in a post
+ * or reply.
+ */
+data class MentionOfLocalSoneFoundEvent(val post: Post)
index 32d311d..f3d8cb4 100644 (file)
@@ -24,7 +24,7 @@ import javax.inject.*
 
 /**
  * Listens to [NewPostFoundEvent]s and [NewPostReplyFoundEvent], parses the
 
 /**
  * Listens to [NewPostFoundEvent]s and [NewPostReplyFoundEvent], parses the
- * texts and emits a [LocalSoneMentionedInPostEvent] if a [SoneTextParser]
+ * texts and emits a [MentionOfLocalSoneFoundEvent] if a [SoneTextParser]
  * finds a [SonePart] that points to a local [Sone].
  */
 class SoneMentionDetector @Inject constructor(private val eventBus: EventBus, private val soneTextParser: SoneTextParser) {
  * finds a [SonePart] that points to a local [Sone].
  */
 class SoneMentionDetector @Inject constructor(private val eventBus: EventBus, private val soneTextParser: SoneTextParser) {
@@ -35,7 +35,7 @@ class SoneMentionDetector @Inject constructor(private val eventBus: EventBus, pr
                        post.sone.isLocal.onFalse {
                                val parts = soneTextParser.parse(post.text, null)
                                if (parts.filterIsInstance<SonePart>().any { it.sone.isLocal }) {
                        post.sone.isLocal.onFalse {
                                val parts = soneTextParser.parse(post.text, null)
                                if (parts.filterIsInstance<SonePart>().any { it.sone.isLocal }) {
-                                       eventBus.post(LocalSoneMentionedInPostEvent(post))
+                                       eventBus.post(MentionOfLocalSoneFoundEvent(post))
                                }
                        }
                }
                                }
                        }
                }
@@ -46,7 +46,7 @@ class SoneMentionDetector @Inject constructor(private val eventBus: EventBus, pr
                event.postReply.let { postReply ->
                        postReply.sone.isLocal.onFalse {
                                if (soneTextParser.parse(postReply.text, null).filterIsInstance<SonePart>().any { it.sone.isLocal }) {
                event.postReply.let { postReply ->
                        postReply.sone.isLocal.onFalse {
                                if (soneTextParser.parse(postReply.text, null).filterIsInstance<SonePart>().any { it.sone.isLocal }) {
-                                       postReply.post.let(::LocalSoneMentionedInPostEvent).also(eventBus::post)
+                                       postReply.post.let(::MentionOfLocalSoneFoundEvent).also(eventBus::post)
                                }
                        }
                }
                                }
                        }
                }
index 2003988..a56e5b5 100644 (file)
@@ -37,14 +37,14 @@ class SoneMentionDetectorTest {
        private val soneProvider = TestSoneProvider()
        private val postProvider = TestPostProvider()
        private val soneTextParser = SoneTextParser(soneProvider, postProvider)
        private val soneProvider = TestSoneProvider()
        private val postProvider = TestPostProvider()
        private val soneTextParser = SoneTextParser(soneProvider, postProvider)
-       private val capturedEvents = mutableListOf<LocalSoneMentionedInPostEvent>()
+       private val capturedEvents = mutableListOf<MentionOfLocalSoneFoundEvent>()
 
        init {
                eventBus.register(SoneMentionDetector(eventBus, soneTextParser))
                eventBus.register(object : Any() {
                        @Subscribe
 
        init {
                eventBus.register(SoneMentionDetector(eventBus, soneTextParser))
                eventBus.register(object : Any() {
                        @Subscribe
-                       fun captureEvent(localSoneMentionedInPostEvent: LocalSoneMentionedInPostEvent) {
-                               capturedEvents += localSoneMentionedInPostEvent
+                       fun captureEvent(mentionOfLocalSoneFoundEvent: MentionOfLocalSoneFoundEvent) {
+                               capturedEvents += mentionOfLocalSoneFoundEvent
                        }
                })
        }
                        }
                })
        }
@@ -67,21 +67,21 @@ class SoneMentionDetectorTest {
        fun `detector emits event on post that contains links to a remote and a local sone`() {
                val post = createPost("text mentions sone://${localSone1.id} and sone://${remoteSone2.id}.")
                eventBus.post(NewPostFoundEvent(post))
        fun `detector emits event on post that contains links to a remote and a local sone`() {
                val post = createPost("text mentions sone://${localSone1.id} and sone://${remoteSone2.id}.")
                eventBus.post(NewPostFoundEvent(post))
-               assertThat(capturedEvents, contains(LocalSoneMentionedInPostEvent(post)))
+               assertThat(capturedEvents, contains(MentionOfLocalSoneFoundEvent(post)))
        }
 
        @Test
        fun `detector emits one event on post that contains two links to the same local sone`() {
                val post = createPost("text mentions sone://${localSone1.id} and sone://${localSone1.id}.")
                eventBus.post(NewPostFoundEvent(post))
        }
 
        @Test
        fun `detector emits one event on post that contains two links to the same local sone`() {
                val post = createPost("text mentions sone://${localSone1.id} and sone://${localSone1.id}.")
                eventBus.post(NewPostFoundEvent(post))
-               assertThat(capturedEvents, contains(LocalSoneMentionedInPostEvent(post)))
+               assertThat(capturedEvents, contains(MentionOfLocalSoneFoundEvent(post)))
        }
 
        @Test
        fun `detector emits one event on post that contains links to two local sones`() {
                val post = createPost("text mentions sone://${localSone1.id} and sone://${localSone2.id}.")
                eventBus.post(NewPostFoundEvent(post))
        }
 
        @Test
        fun `detector emits one event on post that contains links to two local sones`() {
                val post = createPost("text mentions sone://${localSone1.id} and sone://${localSone2.id}.")
                eventBus.post(NewPostFoundEvent(post))
-               assertThat(capturedEvents, contains(LocalSoneMentionedInPostEvent(post)))
+               assertThat(capturedEvents, contains(MentionOfLocalSoneFoundEvent(post)))
        }
 
        @Test
        }
 
        @Test
@@ -110,7 +110,7 @@ class SoneMentionDetectorTest {
                val post = createPost()
                val reply = emptyPostReply("text mentions sone://${remoteSone1.id} and sone://${localSone1.id}.", post)
                eventBus.post(NewPostReplyFoundEvent(reply))
                val post = createPost()
                val reply = emptyPostReply("text mentions sone://${remoteSone1.id} and sone://${localSone1.id}.", post)
                eventBus.post(NewPostReplyFoundEvent(reply))
-               assertThat(capturedEvents, contains(LocalSoneMentionedInPostEvent(post)))
+               assertThat(capturedEvents, contains(MentionOfLocalSoneFoundEvent(post)))
        }
 
        @Test
        }
 
        @Test
@@ -118,7 +118,7 @@ class SoneMentionDetectorTest {
                val post = createPost()
                val reply = emptyPostReply("text mentions sone://${localSone1.id} and sone://${localSone1.id}.", post)
                eventBus.post(NewPostReplyFoundEvent(reply))
                val post = createPost()
                val reply = emptyPostReply("text mentions sone://${localSone1.id} and sone://${localSone1.id}.", post)
                eventBus.post(NewPostReplyFoundEvent(reply))
-               assertThat(capturedEvents, contains(LocalSoneMentionedInPostEvent(post)))
+               assertThat(capturedEvents, contains(MentionOfLocalSoneFoundEvent(post)))
        }
 
        @Test
        }
 
        @Test
@@ -126,7 +126,7 @@ class SoneMentionDetectorTest {
                val post = createPost()
                val reply = emptyPostReply("text mentions sone://${localSone1.id} and sone://${localSone2.id}.", post)
                eventBus.post(NewPostReplyFoundEvent(reply))
                val post = createPost()
                val reply = emptyPostReply("text mentions sone://${localSone1.id} and sone://${localSone2.id}.", post)
                eventBus.post(NewPostReplyFoundEvent(reply))
-               assertThat(capturedEvents, contains(LocalSoneMentionedInPostEvent(post)))
+               assertThat(capturedEvents, contains(MentionOfLocalSoneFoundEvent(post)))
        }
 
        @Test
        }
 
        @Test