From e13cd46faa0404418176f8747d52e8160b2a7068 Mon Sep 17 00:00:00 2001 From: =?utf8?q?David=20=E2=80=98Bombe=E2=80=99=20Roden?= Date: Tue, 18 Feb 2020 16:42:19 +0100 Subject: [PATCH] =?utf8?q?=E2=9C=85=20Add=20tests=20for=20Album.allImages?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- src/main/kotlin/net/pterodactylus/sone/data/Albums.kt | 2 +- .../kotlin/net/pterodactylus/sone/data/AlbumsTest.kt | 19 +++++++++++++++++++ 2 files changed, 20 insertions(+), 1 deletion(-) 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)) + } + } -- 2.7.4