-
Notifications
You must be signed in to change notification settings - Fork 205
Follow-up on primitive value classes #561
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
Conversation
…tc.) to ValueClassSupport.kt
6ae5106 to
bb0c67a
Compare
|
Thanks! This is a great improvement. I ran our tests against this and it fixed several issues. I found two remaining issues.
example: fails to build with:
I tried using
In this test case you added I can work around in test code by adding the cast but is there a way to fix this to avoid this requirement? |
|
Many thanks for the feedback, I will dive into both issues and hope to come with improvements. |
…ents: let the matcher match with either boxed or unboxed value as actual call argument.
|
I was able to find a solution for the 2nd issue you mentioned. Within the definition of the matchers there is no context of the parameter signatures of the stubbed function call, it should match with. Therefore there is no way to detect the mismatch between a nullable function parameter and a non-nullable argument for the eq matcher function. I've fixed the mismatch for (nullable) arguments in eqValueClass() by relaxing that matcher: it now matches the actual mock function call argument against either the boxed or unboxed value of eq-matcher's argument. I will have a look into the captor issue later this weekend. |
|
The issue with the captors is a nasty one: the I have introduced a new factory method At least, the use of ArgumentCator with (suspend) funtion arguments is now covered with tests. For me this completes this PR, I hope you agree with me. |
TimvdLippe
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
General approach LGTM. Will let @jselbo do the in-depth review.
|
I would like to suggest to first focus on getting this PR merged, before merging #556. After merging this one, and rebasing #556, I can adjust documentation of new API to that of the other API. Also the added test cases should be updated to align with the other tests. I can do so in an additional commit after rebasing. |
|
Code changes LGTM 👍 I checked with the latest changes and all our tests are passing, after making use of the new |
|
Can you comment on KT-47562 linking to this PR and saying this complicates the public API for a very popular mocking framework? Maybe a bump will motivate Jetbrains to fix the issue with |
I've just posted a comment explaining the troubles encountered here due to |
This PR is a direct follow-up to #557 , in which @jselbo introduced some test cases that proved Mockito-Kotlin to fail on handling (nullable) primitive value types in eq matcher and argument captor.
Some background: Kotlin compiler will typically pass on value classes unboxed to Java calls. While unboxing, it will apply the nullability of the value class to the unboxed inner type. But with one exception: when the inner type is a Java primitive then nullability cannot be applied to that primitive. In that case Kotlin compiler passes on the unboxed value type into Java calls.
This exceptional behavior is what is breaking MOckito-Kotlin.
To fully cover handling of (nullable) primitive value class types, tests have been added/activated for those types in eq and any matchers, in argument captors and as return values in synchronous and suspendable functions.
Additionally, the boxing and unboxing logic has been extracted to a new class ValueClassSupport, to facilitate for reuse of the logic and to test the logic with dedicated unit tests.