Search in sources :

Example 91 with ArchRule

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

the class ClassesShouldTest method resideOutsideOfPackages.

@Test
@UseDataProvider("resideOutsideOfPackages_rules")
public void resideOutsideOfPackages(ArchRule rule, String... packageIdentifiers) {
    checkTestStillValid(packageIdentifiers, ImmutableSet.of(ArchRule.class, 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 packages ['%s']", Joiner.on("', '").join(packageIdentifiers))).containsPattern(doesntResideOutsideOfPackagesPatternFor(ArchRule.class, packageIdentifiers)).containsPattern(doesntResideOutsideOfPackagesPatternFor(ArchCondition.class, packageIdentifiers)).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 92 with ArchRule

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

the class ClassesShouldTest method resideInAPackage.

@Test
@UseDataProvider("resideInAPackage_rules")
public void resideInAPackage(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 in a package '%s'", packageIdentifier)).containsPattern(doesntResideInAPackagePatternFor(ArchConfiguration.class, packageIdentifier)).containsPattern(doesntResideInAPackagePatternFor(GivenObjects.class, packageIdentifier)).doesNotContain(String.format("%s", ArchRule.class.getSimpleName())).doesNotContain(String.format("%s", ArchCondition.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 93 with ArchRule

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

the class GivenMembersTest method test_members.

@Test
@UseDataProvider("member_syntax_testcases")
public void test_members(GivenMembers<JavaMember> members, String ruleStart, ArchCondition<JavaMember> condition, List<String> expectedViolationDetails) {
    ArchRule rule = members.that(have(modifier(PRIVATE))).or(have(modifier(PROTECTED))).and(are(annotatedWith(B.class))).should(condition);
    assertThat(rule.getDescription()).as("rule description").isEqualTo(ruleStart + " that have modifier PRIVATE or have modifier PROTECTED and are annotated with @B " + "should " + condition.getDescription());
    EvaluationResult result = rule.evaluate(importClasses(ClassWithVariousMembers.class));
    assertViolation(result);
    assertThat(result.getFailureReport().getDetails()).containsOnlyElementsOf(expectedViolationDetails);
}
Also used : ArchRule(com.tngtech.archunit.lang.ArchRule) EvaluationResult(com.tngtech.archunit.lang.EvaluationResult) Test(org.junit.Test) UseDataProvider(com.tngtech.java.junit.dataprovider.UseDataProvider)

Example 94 with ArchRule

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

the class FreezingArchRuleTest method fails_on_an_increased_violation_count_of_the_same_violation_compared_to_frozen_ones.

@Test
public void fails_on_an_increased_violation_count_of_the_same_violation_compared_to_frozen_ones() {
    TestViolationStore violationStore = new TestViolationStore();
    createFrozen(violationStore, rule("some description").withViolations("violation").create());
    ArchRule frozen = freeze(rule("some description").withViolations("violation", "equivalent one").create()).persistIn(violationStore).associateViolationLinesVia((lineFromFirstViolation, lineFromSecondViolation) -> true);
    assertThatRule(frozen).checking(importClasses(getClass())).hasViolations(1).hasAnyViolationOf("violation", "equivalent one");
}
Also used : ArchRule(com.tngtech.archunit.lang.ArchRule) Test(org.junit.Test)

Example 95 with ArchRule

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

the class FreezingArchRuleTest method passes_on_consecutive_calls_without_new_violations.

@Test
public void passes_on_consecutive_calls_without_new_violations() {
    ArchRule input = rule("some description").withViolations("first violation", "second violation").create();
    TestViolationStore violationStore = new TestViolationStore();
    ArchRule frozen = freeze(input).persistIn(violationStore);
    JavaClasses classes = importClasses(getClass());
    frozen.check(classes);
    frozen.check(classes);
    frozen.check(classes);
}
Also used : ArchRule(com.tngtech.archunit.lang.ArchRule) JavaClasses(com.tngtech.archunit.core.domain.JavaClasses) Test(org.junit.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