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.junit.Test
|
|
|
|
import org.moire.ultrasonic.api.subsonic.models.MusicDirectoryChild
|
|
|
|
import org.moire.ultrasonic.api.subsonic.models.Playlist
|
|
|
|
|
|
|
|
/**
|
2017-11-10 21:31:48 +01:00
|
|
|
* Unit test for extension functions that converts api playlist entity to domain.
|
2017-09-02 19:40:32 +02:00
|
|
|
*/
|
|
|
|
class APIPlaylistConverterTest {
|
|
|
|
@Test
|
|
|
|
fun `Should convert Playlist to MusicDirectory domain entity`() {
|
2020-06-13 19:04:31 +02:00
|
|
|
val entity = Playlist(
|
|
|
|
name = "some-playlist-name",
|
|
|
|
entriesList = listOf(
|
2017-12-16 21:28:18 +01:00
|
|
|
MusicDirectoryChild(id = "10", parent = "1393"),
|
|
|
|
MusicDirectoryChild(id = "11", parent = "1393")
|
2020-06-13 19:04:31 +02:00
|
|
|
)
|
|
|
|
)
|
2017-09-02 19:40:32 +02:00
|
|
|
|
|
|
|
val convertedEntity = entity.toMusicDirectoryDomainEntity()
|
|
|
|
|
|
|
|
with(convertedEntity) {
|
2021-05-07 15:36:11 +02:00
|
|
|
name `should be equal to` entity.name
|
2021-11-27 00:51:41 +01:00
|
|
|
size `should be equal to` entity.entriesList.size
|
2021-12-21 12:16:40 +01:00
|
|
|
this[0] `should be equal to` entity.entriesList[0].toTrackEntity()
|
|
|
|
this[1] `should be equal to` entity.entriesList[1].toTrackEntity()
|
2017-09-02 19:40:32 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Test
|
|
|
|
fun `Should convert playlist to domain entity`() {
|
2020-06-13 19:04:31 +02:00
|
|
|
val entity = Playlist(
|
|
|
|
id = "634", name = "some-name", owner = "some-owner",
|
|
|
|
comment = "some-comment", public = false, songCount = 256, duration = 1150,
|
|
|
|
created = Calendar.getInstance(), changed = Calendar.getInstance(),
|
|
|
|
coverArt = "some-art"
|
|
|
|
)
|
2017-09-02 19:40:32 +02:00
|
|
|
|
|
|
|
val convertedEntity = entity.toDomainEntity()
|
|
|
|
|
|
|
|
with(convertedEntity) {
|
2018-03-24 19:30:03 +01:00
|
|
|
id `should be equal to` entity.id
|
|
|
|
name `should be equal to` entity.name
|
|
|
|
comment `should be equal to` entity.comment
|
|
|
|
owner `should be equal to` entity.owner
|
2021-05-07 15:36:11 +02:00
|
|
|
public `should be equal to` entity.public
|
2018-03-24 19:30:03 +01:00
|
|
|
songCount `should be equal to` entity.songCount.toString()
|
2021-05-07 15:36:11 +02:00
|
|
|
created `should be equal to` playlistDateFormat.format(entity.created!!.time)
|
2017-09-02 19:40:32 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Test
|
|
|
|
fun `Should convert list of playlists to list of domain entities`() {
|
2017-12-16 20:47:00 +01:00
|
|
|
val entitiesList = listOf(Playlist(id = "23", name = "some-name", songCount = 10))
|
2017-09-02 19:40:32 +02:00
|
|
|
|
|
|
|
val convertedList = entitiesList.toDomainEntitiesList()
|
|
|
|
|
|
|
|
with(convertedList) {
|
2018-03-24 19:30:03 +01:00
|
|
|
size `should be equal to` entitiesList.size
|
2021-05-07 15:36:11 +02:00
|
|
|
this[0] `should be equal to` entitiesList[0].toDomainEntity()
|
2017-09-02 19:40:32 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|