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