X-Git-Url: https://git.pterodactylus.net/?a=blobdiff_plain;f=src%2Ftest%2Fkotlin%2Fnet%2Fpterodactylus%2Fsone%2Fdata%2FSoneTest.kt;h=fb2312125a02e22d3459decd97bb81899255d870;hb=8e2e2aa6f1c7c4e9b4b994caee11677d4cd41403;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..fb23121 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()) @@ -65,4 +120,53 @@ class SoneTest { assertThat(postCountComparator.compare(sone1, sone2), equalTo(0)) } + @Test + fun `image count comparator sorts Sones correctly if number of images is different`() { + val sone1 = object : IdOnlySone("1") { + override fun getRootAlbum() = AlbumImpl(this).also { it.addImage(createImage(this)) } + } + val sone2 = object : IdOnlySone("2") { + override fun getRootAlbum() = AlbumImpl(this).also { it.addImage(createImage(this)); it.addImage(createImage(this)) } + } + assertThat(imageCountComparator.compare(sone1, sone2), greaterThan(0)) + } + + @Test + fun `image count comparator treats Sones as equal if number of images is the same`() { + val sone1 = object : IdOnlySone("1") { + override fun getRootAlbum() = AlbumImpl(this).also { it.addImage(createImage(this)) } + } + val sone2 = object : IdOnlySone("2") { + override fun getRootAlbum() = AlbumImpl(this).also { it.addImage(createImage(this)) } + } + assertThat(imageCountComparator.compare(sone1, sone2), equalTo(0)) + } + + @Test + fun `allAlbums returns all albums of a Sone but the root album`() { + val sone = object : IdOnlySone("1") { + private val rootAlbum = AlbumImpl(this) + override fun getRootAlbum() = rootAlbum + } + val album1 = AlbumImpl(sone).also(sone.rootAlbum::addAlbum) + val album11 = AlbumImpl(sone).also(album1::addAlbum) + val album2 = AlbumImpl(sone).also(sone.rootAlbum::addAlbum) + assertThat(sone.allAlbums, contains(album1, album11, album2)) + } + + @Test + fun `allImages returns all images of a Sone`() { + val sone = object : IdOnlySone("1") { + private val rootAlbum = AlbumImpl(this) + override fun getRootAlbum() = rootAlbum + } + val album1 = AlbumImpl(sone).also(sone.rootAlbum::addAlbum) + val album11 = AlbumImpl(sone).also(album1::addAlbum) + val album2 = AlbumImpl(sone).also(sone.rootAlbum::addAlbum) + val image1 = createImage(sone).also(album1::addImage) + val image11 = createImage(sone).also(album11::addImage) + val image2 = createImage(sone).also(album2::addImage) + assertThat(sone.allImages, containsInAnyOrder(image1, image11, image2)) + } + }