Skip to content

Commit

Permalink
Disable PreferJavaTimeOverload for all static methods in AssertJ.
Browse files Browse the repository at this point in the history
See #1436

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=284565007
  • Loading branch information
kluever authored and cgdecker committed Dec 9, 2019
1 parent bdc5309 commit 2dee020
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -111,8 +111,10 @@ public final class PreferJavaTimeOverload extends BugChecker

private static final Matcher<ExpressionTree> 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<ExpressionTree> JAVA_DURATION_DECOMPOSITION_MATCHER =
anyOf(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
}

0 comments on commit 2dee020

Please sign in to comment.