use of com.tngtech.archunit.lang.EvaluationResult in project ArchUnit by TNG.
the class GivenMembersTest method declaration_predicates.
@Test
@UseDataProvider("restricted_declaration_rule_starts")
public void declaration_predicates(DescribedRuleStart conjunction, Set<String> expectedMessages) {
EvaluationResult result = conjunction.should(everythingViolationPrintMemberName()).evaluate(importClasses(ClassWithVariousMembers.class, OtherClassWithMembers.class));
assertThat(result.getFailureReport().getDetails()).containsOnlyElementsOf(expectedMessages);
}
use of com.tngtech.archunit.lang.EvaluationResult in project ArchUnit by TNG.
the class GivenMembersTest method complex_members_syntax.
@Test
public void complex_members_syntax() {
EvaluationResult result = members().that().haveName(FIELD_A).or().arePublic().and(areNoFieldsWithType(List.class)).should(beAnnotatedWith(B.class)).evaluate(importClasses(ClassWithVariousMembers.class));
assertViolation(result);
assertThat(result.getFailureReport().getDetails()).containsOnly(String.format("Member '%s' is not annotated with @B", FIELD_A), String.format("Member '%s' is not annotated with @B", CONSTRUCTOR_THREE_ARGS), String.format("Member '%s' is not annotated with @B", METHOD_C));
}
use of com.tngtech.archunit.lang.EvaluationResult in project ArchUnit by TNG.
the class GivenMethodsTest method property_predicates.
@Test
@UseDataProvider("restricted_property_rule_starts")
public void property_predicates(DescribedRuleStart ruleStart, Collection<String> expectedMembers) {
EvaluationResult result = ruleStart.should(everythingViolationPrintMemberName()).evaluate(importClasses(ClassWithVariousMembers.class));
assertThat(result.getFailureReport().getDetails()).containsOnlyElementsOf(expectedMembers);
}
use of com.tngtech.archunit.lang.EvaluationResult in project ArchUnit by TNG.
the class MembersShouldConjunctionTest method andShould_ANDs_conditions.
@Test
@UseDataProvider("ANDed_conditions")
public void andShould_ANDs_conditions(ArchRule rule) {
EvaluationResult result = rule.evaluate(importClasses(RightOne.class, RightTwo.class, WrongOne.class, WrongTwo.class));
FailureReport report = result.getFailureReport();
assertThat(report.toString()).contains(String.format("members should not be declared in %s and should not be declared in %s", WrongOne.class.getName(), WrongTwo.class.getName()));
assertThat(report.getDetails()).containsOnly(isDeclaredInMessage(WrongOne.class, CONSTRUCTOR_NAME, 111), isDeclaredInMessage(WrongOne.class, "wrongMethod1", 113), isDeclaredInMessage(WrongTwo.class, CONSTRUCTOR_NAME, 117), isDeclaredInMessage(WrongTwo.class, "wrongMethod2", 119));
}
use of com.tngtech.archunit.lang.EvaluationResult in project ArchUnit by TNG.
the class MembersShouldTest method haveNameNotContaining.
@Test
@UseDataProvider("haveNameNotContaining_rules")
public void haveNameNotContaining(ArchRule rule, String infix) {
EvaluationResult result = rule.evaluate(importClasses(SimpleFieldAndMethod.class));
assertThat(singleLineFailureReportOf(result)).containsPattern(String.format(".*%s.* name contains '%s' in %s", quote(infix), quote(infix), locationPattern(SimpleFieldAndMethod.class)));
}
Aggregations