alexruiz / fest-assert-2.x

FEST Fluent Assertions 2.x
http://fest.easytesting.org
Apache License 2.0
402 stars 69 forks source link

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

Open michaelwiles opened 11 years ago

michaelwiles commented 11 years ago

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 :+1:

j-maly commented 10 years ago

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.