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()));
}
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()));
}
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);
}
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");
}
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);
}
Aggregations