use of com.tngtech.archunit.lang.ArchRule in project checkstyle-backport-jre8 by rnveach.
the class ArchUnitTest method nonProtectedCheckMethodsTest.
/**
* The goal is to ensure all classes of a specific name pattern have non-protected methods,
* except for those which are annotated with {@code Override}. In the bytecode there is no
* trace anymore if this method was annotated with {@code Override} or not (limitation of
* Archunit), eventually we need to make checkstyle's Check on this.
* Test contains assertions in the callstack, but TeamCity inspection does not see them.
*
* @noinspection JUnitTestMethodWithNoAssertions
*/
@Test
public void nonProtectedCheckMethodsTest() {
// This list contains methods which have been overridden and are set to ignore in this test.
final String[] methodsWithOverrideAnnotation = { "processFiltered", "getMethodName", "mustCheckName", "postProcessHeaderLines", "getLogMessageId" };
final String ignoreMethodList = String.join("|", methodsWithOverrideAnnotation);
final JavaClasses importedClasses = new ClassFileImporter().withImportOption(ImportOption.Predefined.DO_NOT_INCLUDE_TESTS).importPackages("com.puppycrawl.tools.checkstyle.checks");
final ArchRule checkMethodsShouldNotBeProtectedRule = methods().that().haveNameNotMatching(".*(" + ignoreMethodList + ")").and().areDeclaredInClassesThat().haveSimpleNameEndingWith("Check").and().areDeclaredInClassesThat().doNotHaveModifier(JavaModifier.ABSTRACT).should().notBeProtected();
checkMethodsShouldNotBeProtectedRule.check(importedClasses);
}
use of com.tngtech.archunit.lang.ArchRule in project sirius-web by eclipse-sirius.
the class CodingRulesTests method classesImplentingPayloadShouldBeFinal.
@Test
public void classesImplentingPayloadShouldBeFinal() {
// @formatter:off
ArchRule rule = ArchRuleDefinition.classes().that().areAssignableTo(IPayload.class).and().areNotInterfaces().should().haveModifier(JavaModifier.FINAL).andShould().haveOnlyFinalFields();
// @formatter:on
rule.check(this.getClasses());
}
use of com.tngtech.archunit.lang.ArchRule in project sirius-web by eclipse-sirius.
the class RepositoryTests method repositoriesShouldOnlyBeInterfaces.
@Test
public void repositoriesShouldOnlyBeInterfaces() {
// @formatter:off
ArchRule rule = ArchRuleDefinition.classes().that().resideInAPackage(ArchitectureConstants.SIRIUS_WEB_PERSISTENCE_ROOT_PACKAGE).and().areAssignableTo(Repository.class).should().beInterfaces();
// @formatter:on
rule.check(ArchitectureConstants.CLASSES);
}
use of com.tngtech.archunit.lang.ArchRule in project BitBook by C-Otto.
the class ArchUnitIT method services_must_not_access_dto_classes_directly.
@Test
void services_must_not_access_dto_classes_directly() {
ArchRule rule = ArchRuleDefinition.noClasses().that().haveSimpleNameEndingWith("Dto").or().haveSimpleNameEndingWith("DTO").should().dependOnClassesThat().haveSimpleNameEndingWith("Service");
rule.check(importedClasses);
}
use of com.tngtech.archunit.lang.ArchRule in project BitBook by C-Otto.
the class ArchUnitIT method daos_are_transactional.
@Test
void daos_are_transactional() {
ArchRule rule = ArchRuleDefinition.classes().that().haveSimpleNameEndingWith("DaoImpl").should().beAnnotatedWith("javax.transaction.Transactional").orShould().beAnnotatedWith("org.springframework.transaction.annotation.Transactional");
// https://stackoverflow.com/q/26387399/947526
rule.check(importedClasses);
}
Aggregations