use of com.tngtech.archunit.lang.ArchRule in project ArchUnit by TNG.
the class ArchitecturesTest method onion_architecture_with_overwritten_description_retains_ignored_dependencies.
@Test
public void onion_architecture_with_overwritten_description_retains_ignored_dependencies() {
ArchRule onionIgnoringOriginApplicationLayerClass = getTestOnionArchitecture().ignoreDependency(equivalentTo(ApplicationLayerClass.class), DescribedPredicate.<JavaClass>alwaysTrue()).because("some reason causing description to be overwritten");
JavaClasses classes = new ClassFileImporter().importPackages(absolute("onionarchitecture"));
EvaluationResult result = onionIgnoringOriginApplicationLayerClass.evaluate(classes);
ExpectedOnionViolations expectedViolations = getExpectedOnionViolations().withoutViolationsWithOrigin(ApplicationLayerClass.class);
assertPatternMatches(result.getFailureReport().getDetails(), expectedViolations.toPatterns());
}
use of com.tngtech.archunit.lang.ArchRule in project ArchUnit by TNG.
the class FreezingArchRuleTest method default_violation_store_works_with_multi_line_rule_texts_with_different_line_separators.
@Test
@UseDataProvider("different_line_separators_to_store_and_read")
public void default_violation_store_works_with_multi_line_rule_texts_with_different_line_separators(String lineSeparatorOnFreeze, String lineSeparatorOnCheck) throws IOException {
useTemporaryDefaultStorePath();
ArchConfiguration.get().setProperty(ALLOW_STORE_CREATION_PROPERTY_NAME, "true");
RuleCreator ruleCreator = rule("any rule${lineSeparator}with several${lineSeparator}lines with several words").withViolations("some violation");
ArchRule storedRule = freeze(ruleCreator.withStringReplace("${lineSeparator}", lineSeparatorOnFreeze).create());
assertThatRule(storedRule).checking(importClasses(getClass())).hasNoViolation();
ArchRule ruleToCheck = ruleCreator.withStringReplace("${lineSeparator}", lineSeparatorOnCheck).withViolations("some violation", "new").create();
assertThatRule(freeze(ruleToCheck)).checking(importClasses(getClass())).hasOnlyViolations("new");
}
use of com.tngtech.archunit.lang.ArchRule in project ArchUnit by TNG.
the class FreezingArchRuleTest method allows_to_overwrite_frozen_violations_if_configured.
@Test
public void allows_to_overwrite_frozen_violations_if_configured() {
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);
ArchConfiguration.get().setProperty("freeze.refreeze", Boolean.TRUE.toString());
assertThatRule(frozenWithNewViolation).checking(importClasses(getClass())).hasNoViolation();
ArchConfiguration.get().setProperty("freeze.refreeze", Boolean.FALSE.toString());
assertThatRule(frozenWithNewViolation).checking(importClasses(getClass())).hasNoViolation();
ArchRule yetAnotherViolation = rule("some description").withViolations("first violation", "second violation", "third violation").create();
ArchRule frozenWithYetAnotherViolation = freeze(yetAnotherViolation).persistIn(violationStore);
assertThatRule(frozenWithYetAnotherViolation).checking(importClasses(getClass())).hasOnlyViolations("third violation");
}
use of com.tngtech.archunit.lang.ArchRule in project ArchUnit by TNG.
the class FreezingArchRuleTest method automatically_reduces_allowed_violations_if_any_vanish.
@Test
public void automatically_reduces_allowed_violations_if_any_vanish() {
TestViolationStore violationStore = new TestViolationStore();
String secondViolation = "second violation";
createFrozen(violationStore, rule("some description").withViolations("first violation", secondViolation).create());
ArchRule secondViolationSolved = rule("some description").withViolations("first violation").create();
ArchRule frozenWithLessViolation = freeze(secondViolationSolved).persistIn(violationStore);
assertThatRule(frozenWithLessViolation).checking(importClasses(getClass())).hasNoViolation();
ArchRule secondViolationIsBack = rule("some description").withViolations("first violation", secondViolation).create();
ArchRule frozenWithOldViolationBack = freeze(secondViolationIsBack).persistIn(violationStore);
assertThatRule(frozenWithOldViolationBack).checking(importClasses(getClass())).hasOnlyViolations(secondViolation);
}
use of com.tngtech.archunit.lang.ArchRule in project ArchUnit by TNG.
the class FreezingArchRuleTest method delegates_description.
@Test
public void delegates_description() {
ArchRule rule = rule("some description").withoutViolations().create();
ArchRule frozen = freeze(rule);
assertThat(frozen.getDescription()).isEqualTo(rule.getDescription());
}
Aggregations