-
-
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
Steps to Reproduce
When using a value class with init {}
validation, such as this example:
@JvmInline value class MyToken(val raw: 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
}
interface UserOfMyToken {
fun useMyToken(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 class MyToken(val raw: 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.
Metadata
Metadata
Assignees
Labels
No labels