Make the public test classes check configurable.
package io.jenkins.plugins.analysis.core.testutil;
-import org.junit.jupiter.api.Test;
-
+import com.tngtech.archunit.base.DescribedPredicate;
+import com.tngtech.archunit.core.domain.JavaClass;
import com.tngtech.archunit.core.domain.JavaClasses;
-import com.tngtech.archunit.core.domain.JavaModifier;
import com.tngtech.archunit.core.importer.ClassFileImporter;
-import com.tngtech.archunit.lang.ArchRule;
-import static com.tngtech.archunit.lang.syntax.ArchRuleDefinition.*;
+import static com.tngtech.archunit.core.domain.JavaClass.Predicates.*;
+import static com.tngtech.archunit.lang.conditions.ArchPredicates.*;
/**
* Defines several architecture rules for the static analysis utilities.
@@ -16,31 +15,14 @@ import static com.tngtech.archunit.lang.syntax.ArchRuleDefinition.*;
*/
// FIXME: forbid calls to Jenkins.getInstance()
class ArchitectureRulesTest extends edu.hm.hafner.ArchitectureRulesTest {
- /**
- * Returns the classes that should be checked.
- *
- * @return the classes that should be checked
- */
@Override
protected JavaClasses getAllClasses() {
return new ClassFileImporter().importPackages("io.jenkins.plugins.analysis");
}
- /**
- * Test classes should not be public (Junit 5). Only {@link IntegrationTest} classes are required to use JUnit 4.
- */
- @Test
- void shouldNotUsePublicInTestCases() {
- JavaClasses classes = getAllClasses();
-
- ArchRule noPublicTestClassesDefined = noClasses()
- .that().dontHaveModifier(JavaModifier.ABSTRACT)
- .and().haveNameNotMatching(getClass().getName())
- .and().haveSimpleNameEndingWith("Test")
- .and().haveSimpleNameNotEndingWith("ITest")
- .should().bePublic();
-
- noPublicTestClassesDefined.check(classes);
+ @Override
+ protected DescribedPredicate<? super JavaClass> areAllowedPublicTestClasses() {
+ return have(simpleNameEndingWith("ITest"));
}
@Override
