2017-09-02 19:40:32 +02:00
|
|
|
@file:Suppress("IllegalIdentifier")
|
|
|
|
|
2018-02-17 20:36:19 +01:00
|
|
|
package org.moire.ultrasonic.domain
|
2017-09-02 19:40:32 +02:00
|
|
|
|
2020-06-13 19:04:31 +02:00
|
|
|
import java.util.Calendar
|
2018-03-24 19:30:03 +01:00
|
|
|
import org.amshove.kluent.`should be equal to`
|
2017-09-02 19:40:32 +02:00
|
|
|
import org.amshove.kluent.`should equal`
|
|
|
|
import org.junit.Test
|
|
|
|
import org.moire.ultrasonic.api.subsonic.models.Album
|
|
|
|
import org.moire.ultrasonic.api.subsonic.models.MusicDirectoryChild
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Unit test for extension functions in [APIAlbumConverter.kt] file.
|
|
|
|
*/
|
|
|
|
class APIAlbumConverterTest {
|
|
|
|
@Test
|
|
|
|
fun `Should convert Album to domain entity`() {
|
2020-06-13 19:04:31 +02:00
|
|
|
val entity = Album(
|
|
|
|
id = "387", name = "some-name", coverArt = "asdas",
|
|
|
|
artist = "some-artist", artistId = "390", songCount = 12, duration = 841,
|
|
|
|
created = Calendar.getInstance(), year = 2017, genre = "some-genre"
|
|
|
|
)
|
2017-09-02 19:40:32 +02:00
|
|
|
|
|
|
|
val convertedEntity = entity.toDomainEntity()
|
|
|
|
|
|
|
|
with(convertedEntity) {
|
2018-02-22 22:45:28 +01:00
|
|
|
id `should equal` entity.id
|
|
|
|
title `should equal` entity.name
|
|
|
|
isDirectory `should equal` true
|
|
|
|
coverArt `should equal` entity.coverArt
|
|
|
|
artist `should equal` entity.artist
|
|
|
|
artistId `should equal` entity.artistId
|
|
|
|
songCount `should equal` entity.songCount.toLong()
|
|
|
|
duration `should equal` entity.duration
|
2017-09-02 19:40:32 +02:00
|
|
|
created `should equal` entity.created?.time
|
2018-02-22 22:45:28 +01:00
|
|
|
year `should equal` entity.year
|
|
|
|
genre `should equal` entity.genre
|
2017-09-02 19:40:32 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Test
|
|
|
|
fun `Should convert to MusicDirectory domain entity`() {
|
2020-06-13 19:04:31 +02:00
|
|
|
val entity = Album(
|
|
|
|
id = "101", name = "some-album", artist = "some-artist", artistId = "54",
|
|
|
|
coverArt = "some-id", songCount = 10, duration = 456,
|
|
|
|
created = Calendar.getInstance(), year = 2022, genre = "Hard Rock",
|
|
|
|
songList = listOf(MusicDirectoryChild())
|
|
|
|
)
|
2017-09-02 19:40:32 +02:00
|
|
|
|
|
|
|
val convertedEntity = entity.toMusicDirectoryDomainEntity()
|
|
|
|
|
|
|
|
with(convertedEntity) {
|
|
|
|
name `should equal` null
|
2018-03-24 19:30:03 +01:00
|
|
|
getChildren().size `should be equal to` entity.songList.size
|
2018-02-22 22:45:28 +01:00
|
|
|
getChildren()[0] `should equal` entity.songList[0].toDomainEntity()
|
2017-09-02 19:40:32 +02:00
|
|
|
}
|
|
|
|
}
|
2017-09-16 20:02:44 +02:00
|
|
|
|
|
|
|
@Test
|
|
|
|
fun `Should convert list of Album entities to domain list entities`() {
|
2017-12-16 20:10:25 +01:00
|
|
|
val entityList = listOf(Album(id = "455"), Album(id = "1"), Album(id = "1000"))
|
2017-09-16 20:02:44 +02:00
|
|
|
|
|
|
|
val convertedList = entityList.toDomainEntityList()
|
|
|
|
|
|
|
|
with(convertedList) {
|
2018-03-24 19:30:03 +01:00
|
|
|
size `should be equal to` entityList.size
|
2017-09-16 20:02:44 +02:00
|
|
|
forEachIndexed { index, entry ->
|
|
|
|
entry `should equal` entityList[index].toDomainEntity()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2017-09-02 19:40:32 +02:00
|
|
|
}
|