From 17aaa0f87f3212f5c7918960c0250d8c1583c23e Mon Sep 17 00:00:00 2001 From: Yahor Berdnikau Date: Tue, 7 Nov 2017 21:57:43 +0100 Subject: [PATCH] Add JukeboxStatus converter to domain entity. Signed-off-by: Yahor Berdnikau --- .../ultrasonic/data/APIJukeboxCoverter.kt | 13 ++++++++++ .../data/APIJukeboxConverterTest.kt | 26 +++++++++++++++++++ 2 files changed, 39 insertions(+) create mode 100644 ultrasonic/src/main/kotlin/org/moire/ultrasonic/data/APIJukeboxCoverter.kt create mode 100644 ultrasonic/src/test/kotlin/org/moire/ultrasonic/data/APIJukeboxConverterTest.kt diff --git a/ultrasonic/src/main/kotlin/org/moire/ultrasonic/data/APIJukeboxCoverter.kt b/ultrasonic/src/main/kotlin/org/moire/ultrasonic/data/APIJukeboxCoverter.kt new file mode 100644 index 00000000..bb4fe9a1 --- /dev/null +++ b/ultrasonic/src/main/kotlin/org/moire/ultrasonic/data/APIJukeboxCoverter.kt @@ -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 +} diff --git a/ultrasonic/src/test/kotlin/org/moire/ultrasonic/data/APIJukeboxConverterTest.kt b/ultrasonic/src/test/kotlin/org/moire/ultrasonic/data/APIJukeboxConverterTest.kt new file mode 100644 index 00000000..846970a6 --- /dev/null +++ b/ultrasonic/src/test/kotlin/org/moire/ultrasonic/data/APIJukeboxConverterTest.kt @@ -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 + } + } +}