Git Product home page Git Product logo

Comments (7)

ramon2 avatar ramon2 commented on June 28, 2024 2

Thanks @GuiRodriguero and @hankem , with satisfied condition works perfectly

from archunit.

GuiRodriguero avatar GuiRodriguero commented on June 28, 2024 1

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.

ramon2 avatar ramon2 commented on June 28, 2024 1

yes, thanks

from archunit.

hankem avatar hankem commented on June 28, 2024

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 condition complyWithARule.
  • A rule noClasses().that()..should(breakARule) passes if and only if all classes selected by that().… actually violate the condition breakARule.

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 than A.
  • noClasses().should().haveSimpleName("A") fails on classes with simple name A.

You can change from noClasses() to classes() by inverting the condition (e.g. using ArchConditions.not or ArchConditions.never).

from archunit.

ramon2 avatar ramon2 commented on June 28, 2024

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.

hankem avatar hankem commented on June 28, 2024

@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.

hankem avatar hankem commented on June 28, 2024

I'm glad that it works for you! Can we then close this issue?

from archunit.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.