jvmTest.com.bkahlert.kommons.debug.ReflectKtTest.kt Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of kommons-debug Show documentation
Show all versions of kommons-debug Show documentation
Kommons Debug is a Kotlin Multiplatform Library for print debugging.
package com.bkahlert.kommons.debug
import io.kotest.assertions.throwables.shouldThrow
import io.kotest.matchers.shouldBe
import org.junit.jupiter.api.Test
import kotlin.reflect.jvm.javaField
class ReflectKtTest {
@Test fun accessible() {
val instance = BaseClass()
val privateProperty = checkNotNull(instance.kProperties0().single { it.name.startsWith("private") }.javaField)
privateProperty.accessible shouldBe false
shouldThrow { privateProperty.get(instance) }
privateProperty.accessible = true
privateProperty.accessible shouldBe true
privateProperty.get(instance) shouldBe "private-base-property"
}
}