Search in sources :

Example 16 with ArchRule

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

the class MyArchitectureTests method ruleGeneralCodingRules.

@Test
public void ruleGeneralCodingRules() {
    ArchRule archRule = CompositeArchRule.of(GeneralCodingRules.NO_CLASSES_SHOULD_ACCESS_STANDARD_STREAMS).and(NO_CLASSES_SHOULD_USE_FIELD_INJECTION).because("Good practice");
    JavaClasses classesToCheck = this.importedClasses.that(JavaClass.Predicates.resideOutsideOfPackages("..adapter.clients.test.."));
    archRule.check(classesToCheck);
}
Also used : ArchRule(com.tngtech.archunit.lang.ArchRule) CompositeArchRule(com.tngtech.archunit.lang.CompositeArchRule) JavaClasses(com.tngtech.archunit.core.domain.JavaClasses) ArchTest(com.tngtech.archunit.junit.ArchTest) Test(org.junit.jupiter.api.Test)

Example 17 with ArchRule

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

the class MyArchitectureTests method ruleCronJobMethodsAnnotations.

@Test
public void ruleCronJobMethodsAnnotations() {
    ArchRule exceptionType = ArchRuleDefinition.methods().that().arePublic().and().areDeclaredInClassesThat().resideInAPackage("..adapter.cron..").should().beAnnotatedWith(PostConstruct.class).orShould().beAnnotatedWith(Scheduled.class).andShould().beAnnotatedWith(SchedulerLock.class).orShould().beAnnotatedWith(Order.class);
    exceptionType.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 18 with ArchRule

use of com.tngtech.archunit.lang.ArchRule in project github-api by hub4j.

the class ArchTests method testRequireUseOfAssertThat.

@Test
public void testRequireUseOfAssertThat() {
    final String reason = "This project uses `assertThat(...)` or `assertThrows(...)` instead of other `assert*()` methods.";
    final DescribedPredicate<HasName> assertMethodOtherThanAssertThat = nameContaining("assert").and(DescribedPredicate.not(name("assertThat")).and(DescribedPredicate.not(name("assertThrows"))));
    final ArchRule onlyAssertThatRule = classes().should(not(callMethodWhere(target(assertMethodOtherThanAssertThat)))).because(reason);
    onlyAssertThatRule.check(testClassFiles);
}
Also used : ArchRule(com.tngtech.archunit.lang.ArchRule) HasName(com.tngtech.archunit.core.domain.properties.HasName) Test(org.junit.Test)

Example 19 with ArchRule

use of com.tngtech.archunit.lang.ArchRule in project sirius-components by eclipse-sirius.

the class CodingRulesTests method classesImplementingInputShouldBeFinal.

@Test
public void classesImplementingInputShouldBeFinal() {
    // @formatter:off
    ArchRule rule = ArchRuleDefinition.classes().that().areAssignableTo(IInput.class).and().areNotInterfaces().should().haveModifier(JavaModifier.FINAL);
    // @formatter:on
    rule.check(this.getClasses());
}
Also used : ArchRule(com.tngtech.archunit.lang.ArchRule) Test(org.junit.jupiter.api.Test)

Example 20 with ArchRule

use of com.tngtech.archunit.lang.ArchRule in project sirius-components 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());
}
Also used : ArchRule(com.tngtech.archunit.lang.ArchRule) 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