All Downloads are FREE. Search and download functionalities are using the official Maven repository.

jvmTest.com.bkahlert.kommons.debug.ReflectKtTest.kt Maven / Gradle / Ivy

There is a newer version: 2.8.0
Show newest version
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"
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy