jvmTest.com.bkahlert.kommons.debug.JvmRenderKtTest.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 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 ""
}
}