Add converter from api User entity to domain entity.

Signed-off-by: Yahor Berdnikau <egorr.berd@gmail.com>
This commit is contained in:
Yahor Berdnikau 2017-11-15 21:56:01 +01:00
parent 6b74a3e563
commit 2402ed6a50
2 changed files with 60 additions and 0 deletions

View File

@ -0,0 +1,23 @@
// Helper functions to convert User entity to domain entity
@file:JvmName("APIUserConverter")
package org.moire.ultrasonic.data
import org.moire.ultrasonic.domain.UserInfo
import org.moire.ultrasonic.api.subsonic.models.User
fun User.toDomainEntity(): UserInfo = UserInfo().apply {
adminRole = this@toDomainEntity.adminRole
commentRole = this@toDomainEntity.commentRole
coverArtRole = this@toDomainEntity.coverArtRole
downloadRole = this@toDomainEntity.downloadRole
email = this@toDomainEntity.email
jukeboxRole = this@toDomainEntity.jukeboxRole
playlistRole = this@toDomainEntity.playlistRole
podcastRole = this@toDomainEntity.podcastRole
scrobblingEnabled = this@toDomainEntity.scrobblingEnabled
settingsRole = this@toDomainEntity.settingsRole
shareRole = this@toDomainEntity.shareRole
streamRole = this@toDomainEntity.streamRole
uploadRole = this@toDomainEntity.uploadRole
userName = this@toDomainEntity.username
}

View File

@ -0,0 +1,37 @@
@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.User
/**
* Test conversion from api [User] to domain [UserInfo].
*/
class APIUserConverterTest {
@Test
fun `Should convert to domain entity`() {
val entity = User(username = "Awsemo", email = "none@none.net", scrobblingEnabled = false,
shareRole = true, streamRole = true)
val domainEntity = entity.toDomainEntity()
with(domainEntity) {
adminRole `should equal to` entity.adminRole
commentRole `should equal to` entity.commentRole
coverArtRole `should equal to` entity.coverArtRole
downloadRole `should equal to` entity.downloadRole
email `should equal to` entity.email
jukeboxRole `should equal to` entity.jukeboxRole
playlistRole `should equal to` entity.playlistRole
podcastRole `should equal to` entity.podcastRole
scrobblingEnabled `should equal to` entity.scrobblingEnabled
settingsRole `should equal to` entity.settingsRole
shareRole `should equal to` entity.shareRole
streamRole `should equal to` entity.streamRole
uploadRole `should equal to` entity.uploadRole
userName `should equal to` entity.username
}
}
}