Skip to content

Commit 6b0dcf2

Browse files
committed
Merge pull request #138 from dreis2211
* pr/138: Check visibility of @testtemplate methods Closes gh-138
2 parents 64aff5e + ab6f20d commit 6b0dcf2

File tree

3 files changed

+16
-1
lines changed

3 files changed

+16
-1
lines changed

spring-javaformat/spring-javaformat-checkstyle/src/main/java/io/spring/javaformat/checkstyle/check/SpringJUnit5Check.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,11 @@ public class SpringJUnit5Check extends AbstractSpringCheck {
4040

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

43+
private static final String JUNIT5_TEST_TEMPLATE_ANNOTATION = "org.junit.jupiter.api.TestTemplate";
44+
4345
private static final List<String> TEST_ANNOTATIONS = Collections
44-
.unmodifiableList(Arrays.asList("Test", JUNIT4_TEST_ANNOTATION, JUNIT5_TEST_ANNOTATION));
46+
.unmodifiableList(Arrays.asList("Test", "TestTemplate", JUNIT4_TEST_ANNOTATION, JUNIT5_TEST_ANNOTATION,
47+
JUNIT5_TEST_TEMPLATE_ANNOTATION));
4548

4649
private static final List<String> LIFECYCLE_ANNOTATIONS = Collections.unmodifiableList(Arrays.asList("BeforeAll",
4750
"org.junit.jupiter.api.BeforeAll", "BeforeEach", "org.junit.jupiter.api.BeforeEach", "AfterAll",

spring-javaformat/spring-javaformat-checkstyle/src/test/resources/check/JUnit5BadModifier.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
+Test method 'doSomethingWorks' should not be public
22
+Test method 'doSomethingElseWorks' should not be private
3+
+Test method 'doSomethingWithTemplateWorks' should not be public
4+
+Test method 'doSomethingElseWithTemplateWorks' should not be private
35
+Lifecycle method 'publicBeforeAll' should not be public
46
+Lifecycle method 'publicBeforeEach' should not be public
57
+Lifecycle method 'publicAfterAll' should not be public

spring-javaformat/spring-javaformat-checkstyle/src/test/resources/source/JUnit5BadModifier.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,4 +73,14 @@ private void doSomethingElseWorks() {
7373
// test here
7474
}
7575

76+
@TestTemplate
77+
public void doSomethingWithTemplateWorks() {
78+
// test here
79+
}
80+
81+
@TestTemplate
82+
private void doSomethingElseWithTemplateWorks() {
83+
// test here
84+
}
85+
7686
}

0 commit comments

Comments
 (0)