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

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

There is a newer version: 2.8.0
Show newest version
package com.bkahlert.kommons.debug

import com.bkahlert.kommons.debug.CustomToString.Ignore
import com.bkahlert.kommons.test.testAll
import io.kotest.matchers.shouldBe
import org.junit.jupiter.api.Test
import kotlin.collections.Map.Entry

class JvmRenderTest {

    @Test fun render_inaccessible() = testAll {

        val evilMap: Map = object : AbstractMap() {
            override fun equals(other: Any?): Boolean = false
            override fun hashCode(): Int = 1
            override val entries: Set>
                get() = error("no entries")

            override fun toString(): String {
                return "string representation"
            }
        }
        val veryEvilMap: Map = object : AbstractMap() {
            override fun equals(other: Any?): Boolean = false
            override fun hashCode(): Int = 1
            override val entries: Set>
                get() = error("no entries")

            override fun toString(): String {
                return StackTrace.get().findOrNull { it.methodName == "toCustomStringOrNull" }?.toString()
                    ?: error("no string")
            }
        }

        evilMap.render { customToString = Ignore } shouldBe ""
        veryEvilMap.render { customToString = Ignore } shouldBe ""
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy