use of com.tngtech.archunit.lang.EvaluationResult in project ArchUnit by TNG.
the class ClassesShouldTest method resideInAnyPackage.
@Test
@UseDataProvider("resideInAnyPackage_rules")
public void resideInAnyPackage(ArchRule rule, String... packageIdentifiers) {
checkTestStillValid(packageIdentifiers, ImmutableSet.of(ArchRule.class, ArchConfiguration.class), ImmutableSet.<Class<?>>of(GivenObjects.class));
EvaluationResult result = rule.evaluate(importClasses(ArchRule.class, ArchConfiguration.class, GivenObjects.class));
assertThat(singleLineFailureReportOf(result)).contains(String.format("classes should reside in any package ['%s']", Joiner.on("', '").join(packageIdentifiers))).containsPattern(doesntResideInAnyPackagePatternFor(GivenObjects.class, packageIdentifiers)).doesNotContain(String.format("%s", ArchRule.class.getSimpleName())).doesNotContain(String.format("%s", ArchConfiguration.class.getSimpleName()));
}
use of com.tngtech.archunit.lang.EvaluationResult in project ArchUnit by TNG.
the class ClassesShouldTest method assignableFrom.
@Test
@UseDataProvider("assignableFrom_rules")
public void assignableFrom(ArchRule rule, Class<?> satisfied, Class<?> violated) {
EvaluationResult result = rule.evaluate(importClasses(satisfied, violated));
assertThat(singleLineFailureReportOf(result)).contains(String.format("classes should be assignable from %s", List.class.getName())).containsPattern(String.format("Class <%s> is not assignable from %s in %s", quote(violated.getName()), quote(List.class.getName()), locationPattern(violated))).doesNotMatch(String.format(".*%s.* assignable.*", quote(satisfied.getName())));
}
use of com.tngtech.archunit.lang.EvaluationResult in project ArchUnit by TNG.
the class ClassesShouldTest method callMethod.
@Test
@UseDataProvider("callMethod_rules")
public void callMethod(ArchRule rule) {
EvaluationResult result = rule.evaluate(importClasses(ClassWithMethod.class, ClassCallingMethod.class, ClassCallingWrongMethod.class));
assertThat(singleLineFailureReportOf(result)).contains(String.format("classes should call method %s.%s(%s)", ClassWithMethod.class.getSimpleName(), "method", String.class.getSimpleName())).containsPattern(callMethodRegex(ClassCallingWrongMethod.class, ClassCallingMethod.class, "call")).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 callCodeUnitWhere.
@Test
@UseDataProvider("callCodeUnitWhere_rules")
public void callCodeUnitWhere(ArchRule rule) {
EvaluationResult result = rule.evaluate(importClasses(ClassWithFieldMethodAndConstructor.class, ClassAccessingFieldMethodAndConstructor.class, ClassAccessingWrongFieldMethodAndConstructor.class));
assertThat(singleLineFailureReportOf(result)).contains(String.format("classes should call code unit where target is %s", ClassWithFieldMethodAndConstructor.class.getSimpleName())).containsPattern(callCodeUnitRegex(ClassAccessingWrongFieldMethodAndConstructor.class, ClassAccessingFieldMethodAndConstructor.class, CONSTRUCTOR_NAME, int.class, Date.class)).containsPattern(callCodeUnitRegex(ClassAccessingWrongFieldMethodAndConstructor.class, ClassAccessingFieldMethodAndConstructor.class, "call")).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 beInnerClasses.
@Test
@UseDataProvider("beInnerClasses_rules")
public void beInnerClasses(ArchRule rule, Class<?> satisfied, Class<?> violated) {
EvaluationResult result = rule.evaluate(importClasses(satisfied, violated));
assertThat(singleLineFailureReportOf(result)).contains("classes should be inner classes").containsPattern(String.format("Class <%s> is not an inner class", quote(violated.getName()))).doesNotMatch(String.format(".*%s.* inner class.*", quote(satisfied.getName())));
}
Aggregations