Replies: 1 comment 4 replies
-
Not a complete solution but there are "grammar wrappers" (methods that do nothing except adding a verb to the description) methods.that(are(locatedInPackageA))
.should(be(locatedInPackageA)) Thats what I do for my personal predicate collection, since you have context agnostic predicate names that can be used with the regarding verbs. The common verbs are covered by arch unit itself if I recall it correctly : "is", "are", "be", "not" |
Beta Was this translation helpful? Give feedback.
4 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Hey 👋
First of all, I love ArchUnit. I haven't known it for too long and I'm super motivitated now. Thank you. 🙏
Currently I'm writing a bunch oft custom predicates and conditions. But my problem is the naming. Often times there is a predicate that I also need as condition. So far no issue. But then I end up with naming problems.
In the beginning I though I could always differ predicate and condition with natural language. Like this (stupid) example:
classes().that(areFromTheDomainPackage).should(beInsideTheDomainPackage)
. The latter condition is based on the earlier predicate withArchCondition.from(areFromTheDomainPackage)
.But that approach seems to fall short sooner or later. Rather soon. An approach would be to accumulate predicates and conditions in static classes, kinda similar to how it is done in the library. But I think this hurts the readability a lot. While the top example (as useless it is) reads pretty neatless as sentence, this does not:
classes().that(MyPredicates.haveAMethodWithName("foo")).should(MyConditions.haveAMethodWithName("foo"))
.Sure, as long as a test class doesn't need both, predidate and condition, I can important them directly (don't even need the static accumulation class). But again, that does fall short quickly.
So I was reading your code base a lot. And while you sometimes have different names for predicate and condition and also use some static classes, the key difference is your usage of
ClassesThat
andClassesShould
(plus more) that allow a nice chaining of "operators". This way is is possible to do the above example likeclasses().that().haveAMethodWithName("foo").should().haveAMethodWithName("foo")
. Same name for predicts and condition, no naming collision.But the only way I see this is possible would be by extending the classes
ClassesThat
andClassesShould
and then overrideGivenClasses
to use those. And probably alsoArchRuleDefinition
. Not sure if that list is complete.Anyway, there seem to be no easy way to follow the above approch without extend a bunch of classes and replace the usage of library classes with the own ones. At least I don't see it. Also not with the concept of plugins and extensions.
So my question is simply if there is a better way to do it. Another alternative, a best practice, ...
Thank you very much for any input and help! 🙂
Beta Was this translation helpful? Give feedback.
All reactions