49 lines
1.5 KiB
Kotlin
49 lines
1.5 KiB
Kotlin
package be.simplenotes.persistance.converters
|
|
|
|
import be.simplenotes.domain.model.PersistedUser
|
|
import be.simplenotes.domain.model.User
|
|
import be.simplenotes.persistance.users.UserEntity
|
|
import org.assertj.core.api.Assertions.assertThat
|
|
import org.junit.jupiter.api.Test
|
|
import org.mapstruct.factory.Mappers
|
|
|
|
internal class UserConverterTest {
|
|
|
|
@Test
|
|
fun `convert UserEntity to User`() {
|
|
val converter = Mappers.getMapper(UserConverter::class.java)
|
|
val entity = UserEntity {
|
|
username = "test"
|
|
password = "test2"
|
|
}.apply {
|
|
this["id"] = 2
|
|
}
|
|
val user = converter.toUser(entity)
|
|
assertThat(user).isEqualTo(User("test", "test2"))
|
|
}
|
|
|
|
@Test
|
|
fun `convert UserEntity to PersistedUser`() {
|
|
val converter = Mappers.getMapper(UserConverter::class.java)
|
|
val entity = UserEntity {
|
|
username = "test"
|
|
password = "test2"
|
|
}.apply {
|
|
this["id"] = 2
|
|
}
|
|
val user = converter.toPersistedUser(entity)
|
|
assertThat(user).isEqualTo(PersistedUser("test", "test2", 2))
|
|
}
|
|
|
|
@Test
|
|
fun `convert User to UserEntity`() {
|
|
val converter = Mappers.getMapper(UserConverter::class.java)
|
|
val user = User("test", "test2")
|
|
val entity = converter.toEntity(user)
|
|
|
|
assertThat(entity)
|
|
.hasFieldOrPropertyWithValue("username", "test")
|
|
.hasFieldOrPropertyWithValue("password", "test2")
|
|
}
|
|
}
|