Fail the build when naming conventions violated (#3974)

* Failing build if unit test name does not follow one of the following conventions : ..IntegrationTest, ..LongRunningUnitTest, ..ManualTest, ..JdbcTest, ..LiveTest

* Custom PMD Rules project

* Fixed this issue when unit test classes were not being scanned by custom PMD rule (This happened after I pulled code from upstream project)

* Don't fail the build if PMD custom rule fails

* Reconfigure PMD

* Reformat POM

* Adjust PMD rules

* Rename test
This commit is contained in:
Grzegorz Piwowarek
2018-04-10 23:50:17 +02:00
committed by GitHub
parent ecca8c9a89
commit d337266c7a
5 changed files with 148 additions and 23 deletions

View File

@@ -0,0 +1,32 @@
package org.baeldung.pmd;
import net.sourceforge.pmd.lang.java.ast.ASTClassOrInterfaceDeclaration;
import net.sourceforge.pmd.lang.java.rule.AbstractJavaRule;
import java.util.Arrays;
import java.util.List;
import java.util.Objects;
public class UnitTestNamingConventionRule extends AbstractJavaRule {
private static List<String> allowedEndings = Arrays.asList(
"IntegrationTest",
"LongRunningUnitTest",
"ManualTest",
"JdbcTest",
"LiveTest");
public Object visit(ASTClassOrInterfaceDeclaration node, Object data) {
String className = node.getImage();
Objects.requireNonNull(className);
if (className.endsWith("Test") || className.endsWith("Tests")) {
if (allowedEndings.stream()
.noneMatch(className::endsWith)) {
addViolation(data, node);
}
}
return data;
}
}