Add JukeboxStatus converter to domain entity.

Signed-off-by: Yahor Berdnikau <egorr.berd@gmail.com>
This commit is contained in:
Yahor Berdnikau 2017-11-07 21:57:43 +01:00
parent 947a1ce3b5
commit 17aaa0f87f
2 changed files with 39 additions and 0 deletions

View File

@ -0,0 +1,13 @@
// Collection of function to convert subsonic api jukebox responses to app entities
@file:JvmName("APIJukeboxConverter")
package org.moire.ultrasonic.data
import org.moire.ultrasonic.domain.JukeboxStatus
import org.moire.ultrasonic.api.subsonic.models.JukeboxStatus as ApiJukeboxStatus
fun ApiJukeboxStatus.toDomainEntity(): JukeboxStatus = JukeboxStatus().apply {
positionSeconds = this@toDomainEntity.position
setCurrentIndex(this@toDomainEntity.currentIndex)
isPlaying = this@toDomainEntity.playing
gain = this@toDomainEntity.gain
}

View File

@ -0,0 +1,26 @@
@file:Suppress("IllegalIdentifier")
package org.moire.ultrasonic.data
import org.amshove.kluent.`should equal to`
import org.junit.Test
import org.moire.ultrasonic.api.subsonic.models.JukeboxStatus
/**
* Unit test for functions in [APIJukeboxConverter.kt] file.
*/
class APIJukeboxConverterTest {
@Test
fun `Should convert JukeboxStatus to domain entity`() {
val entity = JukeboxStatus(45, true, 0.11f, 442)
val convertedEntity = entity.toDomainEntity()
with(convertedEntity) {
currentPlayingIndex `should equal to` entity.currentIndex
gain `should equal to` entity.gain
isPlaying `should equal to` entity.playing
positionSeconds `should equal to` entity.position
}
}
}