Class EvaluationResult

java.lang.Object
com.tngtech.archunit.lang.EvaluationResult

@PublicAPI(usage=ACCESS) public final class EvaluationResult extends Object
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 Details

  • Method Details

    • getFailureReport

      @PublicAPI(usage=ACCESS) public FailureReport getFailureReport()
    • add

      @PublicAPI(usage=ACCESS) public void add(EvaluationResult part)
    • 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 supplied ViolationHandler. The passed violations will automatically be filtered by the type of the given ViolationHandler. That is, when a ViolationHandler<SomeClass> is passed, only violations by objects assignable to SomeClass will be reported. Note that this will be unsafe for generics, i.e. ArchUnit cannot filter to match the full generic type signature. E.g.
      
       handleViolations((Collection<Optional<String>> objects, String message) ->
           assertType(objects.iterator().next().get(), String.class)
       )
       
      might throw an exception if there are also 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 be JavaMethod).

      For any ViolationHandler<T> violating objects that are not of type T, but implement Convertible will be converted to T and the result will be passed on to the ViolationHandler. This makes sense for example for a client who wants to handle Dependency, but the ConditionEvents corresponding objects are of type JavaAccess which does not share any common meaningful type.
      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

      @PublicAPI(usage=ACCESS) public boolean hasViolation()
    • getPriority

      @PublicAPI(usage=ACCESS) public Priority getPriority()
    • filterDescriptionsMatching

      @PublicAPI(usage=ACCESS) public EvaluationResult filterDescriptionsMatching(Predicate<String> linePredicate)
      Filters all recorded ConditionEvents by 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 EvaluationResult containing only matching events