Search in sources :

Example 11 with ArchRule

use of com.tngtech.archunit.lang.ArchRule in project AngularAndSpringWithMaps by Angular2Guy.

the class MyArchitectureTests method createNoFieldInjectionRule.

private static ArchRule createNoFieldInjectionRule() {
    ArchCondition<JavaField> annotatedWithSpringAutowired = beAnnotatedWith("org.springframework.beans.factory.annotation.Autowired");
    ArchCondition<JavaField> annotatedWithGuiceInject = beAnnotatedWith("com.google.inject.Inject");
    ArchCondition<JavaField> annotatedWithJakartaInject = beAnnotatedWith("javax.inject.Inject");
    ArchRule beAnnotatedWithAnInjectionAnnotation = ArchRuleDefinition.noFields().should(annotatedWithSpringAutowired.or(annotatedWithGuiceInject).or(annotatedWithJakartaInject).as("be annotated with an injection annotation"));
    return beAnnotatedWithAnInjectionAnnotation;
}
Also used : ArchRule(com.tngtech.archunit.lang.ArchRule) CompositeArchRule(com.tngtech.archunit.lang.CompositeArchRule) JavaField(com.tngtech.archunit.core.domain.JavaField)

Example 12 with ArchRule

use of com.tngtech.archunit.lang.ArchRule in project arch-unit-build-plugin-core by societe-generale.

the class NoPublicFieldRuleTest method execute.

@Override
public void execute(String packagePath, ScopePathProvider scopePathProvider, Collection<String> excludedPaths) {
    ArchRule rulePublic = fields().that().areNotStatic().or().areNotFinal().should().notBePublic().allowEmptyShould(true).because(NO_PUBLIC_FIELD_VIOLATION_MESSAGE);
    rulePublic.check(ArchUtils.importAllClassesInPackage(scopePathProvider.getMainClassesPath(), packagePath, excludedPaths));
}
Also used : ArchRule(com.tngtech.archunit.lang.ArchRule)

Example 13 with ArchRule

use of com.tngtech.archunit.lang.ArchRule in project arch-unit-build-plugin-core by societe-generale.

the class DontReturnNullCollectionTest method execute.

@Override
public void execute(String packagePath, ScopePathProvider scopePathProvider, Collection<String> excludedPaths) {
    ArchRule rule = methods().that().haveRawReturnType(List.class).or().haveRawReturnType(Set.class).should().beAnnotatedWith(Nonnull.class).because(NO_NULL_COLLECTION_MESSAGE);
    rule.check(ArchUtils.importAllClassesInPackage(scopePathProvider.getMainClassesPath(), packagePath, excludedPaths));
}
Also used : ArchRule(com.tngtech.archunit.lang.ArchRule) Set(java.util.Set) Nonnull(javax.annotation.Nonnull) List(java.util.List)

Example 14 with ArchRule

use of com.tngtech.archunit.lang.ArchRule in project MovieManager by Angular2Guy.

the class MyArchitectureTests method ruleControllerAnnotations.

@Test
public void ruleControllerAnnotations() {
    ArchRule beAnnotatedWith = ArchRuleDefinition.classes().that().resideInAPackage("..adapter.controller..").should().beAnnotatedWith(RestController.class).orShould().beAnnotatedWith(Configuration.class);
    beAnnotatedWith.check(this.importedClasses);
}
Also used : ArchRule(com.tngtech.archunit.lang.ArchRule) CompositeArchRule(com.tngtech.archunit.lang.CompositeArchRule) ArchTest(com.tngtech.archunit.junit.ArchTest) Test(org.junit.jupiter.api.Test)

Example 15 with ArchRule

use of com.tngtech.archunit.lang.ArchRule in project MovieManager by Angular2Guy.

the class MyArchitectureTests method createNoFieldInjectionRule.

private static ArchRule createNoFieldInjectionRule() {
    ArchCondition<JavaField> annotatedWithSpringAutowired = beAnnotatedWith("org.springframework.beans.factory.annotation.Autowired");
    ArchCondition<JavaField> annotatedWithGuiceInject = beAnnotatedWith("com.google.inject.Inject");
    ArchCondition<JavaField> annotatedWithJakartaInject = beAnnotatedWith("javax.inject.Inject");
    ArchRule beAnnotatedWithAnInjectionAnnotation = ArchRuleDefinition.noFields().should(annotatedWithSpringAutowired.or(annotatedWithGuiceInject).or(annotatedWithJakartaInject).as("be annotated with an injection annotation"));
    return beAnnotatedWithAnInjectionAnnotation;
}
Also used : ArchRule(com.tngtech.archunit.lang.ArchRule) CompositeArchRule(com.tngtech.archunit.lang.CompositeArchRule) JavaField(com.tngtech.archunit.core.domain.JavaField)

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