Skip to content
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

Allows to containsInAnyOrder with a Comparator #404

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

lhauspie
Copy link

Sometimes, when we develop according to DDD principles, for aggregates and entities, we implement the equals method to compare instances based only on the identifier, not on all fields.

However, in tests, we'd like to ensure that a collection contains items based on all (or some) fields in addition to the identifier.

With this proposal, we'll be able to do just that with this type of code:

    assertThat(peoples,
        containsInAnyOrder(
            Comparator.<People, String>comparing(p -> p.getIdentifier())
                .thenComparing(p -> p.getFirstName())
                .thenComparing(p -> p.getLastName())
                .compare(o1, o2),
            new People(1, "John", "Doe"), new People(2, "Jane", "Doe")
        )
    );

If you agree with this proposal, I could extend this functionality to the IsIterableContainingInOrder and IsIterableContainingInRelativeOrder matchers.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant