Skip to content

Support specialized equality methods #3678

@devinrsmith

Description

@devinrsmith

Feature summary

Often times, classes define specialized equality methods that have different semantics than Object#equals. It would be nice to be able to reference these directly via a BiPredicate<T, T> and have it work with isEqualTo and other relevant methods.

Example

assertThat(actual)
    .usingEqualityMethod((x, y) -> x.equalsStrict(y))
    .isEqualTo(expected);

// or

assertThat(actual)
    .usingEqualityMethod(MyObject::equalsStrict)
    .isEqualTo(expected);

I can currently hack around this by (ab)using usingComparator, but it's not ideal.

assertThat(actual)
    .usingComparator((x, y) -> x.equalsStrict(y) ? 0 : -1)
    .isEqualTo(expected)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions