✅ Add tests for Album.allImages
authorDavid ‘Bombe’ Roden <bombe@pterodactylus.net>
Tue, 18 Feb 2020 15:42:19 +0000 (16:42 +0100)
committerDavid ‘Bombe’ Roden <bombe@pterodactylus.net>
Tue, 18 Feb 2020 15:43:46 +0000 (16:43 +0100)
src/main/kotlin/net/pterodactylus/sone/data/Albums.kt
src/test/kotlin/net/pterodactylus/sone/data/AlbumsTest.kt

index da71d62..a38e9dd 100644 (file)
@@ -20,7 +20,7 @@ package net.pterodactylus.sone.data
 /** Returns all images contained in this album and all its albums. */
 val Album.allImages: Collection<Image>
        get() =
-               images + albums.flatMap { it.allImages }
+               images + albums.flatMap(Album::allImages)
 
 /**
  *  Returns this album and all albums contained in this album (recursively).
index 1f938a3..6821a24 100644 (file)
@@ -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))
+       }
+
 }