https://kotlinlang.org logo
#kotest
Title
# kotest
a

Angus

01/26/2023, 9:33 AM
I'm getting a deprecation warning that
Arb.bind()
is "Superceded by bind without KClass parameter.". However in my case the reified generic version can't work for me - I need the version that takes a KClass because I'm getting the types dynamically at runtime. Is there a non-deprecated alternative/can this deprecation be reversed? If interested, my use case is to iterate all sealed subclasses of an interface, to validate they all have a unique name:
Copy code
@Test
    fun `all event names are unique`() {
        val subclasses = AppEvent::class.sealedSubclasses

        val eventNames = mutableSetOf<String>()
        for (subclass in subclasses) {
            // subclass isn't known at compile time, so I can't use the reified version of this call
            val instance = Arb.bind(eventArbs, subclass).next()

            println("Got subclass $subclass with event name ${instance.payloadType}")
            assertTrue(
                "${instance.payloadType} event name is not unique",
                eventNames.add(instance.payloadType))
        }
    }