From 0a2f92314bc1f78a6dea24dc353dd8ad3b041cb9 Mon Sep 17 00:00:00 2001 From: =?utf8?q?David=20=E2=80=98Bombe=E2=80=99=20Roden?= Date: Sat, 4 Jan 2020 22:50:00 +0100 Subject: [PATCH] =?utf8?q?=F0=9F=9A=9A=20Rename=20local-sone-mentioned=20e?= =?utf8?q?vent?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- .../core/event/LocalSoneMentionedInPostEvent.kt | 27 ---------------------- .../core/event/MentionOfLocalSoneFoundEvent.kt | 27 ++++++++++++++++++++++ .../pterodactylus/sone/text/SoneMentionDetector.kt | 6 ++--- .../sone/text/SoneMentionDetectorTest.kt | 18 +++++++-------- 4 files changed, 39 insertions(+), 39 deletions(-) delete mode 100644 src/main/kotlin/net/pterodactylus/sone/core/event/LocalSoneMentionedInPostEvent.kt create mode 100644 src/main/kotlin/net/pterodactylus/sone/core/event/MentionOfLocalSoneFoundEvent.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 index 3e644e0..0000000 --- a/src/main/kotlin/net/pterodactylus/sone/core/event/LocalSoneMentionedInPostEvent.kt +++ /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 . - */ - -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 index 0000000..b63203b --- /dev/null +++ b/src/main/kotlin/net/pterodactylus/sone/core/event/MentionOfLocalSoneFoundEvent.kt @@ -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 . + */ + +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) diff --git a/src/main/kotlin/net/pterodactylus/sone/text/SoneMentionDetector.kt b/src/main/kotlin/net/pterodactylus/sone/text/SoneMentionDetector.kt index 32d311d..f3d8cb4 100644 --- a/src/main/kotlin/net/pterodactylus/sone/text/SoneMentionDetector.kt +++ b/src/main/kotlin/net/pterodactylus/sone/text/SoneMentionDetector.kt @@ -24,7 +24,7 @@ import javax.inject.* /** * 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) { @@ -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().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().any { it.sone.isLocal }) { - postReply.post.let(::LocalSoneMentionedInPostEvent).also(eventBus::post) + postReply.post.let(::MentionOfLocalSoneFoundEvent).also(eventBus::post) } } } diff --git a/src/test/kotlin/net/pterodactylus/sone/text/SoneMentionDetectorTest.kt b/src/test/kotlin/net/pterodactylus/sone/text/SoneMentionDetectorTest.kt index 2003988..a56e5b5 100644 --- a/src/test/kotlin/net/pterodactylus/sone/text/SoneMentionDetectorTest.kt +++ b/src/test/kotlin/net/pterodactylus/sone/text/SoneMentionDetectorTest.kt @@ -37,14 +37,14 @@ class SoneMentionDetectorTest { private val soneProvider = TestSoneProvider() private val postProvider = TestPostProvider() private val soneTextParser = SoneTextParser(soneProvider, postProvider) - private val capturedEvents = mutableListOf() + private val capturedEvents = mutableListOf() 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)) - 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)) - 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)) - assertThat(capturedEvents, contains(LocalSoneMentionedInPostEvent(post))) + assertThat(capturedEvents, contains(MentionOfLocalSoneFoundEvent(post))) } @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)) - assertThat(capturedEvents, contains(LocalSoneMentionedInPostEvent(post))) + assertThat(capturedEvents, contains(MentionOfLocalSoneFoundEvent(post))) } @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)) - assertThat(capturedEvents, contains(LocalSoneMentionedInPostEvent(post))) + assertThat(capturedEvents, contains(MentionOfLocalSoneFoundEvent(post))) } @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)) - assertThat(capturedEvents, contains(LocalSoneMentionedInPostEvent(post))) + assertThat(capturedEvents, contains(MentionOfLocalSoneFoundEvent(post))) } @Test -- 2.7.4