use of com.tngtech.archunit.lang.EvaluationResult in project ArchUnit by TNG.
the class ClassesShouldTest method callMethodWhere.
@Test
@UseDataProvider("callMethodWhere_rules")
public void callMethodWhere(ArchRule rule) {
EvaluationResult result = rule.evaluate(importClasses(ClassWithMethod.class, ClassCallingMethod.class, ClassCallingWrongMethod.class, ClassCallingSelf.class));
assertThat(singleLineFailureReportOf(result)).contains(String.format("classes should call method where target is %s", ClassWithMethod.class.getSimpleName())).containsPattern(callMethodRegex(ClassCallingWrongMethod.class, ClassCallingMethod.class, "call")).containsPattern(callMethodRegex(ClassCallingSelf.class, ClassCallingSelf.class, "target")).doesNotMatch(callMethodRegex(ClassCallingMethod.class, ClassWithMethod.class, "method", String.class));
}
use of com.tngtech.archunit.lang.EvaluationResult in project ArchUnit by TNG.
the class ClassesShouldTest method onlyCallCodeUnitsThat.
@Test
@UseDataProvider("onlyCallCodeUnitsThat_rules")
public void onlyCallCodeUnitsThat(ArchRule rule) {
EvaluationResult result = rule.evaluate(importClasses(ClassWithFieldMethodAndConstructor.class, ClassAccessingFieldMethodAndConstructor.class, ClassAccessingWrongFieldMethodAndConstructor.class));
assertThat(singleLineFailureReportOf(result)).contains(String.format("classes should only call code units 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")).doesNotMatch(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 ClassesShouldTest method haveNameNotMatching.
@Test
@UseDataProvider("haveNameNotMatching_rules")
public void haveNameNotMatching(ArchRule rule, String regex) {
EvaluationResult result = rule.evaluate(importClasses(SomeClass.class, WrongNamedClass.class));
assertThat(singleLineFailureReportOf(result)).contains(String.format("classes should have name not matching '%s'", regex)).containsPattern(String.format("Class <%s> matches '%s' in %s", quote(WrongNamedClass.class.getName()), quote(regex), locationPattern(WrongNamedClass.class))).doesNotContain(String.format("%s", SomeClass.class.getSimpleName()));
}
use of com.tngtech.archunit.lang.EvaluationResult in project ArchUnit by TNG.
the class ClassesShouldTest method resideOutsideOfPackage.
@Test
@UseDataProvider("resideOutsideOfPackage_rules")
public void resideOutsideOfPackage(ArchRule rule, String packageIdentifier) {
checkTestStillValid(packageIdentifier, ImmutableSet.of(ArchRule.class, ArchCondition.class), ImmutableSet.<Class<?>>of(ArchConfiguration.class), ImmutableSet.<Class<?>>of(GivenObjects.class));
EvaluationResult result = rule.evaluate(importClasses(ArchRule.class, ArchCondition.class, ArchConfiguration.class, GivenObjects.class));
assertThat(singleLineFailureReportOf(result)).contains(String.format("classes should reside outside of package '%s'", packageIdentifier)).containsPattern(doesntResideOutsideOfPackagePatternFor(ArchRule.class, packageIdentifier)).containsPattern(doesntResideOutsideOfPackagePatternFor(ArchCondition.class, packageIdentifier)).doesNotContain(String.format("%s", ArchConfiguration.class.getSimpleName())).doesNotContain(String.format("%s", GivenObjects.class.getSimpleName()));
}
use of com.tngtech.archunit.lang.EvaluationResult in project ArchUnit by TNG.
the class ClassesShouldTest method notMetaAnnotatedWith.
@Test
@UseDataProvider("notMetaAnnotated_rules")
public void notMetaAnnotatedWith(ArchRule rule, Class<?> correctClass, Class<?> wrongClass) {
EvaluationResult result = rule.evaluate(importClasses(correctClass, wrongClass));
assertThat(singleLineFailureReportOf(result)).contains("classes should not be meta-annotated with @" + SomeMetaAnnotation.class.getSimpleName()).containsPattern(String.format("Class <%s> is meta-annotated with @%s in %s", quote(wrongClass.getName()), SomeMetaAnnotation.class.getSimpleName(), locationPattern(getClass()))).doesNotMatch(String.format(".*<%s>.*meta-annotated.*", quote(correctClass.getName())));
}
Aggregations