error-prone-support
error-prone-support copied to clipboard
Introduce BugPattern for removing duplicate `Mockito.verifyNoInteractions()` calls
Problem
When verifying that mocks didn't have interactions in tests sometimes many calls to Mockito.verifyNoInteractions()
are used
verifyNoInteractions(mock1);
verifyNoInteractions(mock2);
which unnecessarily pollutes the code, because this method actually accepts varargs.
This can be simplified to just:
verifyNoInteractions(mock1, mock2);
Description of the proposed new feature
- [x] Support a stylistic preference.
- [x] Avoid a common gotcha, or potential problem.
- [ ] Improve performance.
We should rewrite multiple calls to verifyNoInteractions
to one call.
I would like to rewrite the following code:
verifyNoInteractions(mock1);
verifyNoInteractions(mock2);
...
verifyNoInteractions(mockN);
to:
verifyNoInteractions(mock1, mock2, ..., mockN);
Considerations
Tricky parts in my opinion are:
- That there might be a variable number of mocks verified in this way.
- That multiple individual calls might not be consequential.
- That the scope we need to check this must be just inside one test method.
Participation
- [x] I am willing to submit a pull request to implement this improvement.(I'm willing to try to submit a pr, this will be my first encounter with error prone 🙂)