meanbeanlib / meanbean

Automated JavaBean Testing
Apache License 2.0
15 stars 3 forks source link

Bean elements with byte[] property returns (randomly) AssertionError #7

Closed Ichigo85 closed 4 years ago

Ichigo85 commented 4 years ago

Hi. I have a strange issue, it seems a flaky test, because sometimes testing all my POJOs works, sometimes don't with the following error.

java.lang.AssertionError: objects that differ due to supposedly significant property [contentBytes] were considered equal. (
x.contentBytes=[[B@4eaf3684]
vs
y.contentBytes=[[B@1bae316d]
). is property [contentBytes] actually insignificant?

    at org.meanbean.util.AssertionUtils.fail(AssertionUtils.java:51)
    at org.meanbean.test.SignificantObjectPropertyEqualityConsistentAsserter.assertConsistent(SignificantObjectPropertyEqualityConsistentAsserter.java:95)

This kind of error only occurs on classes with a byte[] property, and test fails randomly. The equals method is written like this (generated by IntelliJ):

@Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (!(o instanceof Input)) return false;
        Input input = (Input) o;
        return Objects.equals(firstName, input .firstName) &&
                Objects.equals(lastName, input .lastName) &&
                Objects.equals(email, input .email) &&
                Arrays.equals(contentBytes, input.contentBytes) &&
    }

    @Override
    public int hashCode() {
        int result = Objects.hash(firstName, lastName, email);
        result = 31 * result + Arrays.hashCode(contentBytes);
        return result;
    }

I think, in this case, the error is probably in class SignificantObjectPropertyEqualityConsistentAsserter, on this line boolean newPropertyValueEqualsOriginalPropertyValue = newPropertyValue.equals(originalPropertyValue); because in this case the right way is Array.equals...What I don't understand is why it's a flaky test, it does not fail every time.

meanbeanlib commented 4 years ago

the right way is Array.equals.

Yup, correct.

 

What I don't understand is why it's a flaky test, it does not fail every time.

Ah, looks like it happens when the randomly generated array is empty:

User@737a135b[contentBytes={}]
User@687ef2e0[contentBytes={}]
newPropertyValueEqualsOriginalPropertyValue    false    
originalObjectEqualsModifiedObject             true 
meanbeanlib commented 4 years ago

Latest release should fix this problem. Please give it a try.