X-Git-Url: https://git.pterodactylus.net/?a=blobdiff_plain;f=src%2Ftest%2Fkotlin%2Fnet%2Fpterodactylus%2Fsone%2Fnotify%2FListNotificationFilterTest.kt;h=ffc1e5a47552e2bd347ca21c41561163a65c0518;hb=cc03c378e6d5c713aea50ac8930a1dae0ad1cb88;hp=327732e3f5866abd11bbe520596345e20dda2e08;hpb=fedc22de1913a39285d0704a56f3d8b3f8361a00;p=Sone.git diff --git a/src/test/kotlin/net/pterodactylus/sone/notify/ListNotificationFilterTest.kt b/src/test/kotlin/net/pterodactylus/sone/notify/ListNotificationFilterTest.kt index 327732e..ffc1e5a 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 @@ -24,7 +23,7 @@ import org.junit.Test */ class ListNotificationFilterTest { - private val listNotificationFilter = ListNotificationFilter(showAllPosts, showAllReplies) + private val listNotificationFilter = DefaultListNotificationFilter(showAllPosts, showAllReplies) @Test fun `filter is only created once`() { @@ -73,7 +72,7 @@ class ListNotificationFilterTest { localSone.options.isShowNewPostNotifications = true val newPostNotification = createNewPostNotification() newPostNotification.add(createPost()) - val listNotificationFilter = ListNotificationFilter(showNoPosts, showAllReplies) + val listNotificationFilter = DefaultListNotificationFilter(showNoPosts, showAllReplies) val filteredNotifications = listNotificationFilter.filterNotifications(listOf(newPostNotification), localSone) assertThat(filteredNotifications, emptyIterable()) } @@ -105,7 +104,7 @@ class ListNotificationFilterTest { val newPostNotification = createNewPostNotification() newPostNotification.add(createPost()) newPostNotification.add(createPost()) - val listNotificationFilter = ListNotificationFilter(matchThisPost(newPostNotification.elements[1]), showAllReplies) + val listNotificationFilter = DefaultListNotificationFilter(matchThisPost(newPostNotification.elements[1]), showAllReplies) val filteredNotifications = listNotificationFilter.filterNotifications(listOf(newPostNotification), localSone) assertThat((filteredNotifications[0] as ListNotification).elements, contains(newPostNotification.elements[1])) } @@ -117,7 +116,7 @@ class ListNotificationFilterTest { val newReplyNotification = createNewReplyNotification() newReplyNotification.add(createPostReply()) newReplyNotification.add(createPostReply()) - val listNotificationFilter = ListNotificationFilter(showAllPosts, matchThisReply(newReplyNotification.elements[1])) + val listNotificationFilter = DefaultListNotificationFilter(showAllPosts, matchThisReply(newReplyNotification.elements[1])) val filteredNotifications = listNotificationFilter.filterNotifications(listOf(newReplyNotification), localSone) assertThat(filteredNotifications, hasSize(1)) assertThat((filteredNotifications[0] as ListNotification).elements[0], equalTo(newReplyNotification.elements[1])) @@ -141,7 +140,7 @@ class ListNotificationFilterTest { val newReplyNotification = createNewReplyNotification() newReplyNotification.add(createPostReply()) newReplyNotification.add(createPostReply()) - val listNotificationFilter = ListNotificationFilter(showAllPosts, showNoReplies) + val listNotificationFilter = DefaultListNotificationFilter(showAllPosts, showNoReplies) val filteredNotifications = listNotificationFilter.filterNotifications(listOf(newReplyNotification), localSone) assertThat(filteredNotifications, emptyIterable()) } @@ -171,7 +170,7 @@ class ListNotificationFilterTest { val mentionNotification = createMentionNotification() mentionNotification.add(createPost()) mentionNotification.add(createPost()) - val listNotificationFilter = ListNotificationFilter(matchThisPost(mentionNotification.elements[1]), showAllReplies) + val listNotificationFilter = DefaultListNotificationFilter(matchThisPost(mentionNotification.elements[1]), showAllReplies) val filteredNotifications = listNotificationFilter.filterNotifications(listOf(mentionNotification), null) assertThat(filteredNotifications, hasSize(1)) assertThat((filteredNotifications[0] as ListNotification).elements[0], equalTo(mentionNotification.elements[1])) @@ -182,7 +181,7 @@ class ListNotificationFilterTest { val mentionNotification = createMentionNotification() mentionNotification.add(createPost()) mentionNotification.add(createPost()) - val listNotificationFilter = ListNotificationFilter(showNoPosts, showAllReplies) + val listNotificationFilter = DefaultListNotificationFilter(showNoPosts, showAllReplies) val filteredNotifications = listNotificationFilter.filterNotifications(listOf(mentionNotification), null) assertThat(filteredNotifications, emptyIterable()) } @@ -208,21 +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) - override fun isVisible(currentSone: Sone?) = Predicate { p -> p != null && isPostVisible(currentSone, p) } -} - -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) } -}