X-Git-Url: https://git.pterodactylus.net/?a=blobdiff_plain;f=src%2Ftest%2Fkotlin%2Fnet%2Fpterodactylus%2Fsone%2Fdata%2FSoneTest.kt;h=42980eeb12a7a242f75a0ec459a625aa73bc0c95;hb=5473139d890c40c85712f59ba534583961c2772e;hp=8866b5128e3ce6a570f608045c8e7ffc99668137;hpb=e03a570dffcf1277952bc03b5e1fb54c50e4394a;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 8866b51..42980ee 100644 --- a/src/test/kotlin/net/pterodactylus/sone/data/SoneTest.kt +++ b/src/test/kotlin/net/pterodactylus/sone/data/SoneTest.kt @@ -62,6 +62,28 @@ class SoneTest { } @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()) @@ -98,4 +120,38 @@ 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)) + } + }