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

Unexpected NotEqualEqualsAssertionError #245

Open
jacobhampel opened this issue Apr 21, 2020 · 0 comments
Open

Unexpected NotEqualEqualsAssertionError #245

jacobhampel opened this issue Apr 21, 2020 · 0 comments

Comments

@jacobhampel
Copy link

Version: 0.7.6

I have a class (EntityUnderTest) which has only one property.
If I initalize this object at either in the constructor of the EntityUnderTest or direct at declaration I'll get an NotEqualEqualsAssertionError error.
If a remove the inilization the test passes.

Here is the EntityUnderTest

public class EntityUnderTest

    private ChildEntity faultInjectionParameters = new ChildEntity();

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;
        EntityUnderTest that = (EntityUnderTest) o;
        return Objects.equals(faultInjectionParameters, that.faultInjectionParameters);
    }

    @Override
    public int hashCode() {
        return Objects.hash(faultInjectionParameters);
    }

And the child entity

public class ChildEntity {

    private String string;

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;
        ChildEntity that = (ChildEntity) o;
        return Objects.equals(string, that.string);
    }

    @Override
    public int hashCode() {
        return Objects.hash(string);
    }

}

I also added a short reprocuder here: https://github.com/jacobhampel/pojoTestReproducer

The error message says:

The equals method should return false if objects should not be equal

But the hashCode returns both the same value. So, I would expect that the test will pass.

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

No branches or pull requests

1 participant