Comments (7)
Thanks @GuiRodriguero and @hankem , with satisfied
condition works perfectly
from archunit.
Hi @ramon2!
I faced the same issue today and for me, changing from events.add(violated...) to events.add(satisfied...) was enough
If you're telling ArchUnit "no classes should be like this", then the condition must be satisfied, not violated
Let me know if it works for you :)
from archunit.
yes, thanks
from archunit.
There seems to be a confusion about the semantics of the condition in these rules (which could be better documented 🙈):
- A rule
classes().that().
….should(complyWithARule)
passes if and only if all selected classes satisfy the conditioncomplyWithARule
. - A rule
noClasses().that().
….should(breakARule)
passes if and only if all classes selected bythat().
… actually violate the conditionbreakARule
.
This is why it's actually expected that your test with the "alwaysFail
" condition indeed passes perfectly.
Whenever I can't wrap my head around this kind of logic, I imagine a simple example:
classes().should().haveSimpleName("A")
fails on classes with simple name other thanA
.noClasses().should().haveSimpleName("A")
fails on classes with simple nameA
.
You can change from noClasses()
to classes()
by inverting the condition (e.g. using ArchConditions.not
or ArchConditions.never
).
from archunit.
Thanks @hankem for the response, but I tried all possible scenarios using ArchRuleDefinition.noClasses()
with a custom ArchCondition and I couldn't make the tests fail. For example, I tested cases where the condition:
- always fails for all evaluated classes
- only fails for one of the evaluated classes
- never fails for any of the evaluated classes
and the result is always successful. Could you provide an example that fails with noClasses()
and a custom ArchCondition? I suppose I’m missing something, and maybe an example could help me.
from archunit.
@GuiRodriguero is exactly right:
Whether the evaluation of an ArchCondition
needs to add aConditionEvent
that isViolated
or not depends only on the semantics of the condition – for example, haveSimpleName("A")
adds a SimpleConditionEvent
with satisfied = true
for every object that has simple name "A"
and satisfied = false
for every other object. It then depends on the rule which objects pass the test and which fail. (That's why alwaysFail
is a misleading name for your demo condition.)
from archunit.
I'm glad that it works for you! Can we then close this issue?
from archunit.
Related Issues (20)
- question about calling line numbers HOT 3
- Using MethodReferences is still breaking soundness HOT 5
- Usability: Java confuses the static and non-static versions of DescribedPredicate.and() when using the API the wrong way. HOT 3
- Unable to find the JavaAccess call HOT 8
- Feature suggestion: Freeze files and stored.rules validation / sanity check
- How To : validate return type is not `void` HOT 2
- How To : Is there way to filter classes when using `importJar()` HOT 1
- DEPRECATED_API_SHOULD_NOT_BE_USED does not consider constants nor final fields HOT 2
- ASM is not up-to-date
- Jakarta Inject package name incorrect in BE_ANNOTATED_WITH_AN_INJECTION_ANNOTATION rule HOT 1
- How can I find out which gradle module a class belongs to HOT 7
- Problem with maven multi module project HOT 2
- Check access classes only works for some cases HOT 1
- ArchUnit do not correctly check Annotation on enum Constants HOT 2
- ArchUnit thinks "Switch with arrows" produces non-final fields HOT 1
- Feature suggestion: Expose synchronized blocks in core API
- Performance: archunit-junit5 may scan complete JDK for `@ArchTest`
- SimpleName-Check failing because of trailing file extension (Kt) HOT 6
- ArchUnits - get name of lambda method HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from archunit.