Skip to content

BeSealed() always returns true in Testing #435

@yulivee

Description

@yulivee

Hi, I am trying to test class constraints with ArchUnit and noticed that BeSealed() always seem to return a positive test, regardless of the actual class configuration.

This testcase should never be green, but is:

var commandsWithoutResult = Classes().That().ImplementAnyInterfaces(_commandInterfaceWithoutResult);

        var commandsSealedRule = commandsWithoutResult.Should().BeSealed();
        var commandsNotSealedRule = commandsWithoutResult.Should().NotBeSealed();
        var rules = commandsSealedRule
            .And(commandsNotSealedRule);
        rulesCheck(Setup.Architecture);

I have a class matching the condition of commandsWithoutResult, and when I get the object via GetObjects and check for IsSealed manually, the Test correctly states, that my class is not sealed:

        var objects = commandsWithoutResult.GetObjects(Setup.Architecture).ToArray();
        objects.Should().AllSatisfy(o => o.IsSealed.Should().BeTrue());

In my Debugger, I see the IsSealed Property is set to false

Image

Looking at the Sourcecode of BeSealed, I wonder whether the test just checks if the nullable value bool? IsSealed is set or not.

  public static ICondition<Class> BeSealed()
        {
            return new SimpleCondition<Class>(
                cls => !cls.IsSealed.HasValue || cls.IsSealed.Value,
                "be sealed",
                "is not sealed"
            );
        }

I feel like it should be !cls.IsSealed.HasValue && cls.IsSealed.Value == false. On the other hand, the definition of BeRecord() is the same and the BeRecord()-Test does not show this behaviour. So I am not exactly shure what is going on here.

Some willing to look into this?

Metadata

Metadata

Assignees

No one assigned

    Labels

    needs-triageIndicates that an issue needs to be categorized.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions