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

Unable to chain withIgnoredFields, gives wrong error #171

Closed
NRBPerdijk opened this issue Jul 13, 2017 · 2 comments
Closed

Unable to chain withIgnoredFields, gives wrong error #171

NRBPerdijk opened this issue Jul 13, 2017 · 2 comments
Labels

Comments

@NRBPerdijk
Copy link
Contributor

What steps will reproduce the problem?

Try to ignore multiple fields by calling .withIgnoredFields("fieldName") multiple times, instead of parsing in multiple arguments into a single call. The error message produced (java.lang.IllegalArgumentException: You can call either withOnlyTheseFields or withIgnoredFields, but not both.) does not apply to the issue (multiple calls to the withIgnoredFields function, which is not currently supported).

What is the code that triggers this problem?

public final class AnyClassUnderTest {

    private Long firstFieldToBeIgnored;
    private String secondFieldToBeIgnored;
    private String thirdField;

    @Override
    public boolean equals(final Object o) {
        if (this == o) {
            return true;
        }

        if (o == null || getClass() != o.getClass()) {
            return false;
        }

        final AnyClassUnderTest that = (AnyClassUnderTest) o;
        return Objects.equals(thirdField, that.thirdField);
    }

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

}
public class AnyClassUnderTestTest {
    @Test
    public void equals() throws Exception {
        EqualsVerifier.forClass(AnyClassUnderTest.class)
                .withIgnoredFields("firstFieldToBeIgnored")
                .withIgnoredFields("secondFieldToBeIgnored")
                .verify();
    }

}

What error message or stack trace does EqualsVerifier give?

java.lang.IllegalArgumentException: You can call either withOnlyTheseFields or withIgnoredFields, but not both.

at nl.jqno.equalsverifier.EqualsVerifier.checkIgnoredFields(EqualsVerifier.java:339)
at nl.jqno.equalsverifier.EqualsVerifier.withIgnoredFields(EqualsVerifier.java:178)
at nl.rabobank.gict.fpx.flf.query.service.model.db.AnyClassUnderTestTest.equals(AnyClassUnderTestTest.java:12)

The error message is incorrect.

What did you expect?

A correct error message, or that chaining simply works. :-)

Which version of EqualsVerifier are you using?

EqualsVerifier Version 2.3

Please provide any additional information below.

@jqno
Copy link
Owner

jqno commented Jul 20, 2017

Reproduced. Unsurprisingly, the same thing happens with withOnlyTheseFields.

@jqno
Copy link
Owner

jqno commented Aug 24, 2017

Thanks for the PR! It's contained in version 2.3.3, which is just released.

@jqno jqno closed this as completed Aug 24, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants