diff --git a/core/src/main/java/com/google/errorprone/bugpatterns/time/PreferJavaTimeOverload.java b/core/src/main/java/com/google/errorprone/bugpatterns/time/PreferJavaTimeOverload.java index 8dbda501c87..d14dd969eb0 100644 --- a/core/src/main/java/com/google/errorprone/bugpatterns/time/PreferJavaTimeOverload.java +++ b/core/src/main/java/com/google/errorprone/bugpatterns/time/PreferJavaTimeOverload.java @@ -111,8 +111,10 @@ public final class PreferJavaTimeOverload extends BugChecker private static final Matcher IGNORED_APIS = anyOf( - // For AssertJ - staticMethod().anyClass().namedAnyOf("assertThat", "assumeThat")); + // any static method under org.assertj.* + staticMethod() + .onClass((type, state) -> type.toString().startsWith("org.assertj.")) + .withAnyName()); private static final Matcher JAVA_DURATION_DECOMPOSITION_MATCHER = anyOf( diff --git a/core/src/test/java/com/google/errorprone/bugpatterns/time/PreferJavaTimeOverloadTest.java b/core/src/test/java/com/google/errorprone/bugpatterns/time/PreferJavaTimeOverloadTest.java index b38491b1057..e3755328794 100644 --- a/core/src/test/java/com/google/errorprone/bugpatterns/time/PreferJavaTimeOverloadTest.java +++ b/core/src/test/java/com/google/errorprone/bugpatterns/time/PreferJavaTimeOverloadTest.java @@ -412,4 +412,24 @@ public void durationDividedBy() { "}") .doTest(); } + + // TODO(kak): After upgrading to AssertJ 3.15, double-check that removing the AssertJ matcher from + // PreferJavaTimeOverload.IGNORED_APIS causes these tests to start failing. + @Test + public void assertJ() { + // https://github.com/google/error-prone/issues/1377 + // https://github.com/google/error-prone/issues/1437 + helper + .addSourceLines( + "TestClass.java", + "public class TestClass {", + " public void testAssertThat() {", + " org.assertj.core.api.Assertions.assertThat(1).isEqualTo(1);", + " }", + " public void testAssumeThat() {", + " org.assertj.core.api.Assumptions.assumeThat(1).isEqualTo(1);", + " }", + "}") + .doTest(); + } }