|
4 | 4 | import java.util.List; |
5 | 5 | import java.util.stream.Collectors; |
6 | 6 |
|
| 7 | +import org.junit.jupiter.api.Test; |
| 8 | +import org.junit.jupiter.params.ParameterizedTest; |
| 9 | + |
7 | 10 | import com.tngtech.archunit.base.DescribedPredicate; |
8 | 11 | import com.tngtech.archunit.core.domain.JavaClass; |
9 | 12 | import com.tngtech.archunit.core.domain.JavaMethod; |
10 | 13 | import com.tngtech.archunit.core.domain.JavaModifier; |
| 14 | +import com.tngtech.archunit.junit.ArchTest; |
11 | 15 | import com.tngtech.archunit.lang.ArchCondition; |
12 | 16 | import com.tngtech.archunit.lang.ArchRule; |
13 | 17 | import com.tngtech.archunit.lang.ConditionEvents; |
@@ -53,6 +57,19 @@ public final class PluginArchitectureRules { |
53 | 57 | .and().haveSimpleNameNotEndingWith("ITest") |
54 | 58 | .should().bePublic(); |
55 | 59 |
|
| 60 | + /** Junit 5 test methods should not be public. */ |
| 61 | + public static final ArchRule NO_PUBLIC_TEST_METHODS = |
| 62 | + methods().that().areAnnotatedWith(Test.class) |
| 63 | + .or().areAnnotatedWith(ParameterizedTest.class) |
| 64 | + .and().areDeclaredInClassesThat() |
| 65 | + .haveSimpleNameEndingWith("Test") |
| 66 | + .should().notBePublic(); |
| 67 | + |
| 68 | + /** ArchUnit tests should not be public. */ |
| 69 | + public static final ArchRule NO_PUBLIC_ARCHITECTURE_TESTS = |
| 70 | + fields().that().areAnnotatedWith(ArchTest.class) |
| 71 | + .should().notBePublic(); |
| 72 | + |
56 | 73 | /** Some packages that are transitive dependencies of Jenkins should not be used at all. */ |
57 | 74 | public static final ArchRule NO_FORBIDDEN_PACKAGE_ACCESSED |
58 | 75 | = noClasses().should().dependOnClassesThat(resideInAnyPackage( |
|
0 commit comments