Search in sources :

Example 26 with ArchRule

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());
}
Also used : Immutable(org.eclipse.sirius.components.annotations.Immutable) ArchRule(com.tngtech.archunit.lang.ArchRule) Test(org.junit.jupiter.api.Test)

Example 27 with ArchRule

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());
}
Also used : ArchRule(com.tngtech.archunit.lang.ArchRule) Test(org.junit.jupiter.api.Test)

Example 28 with ArchRule

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());
}
Also used : ArchRule(com.tngtech.archunit.lang.ArchRule) Test(org.junit.jupiter.api.Test)

Example 29 with ArchRule

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);
}
Also used : ArchRule(com.tngtech.archunit.lang.ArchRule) JavaClasses(com.tngtech.archunit.core.domain.JavaClasses) ClassFileImporter(com.tngtech.archunit.core.importer.ClassFileImporter) Test(org.junit.jupiter.api.Test)

Example 30 with ArchRule

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);
}
Also used : ArchRule(com.tngtech.archunit.lang.ArchRule) JavaClasses(com.tngtech.archunit.core.domain.JavaClasses) ClassFileImporter(com.tngtech.archunit.core.importer.ClassFileImporter) Test(org.junit.jupiter.api.Test)

Aggregations

ArchRule (com.tngtech.archunit.lang.ArchRule)141 Test (org.junit.jupiter.api.Test)90 Test (org.junit.Test)37 ArchTest (com.tngtech.archunit.junit.ArchTest)19 CompositeArchRule (com.tngtech.archunit.lang.CompositeArchRule)19 JavaClasses (com.tngtech.archunit.core.domain.JavaClasses)18 UseDataProvider (com.tngtech.java.junit.dataprovider.UseDataProvider)13 ClassFileImporter (com.tngtech.archunit.core.importer.ClassFileImporter)12 DynamicTest (org.junit.jupiter.api.DynamicTest)12 TaskanaIntegrationTest (testapi.TaskanaIntegrationTest)12 EvaluationResult (com.tngtech.archunit.lang.EvaluationResult)6 JavaClass (com.tngtech.archunit.core.domain.JavaClass)5 Immutable (org.eclipse.sirius.components.annotations.Immutable)5 ArchConfiguration (com.tngtech.archunit.ArchConfiguration)4 JavaField (com.tngtech.archunit.core.domain.JavaField)4 CanBeAnnotatedTest (com.tngtech.archunit.core.domain.properties.CanBeAnnotatedTest)4 ArchCondition (com.tngtech.archunit.lang.ArchCondition)3 ClassViolatingCodingRules (com.tngtech.archunit.example.layers.ClassViolatingCodingRules)2 ImmutableProtocol (io.camunda.zeebe.protocol.record.ImmutableProtocol)2 Record (io.camunda.zeebe.protocol.record.Record)2