-
-
Notifications
You must be signed in to change notification settings - Fork 345
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
any() doesn't work for value classes #847
Comments
See here: #152 There's a workaround in this comment: #152 (comment) |
Thanks @aSemy However, I still notice very strange behaviour of First problem:Consider following setup: @JvmInline
value class Foo(private val value: UUID)
@JvmInline
value class Bar(private val value: BigDecimal) {
override fun toString(): String = value.toPlainString()
}
data class Wrapper(
val bar: Bar,
)
class Service {
fun method(wrapper: Wrapper, foo: Foo) {}
}
class AnyDoesntWork : StringSpec({
"mocking fails on BigDecimal.toPlainString()" {
val mock = mockk<Service>()
verify(exactly = 0) { mock.method(any(), any()) }
}
}) this will fail with an exception:
I don't know what exactly is causing this problem, but I noticed to get this exception you have to have:
If you change any of these, the error will not appear. Second problem:Also, there is another problem I encountered. Trying to do simple class Service {
fun method(foo: Foo) {}
}
class AnyDoesntWork : StringSpec({
"mocking doesnt work" {
val mock = mockk<Service>()
verify(exactly = 0) { mock.method(any()) }
}
}) this throws an exception:
I'm using Kotest 5.4.0 and MockK 1.12.5 |
Yeah - nested value classes aren't supported at present #859 |
@aSemy right! and what about the second issue? |
might be related to to my comment #849 (comment) |
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions. If you are sure that this issue is important and should not be marked as |
Prerequisites
Please answer the following questions for yourself before submitting an issue.
Expected Behavior
The mock works and returns expected value from method
Current Behavior
Test fails with
NullPointerException
fromio.mockk.impl.recording.states.RecordingState.matcher(RecordingState.kt:53)
Failure Information (for bugs)
After running the test where I use
any()
for value class I get NPE. I did not find any info about using value classes in MockK in your docs. However I've found similar issue reported in Mockito's GitHub: mockito/mockito-kotlin#445Steps to Reproduce
Create such classes:
and then one test:
Just run and you should get NPE.
Context
Failure Logs
The output of such test is as follows:
The text was updated successfully, but these errors were encountered: