use of com.tngtech.archunit.lang.EvaluationResult in project ArchUnit by TNG.
the class ClassesShouldTest method haveSimpleNameStartingWith.
@Test
@UseDataProvider("haveSimpleNameStartingWith_rules")
public void haveSimpleNameStartingWith(ArchRule rule, String prefix) {
EvaluationResult result = rule.evaluate(importClasses(SomeClass.class, WrongNamedClass.class));
assertThat(singleLineFailureReportOf(result)).contains(String.format("classes should have simple name starting with '%s'", prefix)).containsPattern(String.format("simple name of %s does not start 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 onlyCallConstructorsThat.
@Test
@UseDataProvider("onlyCallConstructorsThat_rules")
public void onlyCallConstructorsThat(ArchRule rule) {
EvaluationResult result = rule.evaluate(importClasses(ClassWithConstructor.class, ClassCallingConstructor.class, ClassCallingWrongConstructor.class));
assertThat(singleLineFailureReportOf(result)).contains(String.format("classes should only call constructors that are declared in %s", ClassWithConstructor.class.getName())).containsPattern(callConstructorRegex(ClassCallingWrongConstructor.class, ClassCallingConstructor.class, int.class, Date.class)).doesNotMatch(accessesFieldRegex(ClassAccessingWrongFieldMethodAndConstructor.class, "sets", ClassAccessingFieldMethodAndConstructor.class, "wrongField")).doesNotMatch(callConstructorRegex(ClassCallingConstructor.class, ClassWithConstructor.class, String.class));
}
use of com.tngtech.archunit.lang.EvaluationResult in project ArchUnit by TNG.
the class ClassesShouldTest method non_package_private_visibility.
@Test
@UseDataProvider("non_package_private_visibility_rules")
public void non_package_private_visibility(ArchRule rule, String description) {
EvaluationResult result = rule.evaluate(importClasses(PrivateClass.class, PackagePrivateClass.class));
assertThat(singleLineFailureReportOf(result)).contains("classes should " + description).contains(String.format("Class <%s>", PackagePrivateClass.class.getName())).contains("does not have modifier " + PUBLIC).contains("does not have modifier " + PROTECTED).contains("does not have modifier " + PRIVATE).doesNotMatch(String.format(".*<%s>.* modifier.*", quote(PrivateClass.class.getName())));
}
use of com.tngtech.archunit.lang.EvaluationResult in project ArchUnit by TNG.
the class ClassesShouldTest method haveSimpleNameNotEndingWith.
@Test
@UseDataProvider("haveSimpleNameNotEndingWith_rules")
public void haveSimpleNameNotEndingWith(ArchRule rule, String suffix) {
EvaluationResult result = rule.evaluate(importClasses(SomeClass.class, WrongNamedClass.class));
assertThat(singleLineFailureReportOf(result)).contains(String.format("classes should have simple name not ending with '%s'", suffix)).containsPattern(String.format("simple name of %s ends with '%s' in %s", quote(WrongNamedClass.class.getName()), quote(suffix), locationPattern(WrongNamedClass.class))).doesNotContain(SomeClass.class.getName());
}
use of com.tngtech.archunit.lang.EvaluationResult in project ArchUnit by TNG.
the class ClassesShouldTest method package_private_visibility.
@Test
@UseDataProvider("package_private_visibility_rules")
public void package_private_visibility(ArchRule rule, String description) {
EvaluationResult result = rule.evaluate(importClasses(PackagePrivateClass.class, PrivateClass.class));
assertThat(singleLineFailureReportOf(result)).contains("classes should " + description).containsPattern(String.format("Class <%s> .* modifier %s", quote(PrivateClass.class.getName()), PRIVATE)).doesNotMatch(String.format(".*<%s>.* modifier.*", quote(PackagePrivateClass.class.getName())));
}
Aggregations