-
-
Notifications
You must be signed in to change notification settings - Fork 381
Closed
Description
Prerequisites
Please answer the following questions for yourself before submitting an issue.
- I am running the latest version
- I checked the documentation and found no answer
- I checked to make sure that this issue has not already been filed
Expected Behavior
Can mock a function returning a nullable value class containing another value class
Current Behavior
ClassCastException when calling the mocked function returning aforementioned value class sandwich
Failure Information (for bugs)
This is a regression from 1.13.12 to .13 when returning nested value classes from a mocked function.
Steps to Reproduce
- have a value class
- have another value class containing the first value class
- have a function returning the second value class, nullable
- mock the function
- call the mocked function
Removing the nullability makes the problem go away, as does moving the nullability into either of the value classes.
Context
I'm guessing this is related to the fix for #813
Stack trace
Exception in thread "main" java.lang.ClassCastException: class Outer cannot be cast to class java.lang.String (Outer is in unnamed module of loader 'app'; java.lang.String is in module java.base of loader 'bootstrap')
at Cls.returnValueClass-dzOYYKU(Repro.kt:11)
at ReproKt.main(Repro.kt:17)
at ReproKt.main(Repro.kt)
Minimal reproducible code (the gist of this issue)
// --------- Gradle deps
dependencies {
implementation("io.mockk:mockk:1.13.13")
}
// --------- code ---------
import io.mockk.every
import io.mockk.mockk
@JvmInline
value class Inner(val underlying: String)
@JvmInline
value class Outer(val inner: Inner)
open class Cls {
fun returnValueClass(): Outer? = null
}
fun main() {
val mock = mockk<Cls>()
every { mock.returnValueClass() } returns Outer(Inner("mock"))
println(mock.returnValueClass())
}
Rawa, joni-, StevenMeliopoulos-at, monosoul, mz-efento and 5 more
Metadata
Metadata
Assignees
Labels
No labels