use of com.tngtech.archunit.lang.EvaluationResult in project ArchUnit by TNG.
the class ClassesShouldTest method haveSimpleNameNotStartingWith.
@Test
@UseDataProvider("haveSimpleNameNotStartingWith_rules")
public void haveSimpleNameNotStartingWith(ArchRule rule, String prefix) {
EvaluationResult result = rule.evaluate(importClasses(SomeClass.class, WrongNamedClass.class));
assertThat(singleLineFailureReportOf(result)).contains(String.format("classes should have simple name not starting with '%s'", prefix)).containsPattern(String.format("simple name of %s starts with '%s' in %s", quote(WrongNamedClass.class.getName()), quote(prefix), locationPattern(WrongNamedClass.class))).doesNotContain(SomeClass.class.getName());
}
use of com.tngtech.archunit.lang.EvaluationResult in project ArchUnit by TNG.
the class ClassesShouldTest method onlyAccessMembersThat.
@Test
@UseDataProvider("onlyAccessMembersThat_rules")
public void onlyAccessMembersThat(ArchRule rule) {
EvaluationResult result = rule.evaluate(importClasses(ClassWithFieldMethodAndConstructor.class, ClassAccessingFieldMethodAndConstructor.class, ClassAccessingWrongFieldMethodAndConstructor.class));
assertThat(singleLineFailureReportOf(result)).contains(String.format("classes should only access members that are declared in %s", ClassWithFieldMethodAndConstructor.class.getName())).containsPattern(callCodeUnitRegex(ClassAccessingWrongFieldMethodAndConstructor.class, ClassAccessingFieldMethodAndConstructor.class, CONSTRUCTOR_NAME, int.class, Date.class)).containsPattern(callCodeUnitRegex(ClassAccessingWrongFieldMethodAndConstructor.class, ClassAccessingFieldMethodAndConstructor.class, "call")).containsPattern(accessesFieldRegex(ClassAccessingWrongFieldMethodAndConstructor.class, "sets", ClassAccessingFieldMethodAndConstructor.class, "wrongField")).doesNotMatch(callCodeUnitRegex(ClassAccessingWrongFieldMethodAndConstructor.class, ClassAccessingFieldMethodAndConstructor.class, "wrongField")).doesNotMatch(callCodeUnitRegex(ClassAccessingFieldMethodAndConstructor.class, ClassWithFieldMethodAndConstructor.class, ""));
}
use of com.tngtech.archunit.lang.EvaluationResult in project ArchUnit by TNG.
the class CodeUnitsShouldTest method throwable_type_predicates.
@Test
@UseDataProvider("restricted_throwable_type_rules")
public void throwable_type_predicates(ArchRule rule, Collection<String> expectedMembers) {
EvaluationResult result = rule.evaluate(importClasses(ClassWithVariousMembers.class));
Set<String> actualMembers = parseMembers(ClassWithVariousMembers.class, result.getFailureReport().getDetails());
assertThat(actualMembers).containsOnlyElementsOf(expectedMembers);
}
use of com.tngtech.archunit.lang.EvaluationResult in project ArchUnit by TNG.
the class CodeUnitsShouldTest method restricted_constructors_calls_by_code_units_predicate.
@Test
@UseDataProvider("restricted_constructors_calls_by_code_units_rules")
public void restricted_constructors_calls_by_code_units_predicate(ArchRule rule) {
EvaluationResult result = rule.evaluate(importClasses(ClassWithMethodAndConstructor.class, ClassCorrectlyCallingMethodAndConstructor.class, ClassWronglyCallingMethodAndConstructor.class));
assertThat(singleLineFailureReportOf(result)).contains("Rule 'constructors should only be called by code units that").containsPattern(String.format("Method <%s.%s> calls constructor <%s.%s>", quote(ClassWronglyCallingMethodAndConstructor.class.getName()), quote(METHOD_CALL_WRONGLY), quote(ClassWithMethodAndConstructor.class.getName()), quote(CONSTRUCTOR_ONE_ARG)));
}
use of com.tngtech.archunit.lang.EvaluationResult in project ArchUnit by TNG.
the class CodeUnitsShouldTest method restricted_constructor_calls_by_classes_predicate.
@Test
@UseDataProvider("restricted_constructor_calls_by_classes_rules")
public void restricted_constructor_calls_by_classes_predicate(ArchRule rule) {
EvaluationResult result = rule.evaluate(importClasses(ClassWithMethodAndConstructor.class, ClassCorrectlyCallingMethodAndConstructor.class, ClassWronglyCallingMethodAndConstructor.class));
assertThat(singleLineFailureReportOf(result)).contains("Rule 'constructors should only be called by classes that").containsPattern(String.format("Method <%s.%s> calls constructor <%s.%s>", quote(ClassWronglyCallingMethodAndConstructor.class.getName()), quote(METHOD_CALL_WRONGLY), quote(ClassWithMethodAndConstructor.class.getName()), quote(CONSTRUCTOR_ONE_ARG)));
}
Aggregations