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
Cleaner code for Mockito users by better integration with static code checkers, more @CheckReturnValue #1270
Cleaner code for Mockito users by better integration with static code checkers, more @CheckReturnValue #1270
Conversation
Note that almost all non- |
Codecov Report
@@ Coverage Diff @@
## release/2.x #1270 +/- ##
=============================================
Coverage 88.2% 88.2%
Complexity 2355 2355
=============================================
Files 291 291
Lines 5945 5945
Branches 709 709
=============================================
Hits 5244 5244
Misses 521 521
Partials 180 180
Continue to review full report at Codecov.
|
Context for this change: within a company-internal PR I found an unused |
The reason I did not include these methods in #1228 was because there were no side-effects. Checking them would therefore not required, as it would be perfectly okay (from a Mockito-perspective) that these methods are invoked and then discarded. The methods I annotated do have side-effects and thus are harmful if you discard the return value. Therefore I am hesitant to accept this PR, as (to my knowledge) these methods are pure and are not harmful for Mockito to be invoked a lot of times. |
Invoking these methods many times may not be harmful in a functional sense, but IMHO Looking at Guava, that seems to be the way how they use the annotation. For example, it is applied to the whole package |
I do understand that point-of-view. However, in that case we would need to update every public API that is non-void to have this annotation, which seems counter-intuitive. Anyways, these are my 2 cents. Paging @mockito/core to give their opinion 😄 |
Well a single annotation in But indeed, let's see how others feel about it. |
Interesting discussion! Here's how I would summarize the decision point:
Given that we already started using the annotations, the downside b) already applies. Merging the PR does not make it any worse. Hence, the downside can be discounted and we only have the benefit :) +1 I'm in favor of merging the PR. Thank you @Stephan202 for tracing the public API methods and coming up with the PR! |
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 rebase on current master as we incorporated ErrorProne, which will probably complain about some of these additions.
@TimvdLippe the current |
Ah my brain was derping. I was working on #1339 and thought I merged it, but I did not. So we have to rebase after that PR is merged. Sorry for the confusion. |
No worries 😄. I see #1339 also targets the (And indeed, that PR contains a bunch of I've subscribed to the other PR and will rebase again once it's merged. |
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.
@TimvdLippe I saw that #1228 was merged, so I rebased this PR and fixed the tests. PTAL :)
@@ -26,7 +26,6 @@ | |||
|
|||
@Test | |||
public void shouldResetOngoingStubbingSoThatMoreMeaningfulExceptionsAreRaised() { | |||
mock(IMethods.class); |
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.
I dropped this statement instead of adding @SuppressWarnings({"CheckReturnValue", "MockitoUsage"})
, but maybe I just don't understand how this statement is relevant to the test. (I would have expected an interaction with the @Mock
ed field.) Let me know if I should revert this.
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.
Yeah this seems fine to me 👍
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.
Awesome thanks!
Builds on #1130, #1228.