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

isEqualsToByComparingFields does not actually compare fields...? #152

Open
michaelwiles opened this issue Apr 11, 2013 · 1 comment
Open

Comments

@michaelwiles
Copy link

Consider...

public class TestEqualToByComparingFields {
    public static class X {
        public X(String message) {
            this.message = message;
        }

        private String message;

    }

    @Test
    public void testIsEqualToByComparingFields() {
        X x1 = new X("1");
        X x2 = new X("2");
        assertThat(x1).isEqualsToByComparingFields(x2);

    }
}

By my reading of the that method, "isEqualsToByComparingFields" this test should fail as message field is different.

However, the test passes.

It is only when I add the getter and the setter for that field message that the test fails.

Should the method not be named "isEqualsToByComparingProperties"? since it's not actually comparing fields but using the getters and setters for comparison.

I had a look at the method and it uses BeanInfo - so it is definitely only comparing on getters and setters.

I assume this is by design but it does make the method name misdirecting?

btw, I do really like this library 👍

@j-maly
Copy link

j-maly commented Feb 23, 2014

I've also bumped into this, the name of the assertion is really misleading and providing one that really does use fields for comparison and ignores properties would be appreciated.

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

2 participants