Skip to content

equals method should not be overriden on interfaces #103

Description

@akutschera

While working on a fix for #102 I noticed that the following test fails:

    @RepeatedTest(10)
    void issue103() {
        var sut = Fixture.fixture().create(Closeable.class);

        assertThat(sut).isEqualTo(sut);
    }

This fails for interfaces and abstract classes because we create a proxy that returns a random value for any called method.

You have to run it multiple times, because the result of equals is a random boolean, so for some created fixtures it's true, for others it's false.
If we create random values for this, we violate the Java contract for equals and hashCode. This might lead to unexpected behaviour.
I believe this should be fixed before the fix for #102 can be merged.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions