X-Git-Url: https://git.pterodactylus.net/?a=blobdiff_plain;f=src%2Ftest%2Fkotlin%2Fnet%2Fpterodactylus%2Fsone%2Fdata%2FSoneTest.kt;h=6b7e51d5b9dc587c60bf1324c11bdb060bb3f792;hb=141f56a62e39c13b1eb14fe6e5c3b8b7bc062168;hp=5cc0ee2ccc862031b55459f45861c705908b2d02;hpb=9b0b5b760adf41d52603a4b65f3e5f3220da28eb;p=Sone.git diff --git a/src/test/kotlin/net/pterodactylus/sone/data/SoneTest.kt b/src/test/kotlin/net/pterodactylus/sone/data/SoneTest.kt index 5cc0ee2..6b7e51d 100644 --- a/src/test/kotlin/net/pterodactylus/sone/data/SoneTest.kt +++ b/src/test/kotlin/net/pterodactylus/sone/data/SoneTest.kt @@ -29,6 +29,61 @@ import kotlin.test.* class SoneTest { @Test + fun `nice name comparator correctly compares Sones by their nice name`() { + val sone1 = object : IdOnlySone("1") { + override fun getProfile() = Profile(this).apply { firstName = "Left" } + } + val sone2 = object : IdOnlySone("2") { + override fun getProfile() = Profile(this).apply { firstName = "Right" } + } + assertThat(niceNameComparator.compare(sone1, sone2), lessThan(0)) + } + + @Test + fun `nice name comparator correctly compares Sones by their ID if nice name is the same`() { + val sone1 = object : IdOnlySone("1") { + override fun getProfile() = Profile(this).apply { firstName = "Left" } + } + val sone2 = object : IdOnlySone("2") { + override fun getProfile() = Profile(this).apply { firstName = "Left" } + } + assertThat(niceNameComparator.compare(sone1, sone2), lessThan(0)) + } + + @Test + fun `nice name comparator treats Sones as equal if nice name and ID are the same`() { + val sone1 = object : IdOnlySone("1") { + override fun getProfile() = Profile(this).apply { firstName = "Left" } + } + val sone2 = object : IdOnlySone("1") { + override fun getProfile() = Profile(this).apply { firstName = "Left" } + } + assertThat(niceNameComparator.compare(sone1, sone2), equalTo(0)) + } + + @Test + fun `last activity comparator correctly compares Sones by last activity`() { + val sone1 = object : IdOnlySone("1") { + override fun getTime() = 1000L + } + val sone2 = object : IdOnlySone("2") { + override fun getTime() = 2000L + } + assertThat(lastActivityComparator.compare(sone1, sone2), greaterThan(0)) + } + + @Test + fun `last activity comparator treats Sones as equal if last activity is the same`() { + val sone1 = object : IdOnlySone("1") { + override fun getTime() = 1000L + } + val sone2 = object : IdOnlySone("2") { + override fun getTime() = 1000L + } + assertThat(lastActivityComparator.compare(sone1, sone2), equalTo(0)) + } + + @Test fun `post count comparator sorts sones with different number of posts correctly`() { val sone1 = object : IdOnlySone("1") { override fun getPosts() = listOf(createPost(), createPost())