From: David ‘Bombe’ Roden Date: Tue, 18 Feb 2020 15:42:19 +0000 (+0100) Subject: ✅ Add tests for Album.allImages X-Git-Tag: v82^2~56 X-Git-Url: https://git.pterodactylus.net/?a=commitdiff_plain;h=e13cd46faa0404418176f8747d52e8160b2a7068;p=Sone.git ✅ Add tests for Album.allImages --- diff --git a/src/main/kotlin/net/pterodactylus/sone/data/Albums.kt b/src/main/kotlin/net/pterodactylus/sone/data/Albums.kt index da71d62..a38e9dd 100644 --- a/src/main/kotlin/net/pterodactylus/sone/data/Albums.kt +++ b/src/main/kotlin/net/pterodactylus/sone/data/Albums.kt @@ -20,7 +20,7 @@ package net.pterodactylus.sone.data /** Returns all images contained in this album and all its albums. */ val Album.allImages: Collection get() = - images + albums.flatMap { it.allImages } + images + albums.flatMap(Album::allImages) /** * Returns this album and all albums contained in this album (recursively). diff --git a/src/test/kotlin/net/pterodactylus/sone/data/AlbumsTest.kt b/src/test/kotlin/net/pterodactylus/sone/data/AlbumsTest.kt index 1f938a3..6821a24 100644 --- a/src/test/kotlin/net/pterodactylus/sone/data/AlbumsTest.kt +++ b/src/test/kotlin/net/pterodactylus/sone/data/AlbumsTest.kt @@ -114,4 +114,23 @@ class AlbumsTest { assertThat(notEmpty(album), equalTo(true)) } + @Test + fun `allImages returns images from album`() { + val sone = IdOnlySone("sone") + val album = AlbumImpl(sone) + val image1 = createImage(sone, "1").also(album::addImage) + val image2 = createImage(sone, "2").also(album::addImage) + assertThat(album.allImages, contains(image1, image2)) + } + + @Test + fun `allImages returns images from subalbum`() { + val sone = IdOnlySone("sone") + val album1 = AlbumImpl(sone) + val album2 = AlbumImpl(sone).also(album1::addAlbum) + val image1 = createImage(sone, "1").also(album1::addImage) + val image2 = createImage(sone, "2").also(album2::addImage) + assertThat(album1.allImages, contains(image1, image2)) + } + }