The Tests actually caught an error :)

If shortcuts were set, these were added as duplicates to the list.
This commit is contained in:
tzugen 2021-06-23 17:09:33 +02:00
parent fe9b2f9700
commit b546f2c2fb
No known key found for this signature in database
GPG Key ID: 61E9C34BC10EC930
3 changed files with 23 additions and 8 deletions

View File

@ -1,5 +1,6 @@
package org.moire.ultrasonic.api.subsonic.models package org.moire.ultrasonic.api.subsonic.models
import java.util.Locale
import org.amshove.kluent.`should be equal to` import org.amshove.kluent.`should be equal to`
import org.amshove.kluent.`should throw` import org.amshove.kluent.`should throw`
import org.junit.Test import org.junit.Test
@ -10,7 +11,7 @@ import org.junit.Test
class AlbumListTypeTest { class AlbumListTypeTest {
@Test @Test
fun `Should create type from string ignoring case`() { fun `Should create type from string ignoring case`() {
val type = AlbumListType.SORTED_BY_NAME.typeName.toLowerCase() val type = AlbumListType.SORTED_BY_NAME.typeName.lowercase(Locale.ROOT)
val albumListType = AlbumListType.fromName(type) val albumListType = AlbumListType.fromName(type)

View File

@ -7,15 +7,29 @@ import org.moire.ultrasonic.api.subsonic.models.Index as APIIndex
import org.moire.ultrasonic.api.subsonic.models.Indexes as APIIndexes import org.moire.ultrasonic.api.subsonic.models.Indexes as APIIndexes
fun APIIndexes.toArtistList(): List<Artist> { fun APIIndexes.toArtistList(): List<Artist> {
val list = this.shortcutList.map { it.toDomainEntity() }.toMutableList() val shortcuts = this.shortcutList.map { it.toDomainEntity() }.toMutableList()
list.addAll(this.indexList.foldIndexToArtistList()) val indexes = this.indexList.foldIndexToArtistList()
return list
indexes.forEach {
if (!shortcuts.contains(it)) {
shortcuts.add(it)
}
}
return shortcuts
} }
fun APIIndexes.toIndexList(musicFolderId: String?): List<Index> { fun APIIndexes.toIndexList(musicFolderId: String?): List<Index> {
val list = this.shortcutList.map { it.toIndexEntity() }.toMutableList() val shortcuts = this.shortcutList.map { it.toIndexEntity() }.toMutableList()
list.addAll(this.indexList.foldIndexToIndexList(musicFolderId)) val indexes = this.indexList.foldIndexToIndexList(musicFolderId)
return list
indexes.forEach {
if (!shortcuts.contains(it)) {
shortcuts.add(it)
}
}
return shortcuts
} }
private fun List<APIIndex>.foldIndexToArtistList(): List<Artist> = this.fold( private fun List<APIIndex>.foldIndexToArtistList(): List<Artist> = this.fold(

View File

@ -31,7 +31,7 @@ class APIIndexConverterTest {
shortcutList = artistsA shortcutList = artistsA
) )
val convertedEntity = entity.toIndexList(null) val convertedEntity = entity.toArtistList()
val expectedArtists = (artistsA + artistsT).map { it.toDomainEntity() }.toMutableList() val expectedArtists = (artistsA + artistsT).map { it.toDomainEntity() }.toMutableList()
with(convertedEntity) { with(convertedEntity) {