Skip to content

Commit

Permalink
Fix error-prone suppressions with JUnit5 @testtemplate (#892)
Browse files Browse the repository at this point in the history
Certain error-prone checks are disabled in test code, and the presence of JUnit5's `@TestTemplate` annotation is now used to detect whether a class is test code.
  • Loading branch information
iamdanfox authored and bulldozer-bot[bot] committed Sep 26, 2019
1 parent b7f4641 commit f38e76a
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,10 @@ static boolean isTestCode(VisitorState state) {
}

private static final Matcher<ClassTree> hasJUnit5TestCases =
Matchers.hasMethod(Matchers.hasAnnotationOnAnyOverriddenMethod("org.junit.jupiter.api.Test"));
Matchers.hasMethod(Matchers.anyOf(
Matchers.hasAnnotationOnAnyOverriddenMethod("org.junit.jupiter.api.Test"),
Matchers.hasAnnotationOnAnyOverriddenMethod("org.junit.jupiter.api.TestTemplate")));

private static final Matcher<ClassTree> hasTestCases = Matchers
.anyOf(JUnitMatchers.hasJUnit4TestCases, hasJUnit5TestCases);
}
Original file line number Diff line number Diff line change
Expand Up @@ -138,11 +138,16 @@ public void illegal_state_exception_in_junit5_test_method_doesnt_match() {
compilationHelper.addSourceLines(
"FooTest.java",
"import org.junit.jupiter.api.Test;",
"import org.junit.jupiter.api.TestTemplate;",
"class FooTest {",
" @Test",
" public void run_junit5_test() {",
" throw new IllegalStateException(\"constant\");",
" }",
" @TestTemplate",
" public void junit5_test_template() {",
" throw new IllegalStateException(\"constant\");",
" }",
"}").doTest();
}

Expand Down
7 changes: 7 additions & 0 deletions changelog/@unreleased/pr-892.v2.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
type: fix
fix:
description: Certain error-prone checks are disabled in test code, and the presence
of JUnit5's `@TestTemplate` annotation is now used to detect whether a class is
test code.
links:
- https://github.com/palantir/gradle-baseline/pull/892

0 comments on commit f38e76a

Please sign in to comment.