use of com.tngtech.archunit.lang.EvaluationResult in project ArchUnit by TNG.
the class MembersShouldTest method complex_members_syntax.
@Test
public void complex_members_syntax() {
EvaluationResult result = members().that(areNoFieldsWithType(List.class)).and().haveNameMatching(".*field.*").should().beAnnotatedWith(B.class).andShould().notBePublic().orShould().bePrivate().evaluate(importClasses(ClassWithVariousMembers.class));
assertViolation(result);
String failure = getOnlyElement(result.getFailureReport().getDetails());
assertThat(failure).matches(String.format(".*Field .*%s.* does not have modifier PRIVATE.*", FIELD_D)).contains("and Field").matches(String.format(".*Field .*%s.* is not annotated with @B.*", FIELD_D));
}
use of com.tngtech.archunit.lang.EvaluationResult in project ArchUnit by TNG.
the class MembersShouldTest method property_predicates.
@Test
@UseDataProvider("restricted_property_rule_ends")
public void property_predicates(MembersShouldConjunction<?> conjunction, Set<String> expectedMembers) {
EvaluationResult result = conjunction.evaluate(importClasses(ClassWithVariousMembers.class, A.class, B.class, C.class, MetaAnnotation.class));
Set<String> actualMembers = parseMembers(result.getFailureReport().getDetails());
assertThat(actualMembers).containsOnlyElementsOf(expectedMembers);
}
use of com.tngtech.archunit.lang.EvaluationResult in project ArchUnit by TNG.
the class MembersShouldTest method haveNameNotStartingWith.
@Test
@UseDataProvider("haveNameNotStartingWith_rules")
public void haveNameNotStartingWith(ArchRule rule, String prefix) {
EvaluationResult result = rule.evaluate(importClasses(SimpleFieldAndMethod.class));
assertThat(singleLineFailureReportOf(result)).containsPattern(String.format(".*%s.* name starts with '%s' in %s", quote(prefix), quote(prefix), locationPattern(SimpleFieldAndMethod.class)));
}
use of com.tngtech.archunit.lang.EvaluationResult in project ArchUnit by TNG.
the class MembersShouldTest method haveNameEndingWith.
@Test
@UseDataProvider("haveNameEndingWith_rules")
public void haveNameEndingWith(ArchRule rule, String suffix, String violatingMember) {
EvaluationResult result = rule.evaluate(importClasses(SimpleFieldAndMethod.class));
assertThat(singleLineFailureReportOf(result)).containsPattern(String.format(".*%s.* name does not end with '%s' in %s", quote(violatingMember), quote(suffix), locationPattern(SimpleFieldAndMethod.class)));
}
use of com.tngtech.archunit.lang.EvaluationResult in project ArchUnit by TNG.
the class ArchitecturesTest method layered_architecture_allows_individual_empty_optionalLayer.
@Test
public void layered_architecture_allows_individual_empty_optionalLayer() {
LayeredArchitecture architecture = layeredArchitecture().optionalLayer("can be absent").definedBy(absolute("should.not.be.found.."));
JavaClasses classes = new ClassFileImporter().importPackages(absolute(""));
EvaluationResult result = architecture.evaluate(classes);
assertThat(result.hasViolation()).as("result of evaluating empty optionalLayer has violation").isFalse();
assertThat(result.getFailureReport().isEmpty()).as("failure report").isTrue();
}
Aggregations