Search in sources :

Example 61 with ArchRule

use of com.tngtech.archunit.lang.ArchRule in project ArchUnit by TNG.

the class ShouldClassesThatTest method containAnyStaticInitializersThat.

@Test
@UseDataProvider("no_classes_should_that_rule_starts")
public void containAnyStaticInitializersThat(ClassesThat<ClassesShouldConjunction> noClassesShouldThatRuleStart) {
    ArchRule rule = noClassesShouldThatRuleStart.containAnyStaticInitializersThat(have(fullNameMatching(quote(Data_of_containAnyMembersThat.ViolatingTarget.class.getName()) + ".*")));
    Set<JavaClass> classes = filterClassesAppearingInFailureReport(rule).on(Data_of_containAnyMembersThat.OkayOrigin.class, Data_of_containAnyMembersThat.ViolatingOrigin.class, Data_of_containAnyMembersThat.OkayTarget.class, Data_of_containAnyMembersThat.ViolatingTarget.class);
    assertThatTypes(classes).matchInAnyOrder(Data_of_containAnyMembersThat.ViolatingOrigin.class, Data_of_containAnyMembersThat.ViolatingTarget.class);
}
Also used : ArchRule(com.tngtech.archunit.lang.ArchRule) JavaClass(com.tngtech.archunit.core.domain.JavaClass) Test(org.junit.Test) UseDataProvider(com.tngtech.java.junit.dataprovider.UseDataProvider)

Example 62 with ArchRule

use of com.tngtech.archunit.lang.ArchRule in project ArchUnit by TNG.

the class ShouldOnlyByClassesThatTest method containAnyStaticInitializersThat.

@Test
@UseDataProvider("should_only_be_by_rule_starts")
public void containAnyStaticInitializersThat(ClassesThat<ClassesShouldConjunction> classesShouldOnlyBeBy) {
    ArchRule rule = classesShouldOnlyBeBy.containAnyStaticInitializersThat(have(fullNameMatching(quote(Data_of_containAnyMembersThat.OkayOrigin.class.getName()) + ".*")));
    Set<JavaClass> classes = filterClassesAppearingInFailureReport(rule).on(Data_of_containAnyMembersThat.OkayOrigin.class, Data_of_containAnyMembersThat.ViolatingOrigin.class, Data_of_containAnyMembersThat.Target.class);
    assertThatTypes(classes).matchInAnyOrder(Data_of_containAnyMembersThat.ViolatingOrigin.class, Data_of_containAnyMembersThat.Target.class);
}
Also used : ArchRule(com.tngtech.archunit.lang.ArchRule) JavaClass(com.tngtech.archunit.core.domain.JavaClass) Test(org.junit.Test) UseDataProvider(com.tngtech.java.junit.dataprovider.UseDataProvider)

Example 63 with ArchRule

use of com.tngtech.archunit.lang.ArchRule in project ArchUnit by TNG.

the class ClassesShouldTest method resideOutsideOfPackage.

@Test
@UseDataProvider("resideOutsideOfPackage_rules")
public void resideOutsideOfPackage(ArchRule rule, String packageIdentifier) {
    checkTestStillValid(packageIdentifier, ImmutableSet.of(ArchRule.class, ArchCondition.class), ImmutableSet.<Class<?>>of(ArchConfiguration.class), ImmutableSet.<Class<?>>of(GivenObjects.class));
    EvaluationResult result = rule.evaluate(importClasses(ArchRule.class, ArchCondition.class, ArchConfiguration.class, GivenObjects.class));
    assertThat(singleLineFailureReportOf(result)).contains(String.format("classes should reside outside of package '%s'", packageIdentifier)).containsPattern(doesntResideOutsideOfPackagePatternFor(ArchRule.class, packageIdentifier)).containsPattern(doesntResideOutsideOfPackagePatternFor(ArchCondition.class, packageIdentifier)).doesNotContain(String.format("%s", ArchConfiguration.class.getSimpleName())).doesNotContain(String.format("%s", GivenObjects.class.getSimpleName()));
}
Also used : ArchRule(com.tngtech.archunit.lang.ArchRule) ArchCondition(com.tngtech.archunit.lang.ArchCondition) ArchConfiguration(com.tngtech.archunit.ArchConfiguration) EvaluationResult(com.tngtech.archunit.lang.EvaluationResult) CanBeAnnotatedTest(com.tngtech.archunit.core.domain.properties.CanBeAnnotatedTest) Test(org.junit.Test) UseDataProvider(com.tngtech.java.junit.dataprovider.UseDataProvider)

Example 64 with ArchRule

use of com.tngtech.archunit.lang.ArchRule in project ArchUnit by TNG.

the class ClassesShouldTest method resideInAnyPackage.

@Test
@UseDataProvider("resideInAnyPackage_rules")
public void resideInAnyPackage(ArchRule rule, String... packageIdentifiers) {
    checkTestStillValid(packageIdentifiers, ImmutableSet.of(ArchRule.class, ArchConfiguration.class), ImmutableSet.<Class<?>>of(GivenObjects.class));
    EvaluationResult result = rule.evaluate(importClasses(ArchRule.class, ArchConfiguration.class, GivenObjects.class));
    assertThat(singleLineFailureReportOf(result)).contains(String.format("classes should reside in any package ['%s']", Joiner.on("', '").join(packageIdentifiers))).containsPattern(doesntResideInAnyPackagePatternFor(GivenObjects.class, packageIdentifiers)).doesNotContain(String.format("%s", ArchRule.class.getSimpleName())).doesNotContain(String.format("%s", ArchConfiguration.class.getSimpleName()));
}
Also used : ArchRule(com.tngtech.archunit.lang.ArchRule) ArchConfiguration(com.tngtech.archunit.ArchConfiguration) EvaluationResult(com.tngtech.archunit.lang.EvaluationResult) CanBeAnnotatedTest(com.tngtech.archunit.core.domain.properties.CanBeAnnotatedTest) Test(org.junit.Test) UseDataProvider(com.tngtech.java.junit.dataprovider.UseDataProvider)

Example 65 with ArchRule

use of com.tngtech.archunit.lang.ArchRule in project ArchUnit by TNG.

the class RandomSyntaxTestBase method rule_has_expected_description_and_can_be_evaluated_without_error.

@Test
@UseDataProvider("random_rules")
public void rule_has_expected_description_and_can_be_evaluated_without_error(DescribedRule describedRule, String expectedDescription) {
    ArchRule archRule = describedRule.archRule;
    assertThat(archRule.getDescription()).as("description of constructed ArchRule").isEqualTo(expectedDescription);
    archRule.evaluate(importClassesWithContext());
    assertCheckEitherPassesOrThrowsAssertionError(archRule);
    ArchRule overriddenText = archRule.as("overridden rule text");
    assertThat(overriddenText.getDescription()).isEqualTo("overridden rule text");
    assertThat(overriddenText.evaluate(importClassesWithContext()).getFailureReport().toString()).contains("overridden rule text");
}
Also used : ArchRule(com.tngtech.archunit.lang.ArchRule) Test(org.junit.Test) UseDataProvider(com.tngtech.java.junit.dataprovider.UseDataProvider)

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