Skip to content

Commit

Permalink
Check visibility of @testtemplate methods
Browse files Browse the repository at this point in the history
Update `SpringJUnit5Check` to check that `@TestTemplate` methods are not
public or private.

See gh-138
  • Loading branch information
dreis2211 authored and philwebb committed Dec 3, 2019
1 parent 64aff5e commit ab6f20d
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 @@ -40,8 +40,11 @@ public class SpringJUnit5Check extends AbstractSpringCheck {

private static final String JUNIT5_TEST_ANNOTATION = "org.junit.jupiter.api.Test";

private static final String JUNIT5_TEST_TEMPLATE_ANNOTATION = "org.junit.jupiter.api.TestTemplate";

private static final List<String> TEST_ANNOTATIONS = Collections
.unmodifiableList(Arrays.asList("Test", JUNIT4_TEST_ANNOTATION, JUNIT5_TEST_ANNOTATION));
.unmodifiableList(Arrays.asList("Test", "TestTemplate", JUNIT4_TEST_ANNOTATION, JUNIT5_TEST_ANNOTATION,
JUNIT5_TEST_TEMPLATE_ANNOTATION));

private static final List<String> LIFECYCLE_ANNOTATIONS = Collections.unmodifiableList(Arrays.asList("BeforeAll",
"org.junit.jupiter.api.BeforeAll", "BeforeEach", "org.junit.jupiter.api.BeforeEach", "AfterAll",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
+Test method 'doSomethingWorks' should not be public
+Test method 'doSomethingElseWorks' should not be private
+Test method 'doSomethingWithTemplateWorks' should not be public
+Test method 'doSomethingElseWithTemplateWorks' should not be private
+Lifecycle method 'publicBeforeAll' should not be public
+Lifecycle method 'publicBeforeEach' should not be public
+Lifecycle method 'publicAfterAll' should not be public
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,4 +73,14 @@ private void doSomethingElseWorks() {
// test here
}

@TestTemplate
public void doSomethingWithTemplateWorks() {
// test here
}

@TestTemplate
private void doSomethingElseWithTemplateWorks() {
// test here
}

}

0 comments on commit ab6f20d

Please sign in to comment.