use of com.tngtech.archunit.lang.EvaluationResult in project ArchUnit by TNG.
the class ClassesShouldTest method beAnonymousClasses.
@Test
@UseDataProvider("beAnonymousClasses_rules")
public void beAnonymousClasses(ArchRule rule, Class<?> satisfied, Class<?> violated) {
EvaluationResult result = rule.evaluate(importClasses(satisfied, violated));
assertThat(singleLineFailureReportOf(result)).contains("classes should be anonymous classes").containsPattern(String.format("Class <%s> is not an anonymous class", quote(violated.getName()))).doesNotMatch(String.format(".*%s.* anonymous class.*", quote(satisfied.getName())));
}
use of com.tngtech.archunit.lang.EvaluationResult in project ArchUnit by TNG.
the class ClassesShouldTest method resideOutsideOfPackages.
@Test
@UseDataProvider("resideOutsideOfPackages_rules")
public void resideOutsideOfPackages(ArchRule rule, String... packageIdentifiers) {
checkTestStillValid(packageIdentifiers, ImmutableSet.of(ArchRule.class, 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 packages ['%s']", Joiner.on("', '").join(packageIdentifiers))).containsPattern(doesntResideOutsideOfPackagesPatternFor(ArchRule.class, packageIdentifiers)).containsPattern(doesntResideOutsideOfPackagesPatternFor(ArchCondition.class, packageIdentifiers)).doesNotContain(String.format("%s", GivenObjects.class.getSimpleName()));
}
use of com.tngtech.archunit.lang.EvaluationResult in project ArchUnit by TNG.
the class ClassesShouldTest method visibility.
@Test
@UseDataProvider("visibility_rules")
public void visibility(ArchRule rule, JavaModifier modifier, Class<?> satisfied, Class<?> violated) {
EvaluationResult result = rule.evaluate(importClasses(satisfied, violated));
assertThat(singleLineFailureReportOf(result)).contains(String.format("classes should be %s", modifier.name().toLowerCase())).containsPattern(String.format("Class <%s> .* modifier %s", quote(violated.getName()), modifier)).doesNotMatch(String.format(".*<%s>.* modifier %s.*", quote(satisfied.getName()), modifier));
}
use of com.tngtech.archunit.lang.EvaluationResult in project ArchUnit by TNG.
the class ClassesShouldTest method accessTargetWhere.
@Test
@UseDataProvider("accessTargetWhere_rules")
public void accessTargetWhere(ArchRule rule) {
EvaluationResult result = rule.evaluate(importClasses(ClassWithFieldMethodAndConstructor.class, ClassAccessingFieldMethodAndConstructor.class, ClassAccessingWrongFieldMethodAndConstructor.class));
assertThat(singleLineFailureReportOf(result)).contains(String.format("classes should access target where target is %s", ClassWithFieldMethodAndConstructor.class.getSimpleName())).containsPattern(accessTargetRegex(ClassAccessingWrongFieldMethodAndConstructor.class, ClassAccessingFieldMethodAndConstructor.class, "wrongField")).containsPattern(accessTargetRegex(ClassAccessingWrongFieldMethodAndConstructor.class, ClassAccessingFieldMethodAndConstructor.class, CONSTRUCTOR_NAME)).containsPattern(accessTargetRegex(ClassAccessingWrongFieldMethodAndConstructor.class, ClassAccessingFieldMethodAndConstructor.class, "call")).doesNotMatch(accessTargetRegex(ClassAccessingFieldMethodAndConstructor.class, ClassWithFieldMethodAndConstructor.class, ""));
}
use of com.tngtech.archunit.lang.EvaluationResult in project ArchUnit by TNG.
the class ClassesShouldTest method beTopLevelClasses.
@Test
@UseDataProvider("beTopLevelClasses_rules")
public void beTopLevelClasses(ArchRule rule, Class<?> satisfied, Class<?> violated) {
EvaluationResult result = rule.evaluate(importClasses(satisfied, violated));
assertThat(singleLineFailureReportOf(result)).contains("classes should be top level classes").containsPattern(String.format("Class <%s> is not a top level class", quote(violated.getName()))).doesNotMatch(String.format(".*%s.* top level class.*", quote(satisfied.getName())));
}
Aggregations