use of com.tngtech.archunit.base.DescribedPredicate in project ArchUnit by TNG.
the class GivenCodeUnitsTest method types_match_for_methods.
@Test
public void types_match_for_methods() {
EvaluationResult result = methods().that(new DescribedPredicate<JavaMember>("are there") {
@Override
public boolean test(JavaMember input) {
return true;
}
}).and(new DescribedPredicate<JavaMethod>("are there") {
@Override
public boolean test(JavaMethod input) {
return true;
}
}).should(new ArchCondition<JavaMethod>("not exist") {
@Override
public void check(JavaMethod method, ConditionEvents events) {
events.add(SimpleConditionEvent.violated(method, "expected violation"));
}
}).evaluate(importClasses(ClassWithVariousMembers.class));
assertThat(Joiner.on(" ").join(result.getFailureReport().getDetails())).contains("expected violation");
}
use of com.tngtech.archunit.base.DescribedPredicate in project flink-mirror by flink-ci.
the class Conditions method haveLeafExceptionTypes.
/**
* Tests leaf exception types of a method against the given predicate.
*
* <p>See {@link #haveLeafTypes(DescribedPredicate)} for details.
*/
public static ArchCondition<JavaMethod> haveLeafExceptionTypes(DescribedPredicate<JavaClass> typePredicate) {
return new ArchCondition<JavaMethod>("have leaf exception types" + typePredicate.getDescription()) {
@Override
public void check(JavaMethod method, ConditionEvents events) {
final List<JavaClass> leafArgumentTypes = method.getExceptionTypes().stream().flatMap(argumentType -> getLeafTypes(argumentType).stream()).collect(Collectors.toList());
for (JavaClass leafType : leafArgumentTypes) {
if (!isJavaClass(leafType)) {
continue;
}
if (!typePredicate.apply(leafType)) {
final String message = String.format("%s: Exception leaf type %s does not satisfy: %s", method.getFullName(), leafType.getName(), typePredicate.getDescription());
events.add(SimpleConditionEvent.violated(method, message));
}
}
}
};
}
Aggregations