From: David ‘Bombe’ Roden Date: Sat, 27 Jun 2020 20:48:51 +0000 (+0200) Subject: ♻️ Move some code to package’s Testing.kt X-Git-Url: https://git.pterodactylus.net/?a=commitdiff_plain;h=f10eb7791c87509e66eb88b3c7dacb74bbac8c28;p=Sone.git ♻️ Move some code to package’s Testing.kt --- diff --git a/src/test/kotlin/net/pterodactylus/sone/notify/ListNotificationFilterTest.kt b/src/test/kotlin/net/pterodactylus/sone/notify/ListNotificationFilterTest.kt index 3a7f47f..67a01c3 100644 --- a/src/test/kotlin/net/pterodactylus/sone/notify/ListNotificationFilterTest.kt +++ b/src/test/kotlin/net/pterodactylus/sone/notify/ListNotificationFilterTest.kt @@ -1,6 +1,5 @@ package net.pterodactylus.sone.notify -import com.google.common.base.Predicate import com.google.inject.Guice import net.pterodactylus.sone.data.Post import net.pterodactylus.sone.data.PostReply @@ -208,20 +207,3 @@ private fun createNewReplyNotification() = private fun createMentionNotification() = ListNotification("mention-notification", "", Template()) - -private fun matchThisPost(post: Post) = createPostVisibilityFilter { _, p -> p == post } -private val showAllPosts = createPostVisibilityFilter { _, _ -> true } -private val showNoPosts = createPostVisibilityFilter { _, _ -> false } - -private fun createPostVisibilityFilter(visible: (Sone?, Post) -> Boolean) = object : PostVisibilityFilter { - override fun isPostVisible(sone: Sone?, post: Post) = visible(sone, post) -} - -private fun matchThisReply(reply: PostReply) = createReplyVisibilityFilter(showAllPosts) { _, r -> r == reply } -private val showAllReplies = createReplyVisibilityFilter(showAllPosts) { _, _ -> true } -private val showNoReplies = createReplyVisibilityFilter(showAllPosts) { _, _ -> false } - -private fun createReplyVisibilityFilter(postVisibilityFilter: PostVisibilityFilter, visible: (Sone?, PostReply) -> Boolean) = object : ReplyVisibilityFilter(postVisibilityFilter) { - override fun isReplyVisible(sone: Sone?, reply: PostReply) = visible(sone, reply) - override fun isVisible(currentSone: Sone?) = Predicate { r -> r != null && isReplyVisible(currentSone, r) } -} diff --git a/src/test/kotlin/net/pterodactylus/sone/notify/Testing.kt b/src/test/kotlin/net/pterodactylus/sone/notify/Testing.kt new file mode 100644 index 0000000..bec8a51 --- /dev/null +++ b/src/test/kotlin/net/pterodactylus/sone/notify/Testing.kt @@ -0,0 +1,23 @@ +package net.pterodactylus.sone.notify + +import net.pterodactylus.sone.data.Post +import net.pterodactylus.sone.data.PostReply +import net.pterodactylus.sone.data.Sone +import java.util.function.Predicate + +fun matchThisPost(post: Post) = createPostVisibilityFilter { _, p -> p == post } +val showAllPosts = createPostVisibilityFilter { _, _ -> true } +val showNoPosts = createPostVisibilityFilter { _, _ -> false } + +private fun createPostVisibilityFilter(visible: (Sone?, Post) -> Boolean) = object : PostVisibilityFilter { + override fun isPostVisible(sone: Sone?, post: Post) = visible(sone, post) +} + +fun matchThisReply(reply: PostReply) = createReplyVisibilityFilter(showAllPosts) { _, r -> r == reply } +val showAllReplies = createReplyVisibilityFilter(showAllPosts) { _, _ -> true } +val showNoReplies = createReplyVisibilityFilter(showAllPosts) { _, _ -> false } + +private fun createReplyVisibilityFilter(postVisibilityFilter: PostVisibilityFilter, visible: (Sone?, PostReply) -> Boolean) = object : ReplyVisibilityFilter(postVisibilityFilter) { + override fun isReplyVisible(sone: Sone?, reply: PostReply) = visible(sone, reply) + override fun isVisible(currentSone: Sone?) = Predicate { r -> r != null && isReplyVisible(currentSone, r) } +}