SQiShER/java-object-diff

DiffNode is showing object difference although both the objects are same.

arun1607 opened this issue · 1 comments

I am having following test classes

`
import lombok.Getter;
import lombok.Setter;

import java.util.ArrayList;
import java.util.List;

/**

  • Created by amits on 28/09/16.
    */
    @Getter
    @Setter
    public class TestUser {

    private String name;

    private List testItems = new ArrayList<>();
    }

import lombok.Getter;
import lombok.Setter;

/**

  • Created by amits on 28/09/16.
    */
    @Getter
    @Setter
    public class TestItem {

    private String itemName;
    }
    `

and following test code

`
public class ObjectDiffTest1 {

@Test
public void testObjectDiffGeneration() throws Exception {
    TestUser firsUser = new TestUser();
    firsUser.setName("john");
    TestItem firstItem = new TestItem();
    firstItem.setItemName("MacBook");
    firsUser.getTestItems().add(firstItem);

    TestUser SecondUser = new TestUser();
    SecondUser.setName("john");
    TestItem secondItem = new TestItem();
    secondItem.setItemName("MacBook");
    SecondUser.getTestItems().add(secondItem);


    DiffNode diff = ObjectDifferBuilder.buildDefault().compare(firsUser, SecondUser);
    diff.visit((node, visit) -> {
        if (node.hasChanges() && !node.hasChildren())
            System.out.println(node.getPath() + " => " + node.getState());
    });
    Assert.assertTrue(diff.isChanged());

}

}
`

I am setting both the objects with same property but still the DiffNode says that object has changes.

Any help would be greatly appreciated.

Please point out if I am wrong in understanding in use of library.

I suppose that DiffNode should not have any changes if the nested objects is same but in above mentioned example I am getting diff even though both the objects are same.