-
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
Feature/make arbitrary arch conditions from predicates #858
Feature/make arbitrary arch conditions from predicates #858
Conversation
a62810e
to
483274e
Compare
@codecholeric, do you have time for some feedback on this? Thanks! |
Hey, sorry that it took me so long, work pipeline problems 😬 Thanks a lot for your push here! 😃
The
These two conditions were tailored in a way that they worked internally, but for me they don't have the quality to make it into the public API 🤔 At least I would want a better violation description somehow. Sometimes the description of the predicate is also fine, but it would at least be necessary to customize it (as these classes allow internally, exactly for cases like the above). Originally I had thought of something like a more convenient lambda API on E.g.
I.e. have some optional additional methods like Regarding your problems, do you have exactly the problem mentioned in #437? Because according to #437 (comment) it should have been fixed by some upgrade, no? I wonder why it runs on Windows CI without any problem, maybe there the |
Hi @codecholeric, thanks for the long answer even on a Sunday ;) If this holds for most examples, it would Regarding the other problems, I need to check again on my work machine. |
The only problem I see about |
I would rather go with a way to make the condition creator more customizable. For simple cases the predicate might already be fine, then you don't have to do anything. But for complex cases you should be able to customize it to have correct wording. I also think having it as a factory method on |
0ac6a6a
to
c255117
Compare
I am still checking in semi-blind, as even rebasing onto latest gives me errors on As for the code: assertThat (ArchCondition
.from( JavaClass.Predicates.simpleName( "SimpleName" ) )
.withViolationString( "does not have" ) )
.hasDescription( "do not have simple name 'SimpleName'" ); but I don't know if it is something the builder should support or that is generated "around" as the ArchCondition is used. |
I've had a similar issue once (and I can still reproduce it on your branch):
|
@u3r I would also guess what @hankem suggested about the
And AFAIS that was what was necessary at the time to make Spotless work unfortunately 😞 As for your question above, I'm not sure I completely understand. The description of the
|
I'll take a look at the fails and suggestions but it will take me a while to get back to this - just as a heads up |
Signed-off-by: Ulf Dreyer <ulf.dreyer@gmx.de>
Signed-off-by: Ulf Dreyer <ulf.dreyer@gmx.de>
Since ArchCondition is already handled contravariantly we can exclude methods that convert from DescribedPredicate to ArchCondition from the contravariance check. Signed-off-by: Ulf Dreyer <ulf.dreyer@gmx.de>
…contravariant Test does not correctly trigger Signed-off-by: Ulf Dreyer <ulf.dreyer@gmx.de>
Signed-off-by: Ulf Dreyer <ulf.dreyer@gmx.de>
c255117
to
b00394e
Compare
I'm working out the technical problems (thanks to @codecholeric and @hankem) Indeed I need the global However I am still no satisfied with the api. @ArchTest
ArchRule demoRule = methods()
.should( never(
ArchCondition.from( HasName.Predicates.nameEndingWith( "s" ).forSubtype() )
.withViolationString( "has a" ) // customize single violation text (this one uses the original description)
/* This next section is needed, because we have no way to customize the original predicate description "name ending with 's'"
This is especially bad as you need to repeat the original description again creating noise during rule definition
*/
.as( "have a name ending with 's'" )
) )
.because( "We don't want that" );
@ArchTest
ArchRule demoRule2 = methods()
.should( never(
ArchCondition.from( ArchPredicates.have(HasName.Predicates.nameEndingWith( "s" )) ) // no need for (further) description customization
//again we need to repeat the original description again (as now it's prefix does not match) creating noise during rule definition
.describeViolatedAs( entity -> entity.getDescription() + "has a name ending with 's'" )
) )
.because( "We don't want that" );
@ArchTest
ArchRule demoRule3 = methods()
.should( never(
ArchCondition.from( HasName.Predicates.nameEndingWith( "s" ).forSubtype() ) // how to document that ArchPredicates.have and friends may not be used
.withDescriptionPrefix("have a") // prefix for the predicate description (reusing that)
.withViolationPrefix( "has a" ) // prefix for the predicate description (reusing that) in the violation case (singular)
) )
.because( "We don't want that" );
@ArchTest
ArchRule demoRule4 = methods()
.should( never(
ArchConditions.have( HasName.Predicates.nameEndingWith( "s" ).forSubtype() ) // how to document that ArchPredicates.have and friends may not be used
) )
.because( "We don't want that" );
Before I start spending time with cleanup, naming and such please have a look and let's agree on My personal favourite would be to implement something that supports |
I'm against adding something to the official API that works nicely in 70% of the cases and badly otherwise. I think it's fine doing this as a user, but I'm not convinced of adding such a thing to the core for all to use. I can see the argument about the bloat, but for me that doesn't trump that an API should work 100% of the cases 🤷♂️ My ideas would be a) instead of
Then the case where it just works would simply be b) To the fluent API I would not add |
To move forward in smaller steps I have taken your PR, extracted a part from it and fixed it up a little here: #904 |
converted to #904, no more use for this |
This is a partial fix for #855.
I've added two of the methods with some tests.
A couple of points though:
a) I had severe problems, getting this to build (see #437) and test (in IntelliJ lots of tests are executed even if only a few are selected). So formatting might be off
b) I have adapted one architecture check - my reasoning is that just converting from a
DescribedPredicate<T>
to aArchCondition<T>
is ok without contravariance. It makes stuff easier to diagnose and doesn't loose any power as ArchConditions are already handled contravariantly.c) I have also added an 'inverse' test but I cannot get that to fail - beats me why.
I'm looking forward to your feedback!