X-Git-Url: https://git.pterodactylus.net/?a=blobdiff_plain;f=src%2Ftest%2Fkotlin%2Fnet%2Fpterodactylus%2Fsone%2Fdata%2FSoneTest.kt;h=9e087814523d4150a020ec6eb0b6feaf9626658e;hb=5076d8379e6413189273defd4f01f241b4a6a57e;hp=6b7e51d5b9dc587c60bf1324c11bdb060bb3f792;hpb=141f56a62e39c13b1eb14fe6e5c3b8b7bc062168;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 6b7e51d..9e08781 100644 --- a/src/test/kotlin/net/pterodactylus/sone/data/SoneTest.kt +++ b/src/test/kotlin/net/pterodactylus/sone/data/SoneTest.kt @@ -98,11 +98,11 @@ class SoneTest { fun `post count comparator compares replies if posts are not different`() { val sone1 = object : IdOnlySone("1") { override fun getPosts() = listOf(createPost(), createPost()) - override fun getReplies() = setOf(emptyPostReply(), emptyPostReply()) + override fun getReplies() = setOf(createPostReply(), createPostReply()) } val sone2 = object : IdOnlySone("2") { override fun getPosts() = listOf(createPost(), createPost()) - override fun getReplies() = setOf(emptyPostReply(), emptyPostReply(), emptyPostReply()) + override fun getReplies() = setOf(createPostReply(), createPostReply(), createPostReply()) } assertThat(postCountComparator.compare(sone1, sone2), greaterThan(0)) } @@ -111,13 +111,62 @@ class SoneTest { fun `post count comparator sorts sone with same amount of posts and replies as equal`() { val sone1 = object : IdOnlySone("1") { override fun getPosts() = listOf(createPost(), createPost()) - override fun getReplies() = setOf(emptyPostReply(), emptyPostReply()) + override fun getReplies() = setOf(createPostReply(), createPostReply()) } val sone2 = object : IdOnlySone("2") { override fun getPosts() = listOf(createPost(), createPost()) - override fun getReplies() = setOf(emptyPostReply(), emptyPostReply()) + override fun getReplies() = setOf(createPostReply(), createPostReply()) } 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)) + } + }