Package com.tngtech.archunit.lang
Class EvaluationResult
java.lang.Object
com.tngtech.archunit.lang.EvaluationResult
Represents the result of evaluating an
ArchRule against some JavaClasses.
To react to failures during evaluation of the rule, one can use handleViolations(ViolationHandler, Object[]):
result.handleViolations((Collection<JavaAccess<?>> violatingObjects, String message) -> {
// do some reporting or react in any way to violation
});
-
Constructor Summary
ConstructorsConstructorDescriptionEvaluationResult(HasDescription rule, ConditionEvents events, Priority priority) EvaluationResult(HasDescription rule, Priority priority) -
Method Summary
Modifier and TypeMethodDescriptionvoidadd(EvaluationResult part) filterDescriptionsMatching(Predicate<String> linePredicate) Filters all recordedConditionEventsby their textual description.final <T> voidhandleViolations(ViolationHandler<T> violationHandler, T... __ignored_parameter_to_reify_type__) Passes violations to the suppliedViolationHandler.boolean
-
Constructor Details
-
EvaluationResult
-
EvaluationResult
@PublicAPI(usage=ACCESS) public EvaluationResult(HasDescription rule, ConditionEvents events, Priority priority)
-
-
Method Details
-
getFailureReport
-
add
-
handleViolations
@SafeVarargs @PublicAPI(usage=ACCESS, state=EXPERIMENTAL) public final <T> void handleViolations(ViolationHandler<T> violationHandler, T... __ignored_parameter_to_reify_type__) Passes violations to the suppliedViolationHandler. The passed violations will automatically be filtered by the type of the givenViolationHandler. That is, when aViolationHandler<SomeClass>is passed, only violations by objects assignable toSomeClasswill be reported. Note that this will be unsafe for generics, i.e. ArchUnit cannot filter to match the full generic type signature. E.g.
might throw an exception if there are alsohandleViolations((Collection<Optional<String>> objects, String message) -> assertType(objects.iterator().next().get(), String.class) )Optional<Integer>violations. So, in general it is safer to use the wildcard?for generic types, unless it is absolutely certain from the context what the type parameter will be (for example when only analyzing methods it might be clear that the type parameter will beJavaMethod).- Type Parameters:
T- Type of the relevant objects causing violations. E.g.JavaAccess<?>- Parameters:
violationHandler- The violation handler that is supposed to handle all violations matching the respective type parameter__ignored_parameter_to_reify_type__- This parameter will be ignored; its only use is to make the generic type reified, so we can retrieve it at runtime. Without this parameter, the generic type would be erased.
-
hasViolation
-
getPriority
-
filterDescriptionsMatching
@PublicAPI(usage=ACCESS) public EvaluationResult filterDescriptionsMatching(Predicate<String> linePredicate) Filters all recordedConditionEventsby their textual description. I.e. the lines of the description of an event are passed to the supplied predicate to decide if the event is relevant.- Parameters:
linePredicate- A predicate to determine which lines of events match. Predicate.test(..) == true will imply the violation will be preserved.- Returns:
- A new
EvaluationResultcontaining only matching events
-