use of com.tngtech.archunit.lang.ArchRule in project ArchUnit by TNG.
the class FreezingArchRuleTest method allows_to_specify_a_custom_matcher_to_decide_which_violations_count_as_known.
// This is e.g. useful to ignore the line number in "message (Foo.java:xxx)"
@Test
public void allows_to_specify_a_custom_matcher_to_decide_which_violations_count_as_known() {
TestViolationStore violationStore = new TestViolationStore();
createFrozen(violationStore, rule("some description").withViolations("some #ignore_this# violation", "second #ignore_this# violation").create());
ArchRule frozen = freeze(rule("some description").withViolations("some #now changed# violation", "second #now changed somehow# violation", "and new").create()).persistIn(violationStore).associateViolationLinesVia((lineFromFirstViolation, lineFromSecondViolation) -> {
String storedCleanedUp = lineFromFirstViolation.replaceAll("#.*#", "");
String actualCleanedUp = lineFromSecondViolation.replaceAll("#.*#", "");
return storedCleanedUp.equals(actualCleanedUp);
});
assertThatRule(frozen).checking(importClasses(getClass())).hasOnlyViolations("and new");
}
use of com.tngtech.archunit.lang.ArchRule in project ArchUnit by TNG.
the class FreezingArchRuleTest method freezes_violations_on_first_call.
@Test
public void freezes_violations_on_first_call() {
ArchRule input = rule("some description").withViolations("first violation", "second violation").create();
TestViolationStore violationStore = new TestViolationStore();
ArchRule frozen = freeze(input).persistIn(violationStore);
assertThatRule(frozen).checking(importClasses(getClass())).hasNoViolation();
violationStore.verifyStoredRule("some description", "first violation", "second violation");
}
use of com.tngtech.archunit.lang.ArchRule in project ArchUnit by TNG.
the class FreezingArchRuleTest method fails_on_violations_additional_to_frozen_ones.
@Test
public void fails_on_violations_additional_to_frozen_ones() {
TestViolationStore violationStore = new TestViolationStore();
createFrozen(violationStore, rule("some description").withViolations("first violation").create());
ArchRule anotherViolation = rule("some description").withViolations("first violation", "second violation").create();
ArchRule frozenWithNewViolation = freeze(anotherViolation).persistIn(violationStore);
assertThatRule(frozenWithNewViolation).checking(importClasses(getClass())).hasOnlyViolations("second violation");
}
use of com.tngtech.archunit.lang.ArchRule in project ArchUnit by TNG.
the class FreezingArchRuleTest method works_with_multi_line_violations_with_different_line_separators.
@Test
@UseDataProvider("different_line_separators_to_store_and_read")
public void works_with_multi_line_violations_with_different_line_separators(String lineSeparatorOnFreeze, String lineSeparatorOnCheck) {
TestViolationStore violationStore = new TestViolationStore();
RuleCreator ruleCreator = rule("some rule").withViolations(new ViolatedEvent("first violation1${lineSeparator}with multiple${lineSeparator}lines with several words", "second violation1${lineSeparator}with multiple${lineSeparator}lines with several words"), new ViolatedEvent("first violation2${lineSeparator}with multiple${lineSeparator}lines with several words", "second violation2${lineSeparator}with multiple${lineSeparator}lines with several words"));
ArchRule storedRule = ruleCreator.withStringReplace("${lineSeparator}", lineSeparatorOnFreeze).create();
createFrozen(violationStore, storedRule);
ArchRule ruleToCheck = ruleCreator.withStringReplace("${lineSeparator}", lineSeparatorOnCheck).create();
assertThatRule(freeze(ruleToCheck).persistIn(violationStore)).checking(importClasses(getClass())).hasNoViolation();
}
use of com.tngtech.archunit.lang.ArchRule in project ArchUnit by TNG.
the class ShouldClassesThatTest method transitivelyDependOnClassesThat_reports_all_transitive_dependencies.
@Test
@DataProvider(value = { "true", "false" })
public void transitivelyDependOnClassesThat_reports_all_transitive_dependencies(boolean viaPredicate) {
Class<?> testClass = TransitivelyDependOnClassesThatTestCases.TestClass.class;
Class<?> directlyDependentClass1 = TransitivelyDependOnClassesThatTestCases.DirectlyDependentClass1.class;
Class<?> directlyDependentClass2 = TransitivelyDependOnClassesThatTestCases.DirectlyDependentClass2.class;
Class<?> transitivelyDependentClass = TransitivelyDependOnClassesThatTestCases.TransitivelyDependentClass.class;
JavaClasses classes = new ClassFileImporter().importClasses(testClass, directlyDependentClass1, directlyDependentClass2, transitivelyDependentClass);
ClassesShould noClassesShould = noClasses().that().haveFullyQualifiedName(testClass.getName()).should();
ArchRule rule = viaPredicate ? noClassesShould.transitivelyDependOnClassesThat(have(fullyQualifiedName(transitivelyDependentClass.getName()))) : noClassesShould.transitivelyDependOnClassesThat().haveFullyQualifiedName(transitivelyDependentClass.getName());
assertThatRule(rule).checking(classes).hasViolations(2).hasViolationMatching(String.format(".*%s\\.%s.* has type .*%s.*", quote(directlyDependentClass1.getName()), "transitiveDependency1", quote(transitivelyDependentClass.getName()))).hasViolationMatching(String.format(".*%s\\.%s.* has type .*%s.*", quote(directlyDependentClass2.getName()), "transitiveDependency2", quote(transitivelyDependentClass.getName())));
}
Aggregations