Add converting MusicDirectoryChild list to domain entities list.

Signed-off-by: Yahor Berdnikau <egorr.berd@gmail.com>
This commit is contained in:
Yahor Berdnikau 2017-09-14 22:01:55 +02:00
parent 2d12aea79f
commit 645728c0f7
2 changed files with 15 additions and 1 deletions

View File

@ -48,6 +48,8 @@ fun MusicDirectoryChild.toDomainEntity(): MusicDirectory.Entry = MusicDirectory.
}
}
fun List<MusicDirectoryChild>.toDomainEntityList() = this.map { it.toDomainEntity() }
fun APIMusicDirectory.toDomainEntity(): MusicDirectory = MusicDirectory().apply {
name = this@toDomainEntity.name
addAll(this@toDomainEntity.childList.map { it.toDomainEntity() })

View File

@ -71,7 +71,7 @@ class APIMusicDirectoryConverterTest {
}
@Test
fun `Should convert MusicDirectoryChild podact entity`() {
fun `Should convert MusicDirectoryChild podcast entity`() {
val entity = MusicDirectoryChild(id = 584, streamId = 394,
artist = "some-artist", publishDate = Calendar.getInstance())
@ -82,4 +82,16 @@ class APIMusicDirectoryConverterTest {
artist `should equal to` dateFormat.format(entity.publishDate?.time)
}
}
@Test
fun `Should convert list of MusicDirectoryChild to domain entity list`() {
val entitiesList = listOf(MusicDirectoryChild(id = 45), MusicDirectoryChild(id = 34))
val domainList = entitiesList.toDomainEntityList()
domainList.size `should equal to` entitiesList.size
domainList.forEachIndexed { index, entry ->
entry `should equal` entitiesList[index].toDomainEntity()
}
}
}