Skip to content

Commit

Permalink
Only match _static_ methods named when/verify.
Browse files Browse the repository at this point in the history
PiperOrigin-RevId: 493588908
  • Loading branch information
graememorgan authored and Error Prone Team committed Dec 7, 2022
1 parent 6f4c1fa commit 6ddbaa4
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
import static com.google.common.collect.Streams.stream;
import static com.google.errorprone.BugPattern.SeverityLevel.WARNING;
import static com.google.errorprone.matchers.Description.NO_MATCH;
import static com.google.errorprone.matchers.Matchers.anyMethod;
import static com.google.errorprone.matchers.Matchers.anyOf;
import static com.google.errorprone.matchers.Matchers.hasAnnotation;
import static com.google.errorprone.matchers.Matchers.staticMethod;
Expand Down Expand Up @@ -195,5 +194,5 @@ private boolean annotatedAtMostMock(Symbol symbol) {
hasAnnotation("org.mockito.InjectMocks");

private static final Matcher<ExpressionTree> WHEN_OR_VERIFY =
anyMethod().anyClass().namedAnyOf("when", "verify");
staticMethod().anyClass().namedAnyOf("when", "verify");
}
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,25 @@ public void spyNeverUsed() {
.doTest();
}

@Test
public void nonStaticVerify_countsAsUse() {
helper
.addSourceLines(
"Test.java",
"import static org.mockito.Mockito.spy;",
"class Test {",
" public Object test() {",
" Test test = spy(new Test());",
" verify(test).test();",
" return null;",
" }",
" Test verify (Test t) {",
" return t;",
" }",
"}")
.doTest();
}

@Test
public void passedToProduction() {
helper
Expand Down

0 comments on commit 6ddbaa4

Please sign in to comment.