2 * Sone - SoneTest.kt - Copyright © 2020 David ‘Bombe’ Roden
4 * This program is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation, either version 3 of the License, or
7 * (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program. If not, see <http://www.gnu.org/licenses/>.
18 package net.pterodactylus.sone.data
20 import net.pterodactylus.sone.data.impl.*
21 import net.pterodactylus.sone.test.*
22 import org.hamcrest.MatcherAssert.*
23 import org.hamcrest.Matchers.*
27 * Unit test for functions in Sone.
32 fun `post count comparator sorts sones with different number of posts correctly`() {
33 val sone1 = object : IdOnlySone("1") {
34 override fun getPosts() = listOf(createPost(), createPost())
36 val sone2 = object : IdOnlySone("2") {
37 override fun getPosts() = listOf(createPost(), createPost(), createPost())
39 assertThat(postCountComparator.compare(sone1, sone2), greaterThan(0))
43 fun `post count comparator compares replies if posts are not different`() {
44 val sone1 = object : IdOnlySone("1") {
45 override fun getPosts() = listOf(createPost(), createPost())
46 override fun getReplies() = setOf(emptyPostReply(), emptyPostReply())
48 val sone2 = object : IdOnlySone("2") {
49 override fun getPosts() = listOf(createPost(), createPost())
50 override fun getReplies() = setOf(emptyPostReply(), emptyPostReply(), emptyPostReply())
52 assertThat(postCountComparator.compare(sone1, sone2), greaterThan(0))
56 fun `post count comparator sorts sone with same amount of posts and replies as equal`() {
57 val sone1 = object : IdOnlySone("1") {
58 override fun getPosts() = listOf(createPost(), createPost())
59 override fun getReplies() = setOf(emptyPostReply(), emptyPostReply())
61 val sone2 = object : IdOnlySone("2") {
62 override fun getPosts() = listOf(createPost(), createPost())
63 override fun getReplies() = setOf(emptyPostReply(), emptyPostReply())
65 assertThat(postCountComparator.compare(sone1, sone2), equalTo(0))