The Tests actually caught an error :)
If shortcuts were set, these were added as duplicates to the list.
This commit is contained in:
parent
fe9b2f9700
commit
b546f2c2fb
|
@ -1,5 +1,6 @@
|
|||
package org.moire.ultrasonic.api.subsonic.models
|
||||
|
||||
import java.util.Locale
|
||||
import org.amshove.kluent.`should be equal to`
|
||||
import org.amshove.kluent.`should throw`
|
||||
import org.junit.Test
|
||||
|
@ -10,7 +11,7 @@ import org.junit.Test
|
|||
class AlbumListTypeTest {
|
||||
@Test
|
||||
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)
|
||||
|
||||
|
|
|
@ -7,15 +7,29 @@ import org.moire.ultrasonic.api.subsonic.models.Index as APIIndex
|
|||
import org.moire.ultrasonic.api.subsonic.models.Indexes as APIIndexes
|
||||
|
||||
fun APIIndexes.toArtistList(): List<Artist> {
|
||||
val list = this.shortcutList.map { it.toDomainEntity() }.toMutableList()
|
||||
list.addAll(this.indexList.foldIndexToArtistList())
|
||||
return list
|
||||
val shortcuts = this.shortcutList.map { it.toDomainEntity() }.toMutableList()
|
||||
val indexes = this.indexList.foldIndexToArtistList()
|
||||
|
||||
indexes.forEach {
|
||||
if (!shortcuts.contains(it)) {
|
||||
shortcuts.add(it)
|
||||
}
|
||||
}
|
||||
|
||||
return shortcuts
|
||||
}
|
||||
|
||||
fun APIIndexes.toIndexList(musicFolderId: String?): List<Index> {
|
||||
val list = this.shortcutList.map { it.toIndexEntity() }.toMutableList()
|
||||
list.addAll(this.indexList.foldIndexToIndexList(musicFolderId))
|
||||
return list
|
||||
val shortcuts = this.shortcutList.map { it.toIndexEntity() }.toMutableList()
|
||||
val indexes = this.indexList.foldIndexToIndexList(musicFolderId)
|
||||
|
||||
indexes.forEach {
|
||||
if (!shortcuts.contains(it)) {
|
||||
shortcuts.add(it)
|
||||
}
|
||||
}
|
||||
|
||||
return shortcuts
|
||||
}
|
||||
|
||||
private fun List<APIIndex>.foldIndexToArtistList(): List<Artist> = this.fold(
|
||||
|
|
|
@ -31,7 +31,7 @@ class APIIndexConverterTest {
|
|||
shortcutList = artistsA
|
||||
)
|
||||
|
||||
val convertedEntity = entity.toIndexList(null)
|
||||
val convertedEntity = entity.toArtistList()
|
||||
|
||||
val expectedArtists = (artistsA + artistsT).map { it.toDomainEntity() }.toMutableList()
|
||||
with(convertedEntity) {
|
||||
|
|
Loading…
Reference in New Issue