Skip to content

Commit 9ef995b

Browse files
authored
Merge pull request #73 from jenkinsci/no-public-tests
Add architecture tests to check that no tests are `public`
2 parents ed52355 + 818fa29 commit 9ef995b

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

src/test/java/io/jenkins/plugins/util/PluginArchitectureRules.java

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,14 @@
44
import java.util.List;
55
import java.util.stream.Collectors;
66

7+
import org.junit.jupiter.api.Test;
8+
import org.junit.jupiter.params.ParameterizedTest;
9+
710
import com.tngtech.archunit.base.DescribedPredicate;
811
import com.tngtech.archunit.core.domain.JavaClass;
912
import com.tngtech.archunit.core.domain.JavaMethod;
1013
import com.tngtech.archunit.core.domain.JavaModifier;
14+
import com.tngtech.archunit.junit.ArchTest;
1115
import com.tngtech.archunit.lang.ArchCondition;
1216
import com.tngtech.archunit.lang.ArchRule;
1317
import com.tngtech.archunit.lang.ConditionEvents;
@@ -53,6 +57,19 @@ public final class PluginArchitectureRules {
5357
.and().haveSimpleNameNotEndingWith("ITest")
5458
.should().bePublic();
5559

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+
5673
/** Some packages that are transitive dependencies of Jenkins should not be used at all. */
5774
public static final ArchRule NO_FORBIDDEN_PACKAGE_ACCESSED
5875
= noClasses().should().dependOnClassesThat(resideInAnyPackage(

0 commit comments

Comments
 (0)