49 lines
1.4 KiB
Kotlin
49 lines
1.4 KiB
Kotlin
package be.simplenotes.persistence.converters
|
|
|
|
import be.simplenotes.persistence.users.UserEntity
|
|
import be.simplenotes.types.PersistedUser
|
|
import be.simplenotes.types.User
|
|
import io.micronaut.context.BeanContext
|
|
import org.assertj.core.api.Assertions.assertThat
|
|
import org.junit.jupiter.api.Test
|
|
|
|
internal class UserConverterTest {
|
|
|
|
private val ctx = BeanContext.run()
|
|
private val converter = ctx.getBean(UserConverter::class.java)
|
|
|
|
@Test
|
|
fun `convert UserEntity to User`() {
|
|
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 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 user = User("test", "test2")
|
|
val entity = converter.toEntity(user)
|
|
|
|
assertThat(entity)
|
|
.hasFieldOrPropertyWithValue("username", "test")
|
|
.hasFieldOrPropertyWithValue("password", "test2")
|
|
}
|
|
}
|