From e03a570dffcf1277952bc03b5e1fb54c50e4394a Mon Sep 17 00:00:00 2001 From: =?utf8?q?David=20=E2=80=98Bombe=E2=80=99=20Roden?= Date: Sun, 16 Feb 2020 21:10:39 +0100 Subject: [PATCH] =?utf8?q?=E2=9C=85=20Add=20test=20for=20nice-name=20compa?= =?utf8?q?rator?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- .../kotlin/net/pterodactylus/sone/data/SoneTest.kt | 33 ++++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/src/test/kotlin/net/pterodactylus/sone/data/SoneTest.kt b/src/test/kotlin/net/pterodactylus/sone/data/SoneTest.kt index 5cc0ee2..8866b51 100644 --- a/src/test/kotlin/net/pterodactylus/sone/data/SoneTest.kt +++ b/src/test/kotlin/net/pterodactylus/sone/data/SoneTest.kt @@ -29,6 +29,39 @@ 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 `post count comparator sorts sones with different number of posts correctly`() { val sone1 = object : IdOnlySone("1") { override fun getPosts() = listOf(createPost(), createPost()) -- 2.7.4