use of com.tngtech.archunit.lang.ArchRule in project sirius-components by eclipse-sirius.
the class AbstractImmutableTests method immutableClassesShouldHavePublicGetters.
@Test
public void immutableClassesShouldHavePublicGetters() {
// @formatter:off
ArchRule rule = ArchRuleDefinition.fields().that().areDeclaredInClassesThat().resideInAPackage(this.getProjectRootPackage()).and().areDeclaredInClassesThat().areAnnotatedWith(Immutable.class).should(this.haveAPublicGetter());
// @formatter:on
rule.check(this.getClasses());
}
use of com.tngtech.archunit.lang.ArchRule in project sirius-components by eclipse-sirius.
the class AbstractConfigurationTests method configurationClassShouldOnlyHaveFinalFields.
@Test
public void configurationClassShouldOnlyHaveFinalFields() {
// @formatter:off
ArchRule rule = ArchRuleDefinition.classes().that().resideInAPackage(this.getProjectRootPackage()).and().areAnnotatedWith(Configuration.class).should().haveOnlyFinalFields();
// @formatter:on
rule.check(this.getClasses());
}
use of com.tngtech.archunit.lang.ArchRule in project sirius-components by eclipse-sirius.
the class AbstractServicesTests method serviceClassShouldOnlyUseAuditedRepositoryMethods.
@Test
public void serviceClassShouldOnlyUseAuditedRepositoryMethods() {
// @formatter:off
ArchRule rule = ArchRuleDefinition.noClasses().that().resideInAPackage(this.getProjectRootPackage()).should().callMethodWhere(this.nonAuditedRepositoryMethod());
// @formatter:on
rule.check(this.getClasses());
}
use of com.tngtech.archunit.lang.ArchRule in project checkstyle by checkstyle.
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 micrometer by micrometer-metrics.
the class JvmGcMetricsTest method noJvmImplementationSpecificApiSignatures.
@Test
void noJvmImplementationSpecificApiSignatures() {
JavaClasses importedClasses = new ClassFileImporter().importPackages("io.micrometer.binder.jvm");
ArchRule noSunManagementInMethodSignatures = methods().should().notHaveRawReturnType(resideInAPackage("com.sun.management..")).andShould().notHaveRawParameterTypes(DescribedPredicate.anyElementThat(resideInAPackage("com.sun.management..")));
noSunManagementInMethodSignatures.check(importedClasses);
}
Aggregations