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

getter/setter testers not working for getter/setter making defensive copy of array in version 0.7.5 #212

Closed
gcire opened this Issue Sep 21, 2017 · 0 comments

Comments

Projects
None yet
2 participants
@gcire

gcire commented Sep 21, 2017

import java.util.Arrays;

public class AAA {
	private BBB[]  bbb = new BBB[] { new BBB(), new BBB() };
	public BBB[] getBbb() {
		return bbb == null ? null : Arrays.copyOf(bbb, bbb.length);
	}
	public void setBbb(BBB[] bbb) {
		this.bbb = (bbb == null) ? null : Arrays.copyOf(bbb, bbb.length);
	}
}
public class BBB { }

The getter/setter methods in above code making defensive copies for field of array type are unable to pass the following test.

assertPojoMethodsFor(AAA.class)
	.testing(Method.GETTER)
	.testing(Method.SETTER)
	.areWellImplemented();	

It looks like the cause is that Objects.equals(,) instead of Objects.deepEquals(,) is used in SetterAssertions class to compare values but the former doesn't seem to work for array copies. Same issue is with GetterAssertions

public class SetterAssertions {
    public void willSetValueOnField(final Method setter, final Field field, final Object expectedValue) {
        try {
            setter.setAccessible(true);
            setter.invoke(objectUnderAssert, expectedValue);
            final Object value = FieldUtils.getValue(objectUnderAssert, field);
            final boolean result = Objects.equals(value, expectedValue);

            checkResult(result, new SetterAssertionError(classUnderTest, field, expectedValue, value));
        } catch (IllegalAccessException | InvocationTargetException e) {
            throw new GetOrSetValueException(field.getName(), classUnderTest, e);
        }
    }

@sta-szek sta-szek added the bug label Sep 22, 2017

@sta-szek sta-szek added this to the 0.7.6 milestone Sep 22, 2017

@sta-szek sta-szek closed this Sep 25, 2017

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment