New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Mockk cannot handle sealed classes in every
block
#934
Comments
Looks like a good demo - can you (or someone else) update https://github.com/mockk/mockk/blob/6d5fe10cfd3662c7716f7381ecc6b06bde12a091/modules/mockk/src/commonTest/kotlin/io/mockk/it/SealedClassTest.kt and make a PR? I'd like to see a failing test, then it's easier to fix. |
The test can be something like that: Example testclass SealedInterfaceTest {
@Test
fun serviceTakesSealedInterfaceAsInput() {
val mockNodeId = 1
val factory = mockk<Factory> {
every { getId(any()) } answers { mockNodeId }
}
val result = factory.getId(Root(0))
assertEquals(mockNodeId, result)
}
companion object {
sealed interface Node {
val id: Int
}
data class Root(override val id: Int) : Node
data class Leaf(override val id: Int) : Node
interface Factory {
fun create(): Node
fun getId(node: Node): Int
}
class FactoryImpl : Factory {
override fun create(): Node = Root(0)
override fun getId(node: Node): Int = node.id
}
}
} One way to make it fail is to change JVM target here to The exception itself seems to originate here, so the problem is that we are trying to create a subclass with Byte Buddy, but we can't since we are creating a subclass for interface that is sealed. |
yes please!
The toolchain for tests should be overridden using the config in mockk/buildSrc/src/main/kotlin/buildsrc/convention/toolchain-jvm.gradle.kts Lines 27 to 30 in 6d5fe10
mockk/.github/workflows/gradle.yml Line 19 in 6d5fe10
|
Created a PR with a fix: #939 |
Sample project: https://github.com/ThanksForAllTheFish/mockk832
Related: #832
Mockk 1.13.2 still throws
when using sealed classes on kotlin 1.7 and java 17. The issue now is in
every
blocks, for instance:The text was updated successfully, but these errors were encountered: