Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix error-prone suppressions with JUnit5 @TestTemplate #892

Merged
merged 2 commits into from
Sep 26, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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