🎨 Replace post count comparator with Kotlin version
[Sone.git] / src / test / kotlin / net / pterodactylus / sone / data / SoneTest.kt
diff --git a/src/test/kotlin/net/pterodactylus/sone/data/SoneTest.kt b/src/test/kotlin/net/pterodactylus/sone/data/SoneTest.kt
new file mode 100644 (file)
index 0000000..5cc0ee2
--- /dev/null
@@ -0,0 +1,68 @@
+/**
+ * Sone - SoneTest.kt - Copyright Â© 2020 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.data
+
+import net.pterodactylus.sone.data.impl.*
+import net.pterodactylus.sone.test.*
+import org.hamcrest.MatcherAssert.*
+import org.hamcrest.Matchers.*
+import kotlin.test.*
+
+/**
+ * Unit test for functions in Sone.
+ */
+class SoneTest {
+
+       @Test
+       fun `post count comparator sorts sones with different number of posts correctly`() {
+               val sone1 = object : IdOnlySone("1") {
+                       override fun getPosts() = listOf(createPost(), createPost())
+               }
+               val sone2 = object : IdOnlySone("2") {
+                       override fun getPosts() = listOf(createPost(), createPost(), createPost())
+               }
+               assertThat(postCountComparator.compare(sone1, sone2), greaterThan(0))
+       }
+
+       @Test
+       fun `post count comparator compares replies if posts are not different`() {
+               val sone1 = object : IdOnlySone("1") {
+                       override fun getPosts() = listOf(createPost(), createPost())
+                       override fun getReplies() = setOf(emptyPostReply(), emptyPostReply())
+               }
+               val sone2 = object : IdOnlySone("2") {
+                       override fun getPosts() = listOf(createPost(), createPost())
+                       override fun getReplies() = setOf(emptyPostReply(), emptyPostReply(), emptyPostReply())
+               }
+               assertThat(postCountComparator.compare(sone1, sone2), greaterThan(0))
+       }
+
+       @Test
+       fun `post count comparator sorts sone with same amount of posts and replies as equal`() {
+               val sone1 = object : IdOnlySone("1") {
+                       override fun getPosts() = listOf(createPost(), createPost())
+                       override fun getReplies() = setOf(emptyPostReply(), emptyPostReply())
+               }
+               val sone2 = object : IdOnlySone("2") {
+                       override fun getPosts() = listOf(createPost(), createPost())
+                       override fun getReplies() = setOf(emptyPostReply(), emptyPostReply())
+               }
+               assertThat(postCountComparator.compare(sone1, sone2), equalTo(0))
+       }
+
+}