-
-
Notifications
You must be signed in to change notification settings - Fork 2.6k
automatically detect class to mock #2779
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
automatically detect class to mock #2779
Conversation
this commit adds method `Mockito.mock()` as a shorter alternative for `Mockito.mock(Class)`. When result of this call is assigned to a variable/field, java will detect the needed class automatically. P.S. I had to ignore errorprone checks "DoNotMock" and "DoNotMockAutoValue" because they fail with IndexOutOfBoundException trying to get the first argument of `Mockito.mock()`. :)
|
This is a super interesting implementation and I am not sure what to think of it. What I like about That said, I am not sure if there is any harm in shipping this method, given that it does resolve the unchecked warning problem for @mockito/developers WDYT? |
|
I do like the concept! I am however not sure if overloading might create some issues here and there, but as our tests compile, it does not seem to be a problem. We are already doing a lot with the Java language that is not intuitive at first glance, so I think this would be a good API addition. |
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.
Please add a new section to the JavaDoc (section 54) that showcases the new feature. Don't forget to also link to the new section in the Contents section at the top.
|
This API is similar to the Spock one where it has been in common use for years. If there are no warnings in IDE, why not to leverage it (assuming no technical glitches are found). is a (current) alternative, but the new one is even more robust (and shorter). Btw, Groovy allows to do that kind of tricks, but I didn't know about that one in Java, good idea @asolntsev! |
Codecov ReportBase: 86.18% // Head: 74.95% // Decreases project coverage by
Additional details and impacted files@@ Coverage Diff @@
## main #2779 +/- ##
=============================================
- Coverage 86.18% 74.95% -11.23%
+ Complexity 2828 2549 -279
=============================================
Files 320 320
Lines 8583 8556 -27
Branches 1060 1044 -16
=============================================
- Hits 7397 6413 -984
- Misses 905 1814 +909
- Partials 281 329 +48
Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here. ☔ View full report at Codecov. |
I also didn't know that Java can detect the class name. |
... similarly to `Mockito.mock()`
|
@szpak @TimvdLippe Similarly to |
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.
2 small nits. I wanted to fix them myself, but I didn't have permission to push to your fork. After that, this LGTM!
Co-authored-by: Tim van der Lippe <
this commit adds method
Mockito.mock()as a shorter alternative forMockito.mock(Class). When result of this call is assigned to a variable/field, java will detect the needed class automatically.P.S. I had to ignore errorprone checks "DoNotMock" and "DoNotMockAutoValue" because they fail with IndexOutOfBoundException trying to get the first argument of
Mockito.mock(). :)