TNG / ArchUnit

A Java architecture test library, to specify and assert architecture rules in plain Java
http://archunit.org
Apache License 2.0
3.17k stars 287 forks source link

add automatic conversions to violation handling #1251

Closed codecholeric closed 5 months ago

codecholeric commented 6 months ago

The extensive freedom of how to create a ConditionEvent causes problems for any client that needs more structured results (e.g. tools). ViolationHandler provides a convenient API to obtain only those sort of violations that can be handled by a client (e.g. tackling dependencies). However, the type of the correspondingObject attached to the ConditionEvent can take many forms. From classes to methods, method calls, dependencies or aggregated dependencies (like module dependencies) it's hard to determine the possibilities and handle them all. Furthermore, the type of some objects (e.g. ComponentDependency isn't even public, so there is hardly any clean way to handle these objects.

To mitigate this a little we now support transparent conversions between compatible objects. E.g. a component dependency can also be considered a set of class dependencies. ViolationHandler now allows to be used including these conversions that are implemented by standard ArchUnit objects where reasonable. This allows e.g. to obtain all module dependencies as Set<Dependency> for every violation.