-
Notifications
You must be signed in to change notification settings - Fork 301
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add API to create ArchConditions from predicates #904
Add API to create ArchConditions from predicates #904
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
All in all it looks good to me - just two remarks for my curiosity.
"Fixed it up a little" puts a different meaning to "a little" than I would though ;-)
Thanks for doing this - as announced I didn't find any time the passt few weeks for following up on this.
archunit/src/main/java/com/tngtech/archunit/lang/conditions/ArchConditions.java
Show resolved
Hide resolved
Okay, let's say |
All good for me, looking forward to getting rid of some copy/pasta in our codebase with the new version! |
There have been some leftovers from the Java 8 migration like obsolete explicit type arguments where it can be inferred. Signed-off-by: Peter Gafert <peter.gafert@tngtech.com>
Signed-off-by: Peter Gafert <peter.gafert@tngtech.com>
The naming was a little inconsistent, `IsConditionByPredicate` took the details description as model for the name ("is/isn't"), while `HaveConditionByPredicate` took the condition description. Now they both take the condition description to derive the class name. Signed-off-by: Peter Gafert <peter.gafert@tngtech.com>
e349294
to
2cc486e
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's gonna be very useful! (I love how ArchConditions
could be shortened by almost 300 LoC.)
archunit/src/test/java/com/tngtech/archunit/lang/syntax/elements/MembersShouldTest.java
Show resolved
Hide resolved
archunit/src/main/java/com/tngtech/archunit/base/DescribedPredicate.java
Outdated
Show resolved
Hide resolved
archunit/src/main/java/com/tngtech/archunit/lang/conditions/ArchConditions.java
Outdated
Show resolved
Hide resolved
archunit/src/main/java/com/tngtech/archunit/lang/conditions/ArchConditions.java
Show resolved
Hide resolved
archunit/src/main/java/com/tngtech/archunit/lang/ArchCondition.java
Outdated
Show resolved
Hide resolved
archunit/src/main/java/com/tngtech/archunit/lang/ArchCondition.java
Outdated
Show resolved
Hide resolved
archunit/src/main/java/com/tngtech/archunit/lang/ArchCondition.java
Outdated
Show resolved
Hide resolved
archunit/src/main/java/com/tngtech/archunit/lang/ArchCondition.java
Outdated
Show resolved
Hide resolved
archunit/src/main/java/com/tngtech/archunit/lang/ArchCondition.java
Outdated
Show resolved
Hide resolved
archunit/src/test/java/com/tngtech/archunit/lang/ArchConditionTest.java
Outdated
Show resolved
Hide resolved
So far there has not been any straight forward way to turn a `DescribedPredicate` into an `ArchCondition`, even though the semantics are fairly similar (both determine if elements match a certain condition). The reason is, that `ArchCondition` needs more information than `DescribedPredicate`. While `DescribedPredicate` only needs to have some description to be displayed as part of the `ArchRule` text, `ArchCondition` additionally needs to describe each single event/violation that occurs. And the way how to do this depends on the predicate (take e.g. "does not *have* simple name 'Demo'" vs "is no enum" or "does not reside in a package 'com.demo'"). Thus, we have created a generic factory method `ArchCondition.from(predicate)` and two more convenient "sentence-like" factory methods `ArchConditions.{have/be}(predicate)` that can be used for most common cases. In any case if the event description does not fit it is possible to adjust it via `ConditionByPredicate.describeEventsBy(..)`. Signed-off-by: Ulf Dreyer <ulf.dreyer@gmx.de> Signed-off-by: Peter Gafert <peter.gafert@tngtech.com>
450c1bd
to
19839a1
Compare
This is huge, for the 1.0.0 Release I am definetly going to donate and if time let's me even contribute to this lovely project. |
So far there has not been any straight forward way to turn a
DescribedPredicate
into anArchCondition
, even though the semantics are fairly similar (both determine if elements match a certain condition). The reason is, thatArchCondition
needs more information thanDescribedPredicate
. WhileDescribedPredicate
only needs to have some description to be displayed as part of theArchRule
text,ArchCondition
additionally needs to describe each single event/violation that occurs. And the way how to do this depends on the predicate (take e.g. "does not have simple name 'Demo'" vs "is no enum" or "does not reside in a package 'com.demo'"). Thus, we have created a generic factory methodArchCondition.from(predicate)
and two more convenient "sentence-like" factory methodsArchConditions.{have/be}(predicate)
that can be used for most common cases. In any case if the event description does not fit it is possible to adjust it viaConditionByPredicate.describeEventsBy(..)
.Issue: #855