From: David ‘Bombe’ Roden Date: Tue, 18 Feb 2020 15:43:01 +0000 (+0100) Subject: 🎨 Add Sone.allImages accessor X-Git-Tag: v82^2~55 X-Git-Url: https://git.pterodactylus.net/?a=commitdiff_plain;h=8e2e2aa6f1c7c4e9b4b994caee11677d4cd41403;p=Sone.git 🎨 Add Sone.allImages accessor --- diff --git a/src/main/kotlin/net/pterodactylus/sone/data/Sone.kt b/src/main/kotlin/net/pterodactylus/sone/data/Sone.kt index 46ff336..34403a1 100644 --- a/src/main/kotlin/net/pterodactylus/sone/data/Sone.kt +++ b/src/main/kotlin/net/pterodactylus/sone/data/Sone.kt @@ -55,3 +55,7 @@ val imageCountComparator: Comparator = val Sone.allAlbums: List get() = rootAlbum.albums.flatMap(Album::allAlbums) + +val Sone.allImages: Collection + get() = + rootAlbum.allImages diff --git a/src/test/kotlin/net/pterodactylus/sone/data/SoneTest.kt b/src/test/kotlin/net/pterodactylus/sone/data/SoneTest.kt index 42980ee..fb23121 100644 --- a/src/test/kotlin/net/pterodactylus/sone/data/SoneTest.kt +++ b/src/test/kotlin/net/pterodactylus/sone/data/SoneTest.kt @@ -154,4 +154,19 @@ class SoneTest { 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)) + } + }