♻️ Move some code to package’s Testing.kt
authorDavid ‘Bombe’ Roden <bombe@pterodactylus.net>
Sat, 27 Jun 2020 20:48:51 +0000 (22:48 +0200)
committerDavid ‘Bombe’ Roden <bombe@pterodactylus.net>
Sat, 27 Jun 2020 20:48:51 +0000 (22:48 +0200)
src/test/kotlin/net/pterodactylus/sone/notify/ListNotificationFilterTest.kt
src/test/kotlin/net/pterodactylus/sone/notify/Testing.kt [new file with mode: 0644]

index 3a7f47f..67a01c3 100644 (file)
@@ -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<Post>("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<PostReply> { 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 (file)
index 0000000..bec8a51
--- /dev/null
@@ -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<PostReply> { r -> r != null && isReplyVisible(currentSone, r) }
+}