use of com.tngtech.archunit.core.domain.JavaClasses in project ArchUnit by TNG.
the class GivenSlicesTest method restricting_slices_that_should_not_depend_on_each_other.
@Test
public void restricting_slices_that_should_not_depend_on_each_other() {
archConfigurationRule.setFailOnEmptyShould(false);
GivenSlices givenSlices = slices().matching("..testclasses.(*)..");
JavaClasses classes = new ClassFileImporter().importPackages("com.tngtech.archunit.library.testclasses");
EvaluationResult result = givenSlices.that(DescribedPredicate.<Slice>alwaysFalse()).and(DescribedPredicate.<Slice>alwaysTrue()).should().notDependOnEachOther().evaluate(classes);
assertThat(result.hasViolation()).as("Result has violation").isFalse();
result = givenSlices.that(DescribedPredicate.<Slice>alwaysTrue()).or(DescribedPredicate.<Slice>alwaysFalse()).should().notDependOnEachOther().evaluate(classes);
assertThat(result.hasViolation()).as("Result has violation").isTrue();
}
use of com.tngtech.archunit.core.domain.JavaClasses in project ArchUnit by TNG.
the class PlantUmlArchConditionTest method getClassesFrom.
private static JavaClasses getClassesFrom(String pkg) {
String packageName = "com.tngtech.archunit.library.diagramtests." + pkg;
JavaClasses classes = new ClassFileImporter().importPackages(packageName);
if (isEmpty(classes)) {
throw new IllegalStateException(String.format("No classes were imported from '%s'", packageName));
}
return classes;
}
use of com.tngtech.archunit.core.domain.JavaClasses in project ArchUnit by TNG.
the class PlantUmlArchConditionTest method class_must_be_contained_within_the_diagram_if_it_has_relevant_dependencies.
@Test
public void class_must_be_contained_within_the_diagram_if_it_has_relevant_dependencies() {
File file = TestDiagram.in(temporaryFolder).component("SomeComponent").withStereoTypes("..someStereotype.").write();
JavaClasses notContained = importClasses(Object.class);
PlantUmlArchCondition condition = adhereToPlantUmlDiagram(file, consideringAllDependencies());
classes().should(condition.ignoreDependenciesWithOrigin(equivalentTo(Object.class))).check(notContained);
thrown.expect(IllegalStateException.class);
thrown.expectMessage(String.format("Class %s is not contained in any component", getOnlyElement(notContained).getName()));
classes().should(condition).check(notContained);
}
use of com.tngtech.archunit.core.domain.JavaClasses 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())));
}
use of com.tngtech.archunit.core.domain.JavaClasses in project ArchUnit by TNG.
the class SlicesShouldTest method slice_rules_should_ignore_configured_dependencies.
@Test
@UseDataProvider("rules")
public void slice_rules_should_ignore_configured_dependencies(SliceRule rule) {
JavaClasses classes = new ClassFileImporter().importPackages(TEST_CLASSES_PACKAGE);
assertViolations(classes, rule).contain(FirstThreeAnyClass.class, SecondThreeAnyClass.class).contain(FirstAnyPkgClass.class, SomePkgSubclass.class).contain(SecondAnyClass.class, FirstAnyPkgClass.class).contain(SecondThreeAnyClass.class, SomePkgClass.class);
rule = rule.ignoreDependency(classIn(".*\\.first\\.three\\..*"), DescribedPredicate.<JavaClass>alwaysTrue());
assertViolations(classes, rule).doNotContain(FirstThreeAnyClass.class, SecondThreeAnyClass.class).contain(FirstAnyPkgClass.class, SomePkgSubclass.class).contain(SecondAnyClass.class, FirstAnyPkgClass.class).contain(SecondThreeAnyClass.class, SomePkgClass.class);
rule = rule.ignoreDependency(FirstAnyPkgClass.class.getName(), SomePkgSubclass.class.getName());
assertViolations(classes, rule).doNotContain(FirstThreeAnyClass.class, SecondThreeAnyClass.class).doNotContain(FirstAnyPkgClass.class, SomePkgSubclass.class).contain(SecondAnyClass.class, FirstAnyPkgClass.class).contain(SecondThreeAnyClass.class, SomePkgClass.class);
rule = rule.ignoreDependency(SecondAnyClass.class, FirstAnyPkgClass.class);
assertViolations(classes, rule).doNotContain(FirstThreeAnyClass.class, SecondThreeAnyClass.class).doNotContain(FirstAnyPkgClass.class, SomePkgSubclass.class).doNotContain(SecondAnyClass.class, FirstAnyPkgClass.class).contain(SecondThreeAnyClass.class, SomePkgClass.class);
rule = rule.ignoreDependency(DescribedPredicate.<JavaClass>alwaysTrue(), classIn(".*\\.some\\.pkg\\..*"));
assertViolations(classes, rule).doNotContain(FirstThreeAnyClass.class, SecondThreeAnyClass.class).doNotContain(FirstAnyPkgClass.class, SomePkgSubclass.class).doNotContain(SecondAnyClass.class, FirstAnyPkgClass.class).doNotContain(SecondThreeAnyClass.class, SomePkgClass.class);
}
Aggregations