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 `nice name comparator correctly compares Sones by their nice name`() {
33 val sone1 = object : IdOnlySone("1") {
34 override fun getProfile() = Profile(this).apply { firstName = "Left" }
36 val sone2 = object : IdOnlySone("2") {
37 override fun getProfile() = Profile(this).apply { firstName = "Right" }
39 assertThat(niceNameComparator.compare(sone1, sone2), lessThan(0))
43 fun `nice name comparator correctly compares Sones by their ID if nice name is the same`() {
44 val sone1 = object : IdOnlySone("1") {
45 override fun getProfile() = Profile(this).apply { firstName = "Left" }
47 val sone2 = object : IdOnlySone("2") {
48 override fun getProfile() = Profile(this).apply { firstName = "Left" }
50 assertThat(niceNameComparator.compare(sone1, sone2), lessThan(0))
54 fun `nice name comparator treats Sones as equal if nice name and ID are the same`() {
55 val sone1 = object : IdOnlySone("1") {
56 override fun getProfile() = Profile(this).apply { firstName = "Left" }
58 val sone2 = object : IdOnlySone("1") {
59 override fun getProfile() = Profile(this).apply { firstName = "Left" }
61 assertThat(niceNameComparator.compare(sone1, sone2), equalTo(0))
65 fun `post count comparator sorts sones with different number of posts correctly`() {
66 val sone1 = object : IdOnlySone("1") {
67 override fun getPosts() = listOf(createPost(), createPost())
69 val sone2 = object : IdOnlySone("2") {
70 override fun getPosts() = listOf(createPost(), createPost(), createPost())
72 assertThat(postCountComparator.compare(sone1, sone2), greaterThan(0))
76 fun `post count comparator compares replies if posts are not different`() {
77 val sone1 = object : IdOnlySone("1") {
78 override fun getPosts() = listOf(createPost(), createPost())
79 override fun getReplies() = setOf(emptyPostReply(), emptyPostReply())
81 val sone2 = object : IdOnlySone("2") {
82 override fun getPosts() = listOf(createPost(), createPost())
83 override fun getReplies() = setOf(emptyPostReply(), emptyPostReply(), emptyPostReply())
85 assertThat(postCountComparator.compare(sone1, sone2), greaterThan(0))
89 fun `post count comparator sorts sone with same amount of posts and replies as equal`() {
90 val sone1 = object : IdOnlySone("1") {
91 override fun getPosts() = listOf(createPost(), createPost())
92 override fun getReplies() = setOf(emptyPostReply(), emptyPostReply())
94 val sone2 = object : IdOnlySone("2") {
95 override fun getPosts() = listOf(createPost(), createPost())
96 override fun getReplies() = setOf(emptyPostReply(), emptyPostReply())
98 assertThat(postCountComparator.compare(sone1, sone2), equalTo(0))