diff --git a/core/src/main/java/com/google/errorprone/bugpatterns/MockNotUsedInProduction.java b/core/src/main/java/com/google/errorprone/bugpatterns/MockNotUsedInProduction.java index e7a32649353..fab61e95b5c 100644 --- a/core/src/main/java/com/google/errorprone/bugpatterns/MockNotUsedInProduction.java +++ b/core/src/main/java/com/google/errorprone/bugpatterns/MockNotUsedInProduction.java @@ -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; @@ -195,5 +194,5 @@ private boolean annotatedAtMostMock(Symbol symbol) { hasAnnotation("org.mockito.InjectMocks"); private static final Matcher WHEN_OR_VERIFY = - anyMethod().anyClass().namedAnyOf("when", "verify"); + staticMethod().anyClass().namedAnyOf("when", "verify"); } diff --git a/core/src/test/java/com/google/errorprone/bugpatterns/MockNotUsedInProductionTest.java b/core/src/test/java/com/google/errorprone/bugpatterns/MockNotUsedInProductionTest.java index 97214fe4b91..17acafacc6b 100644 --- a/core/src/test/java/com/google/errorprone/bugpatterns/MockNotUsedInProductionTest.java +++ b/core/src/test/java/com/google/errorprone/bugpatterns/MockNotUsedInProductionTest.java @@ -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