You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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
Steps to Reproduce
When using a value class with init {} validation, such as this example:
@JvmInline value classMyToken(valraw:String) {
init { require(raw.startsWith("MY_PREFIX::")) }
}
Then a mock such as this
@Test
fun`should work with value classes`() {
registerInstanceFactory {
println("called")
MyToken("MY_PREFIX::bar")
}
val userOfMyToken = mockk<UserOfMyToken>()
every { userOfMyToken.useMyToken(any()) } returns Unit
}
interfaceUserOfMyToken {
funuseMyToken(myToken:MyToken)
}
Then "called" is not logged, and the test fails with an IllegalArgumentException on the init's require().
But if I just change the value class to a data class:
data classMyToken(valraw:String) {
init { require(raw.startsWith("MY_PREFIX::")) }
}
Then "called"is logged, and the the test passes. And using withInstanceFactory instead of registerInstanceFactory produces the same result.
The text was updated successfully, but these errors were encountered:
scmorse
changed the title
registerInstanceFactory / withInstanceFactory suppliers are not used for value classesregisterInstanceFactory supplier is not used for value classes
Jan 9, 2024
Prerequisites
Please answer the following questions for yourself before submitting an issue.
Steps to Reproduce
When using a value class with
init {}
validation, such as this example:Then a mock such as this
Then
"called"
is not logged, and the test fails with anIllegalArgumentException
on the init'srequire()
.But if I just change the value class to a data class:
Then
"called"
is logged, and the the test passes. And usingwithInstanceFactory
instead ofregisterInstanceFactory
produces the same result.The text was updated successfully, but these errors were encountered: