use of com.tngtech.archunit.lang.EvaluationResult in project ArchUnit by TNG.
the class ClassesShouldTest method beLocalClasses.
@Test
@UseDataProvider("beLocalClasses_rules")
public void beLocalClasses(ArchRule rule, Class<?> satisfied, Class<?> violated) {
EvaluationResult result = rule.evaluate(importClasses(satisfied, violated));
assertThat(singleLineFailureReportOf(result)).contains("classes should be local classes").containsPattern(String.format("Class <%s> is not a local class", quote(violated.getName()))).doesNotMatch(String.format(".*%s.* local class.*", quote(satisfied.getName())));
}
use of com.tngtech.archunit.lang.EvaluationResult in project ArchUnit by TNG.
the class ClassesShouldTest method beEnums.
@Test
@UseDataProvider("beEnums_rules")
public void beEnums(ArchRule rule, Class<?> satisfied, Class<?> violated) {
EvaluationResult result = rule.evaluate(importClasses(satisfied, violated));
assertThat(singleLineFailureReportOf(result)).contains("classes should be enums").containsPattern(String.format("Class <%s> is not an enum in %s", quote(violated.getName()), locationPattern(violated))).doesNotMatch(String.format(".*%s.* enum.*", quote(satisfied.getName())));
}
use of com.tngtech.archunit.lang.EvaluationResult in project ArchUnit by TNG.
the class ClassesShouldTest method notBeTopLevelClasses.
@Test
@UseDataProvider("notBeTopLevelClasses_rules")
public void notBeTopLevelClasses(ArchRule rule, Class<?> satisfied, Class<?> violated) {
EvaluationResult result = rule.evaluate(importClasses(satisfied, violated));
assertThat(singleLineFailureReportOf(result)).contains("classes should not be top level classes").containsPattern(String.format("Class <%s> is a top level class", quote(violated.getName()))).doesNotMatch(String.format(".*%s.* top level class.*", quote(satisfied.getName())));
}
use of com.tngtech.archunit.lang.EvaluationResult in project ArchUnit by TNG.
the class ClassesShouldTest method onlyAccessFieldsThat.
@Test
@UseDataProvider("onlyAccessFieldsThat_rules")
public void onlyAccessFieldsThat(ArchRule rule) {
EvaluationResult result = rule.evaluate(importClasses(ClassWithField.class, ClassAccessingField.class, ClassAccessingWrongField.class));
assertThat(singleLineFailureReportOf(result)).contains("classes should only access fields that are declared in " + ClassWithField.class.getName()).containsPattern(accessesFieldRegex(ClassAccessingWrongField.class, "(sets|gets|accesses)", ClassAccessingField.class, "classWithField")).containsPattern(accessesFieldRegex(ClassAccessingField.class, "(sets|gets|accesses)", ClassAccessingField.class, "classWithField")).doesNotMatch(accessesFieldRegex(ClassAccessingField.class, "(sets|gets|accesses)", ClassWithField.class, "field")).doesNotMatch(accessesFieldRegex(ClassWithField.class, "(sets|gets|accesses)", ClassWithField.class, "field"));
}
use of com.tngtech.archunit.lang.EvaluationResult in project ArchUnit by TNG.
the class ClassesShouldTest method notImplement.
@Test
@UseDataProvider("notImplement_rules")
public void notImplement(ArchRule rule, Class<?> satisfied, Class<?> violated) {
EvaluationResult result = rule.evaluate(importClasses(satisfied, violated));
assertThat(singleLineFailureReportOf(result)).contains(String.format("classes should not implement %s", Collection.class.getName())).containsPattern(String.format("Class <%s> implements %s in %s", quote(violated.getName()), quote(Collection.class.getName()), locationPattern(violated))).doesNotMatch(String.format(".*%s.* implement.*", quote(satisfied.getName())));
}
Aggregations