Skip to content

Including a "Collection" attribute in the Configuration #70

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

Closed
gulench opened this issue Jul 27, 2013 · 2 comments
Closed

Including a "Collection" attribute in the Configuration #70

gulench opened this issue Jul 27, 2013 · 2 comments
Milestone

Comments

@gulench
Copy link

gulench commented Jul 27, 2013

How do you set up a Configuration that includes a "Collection" attribute? Please refer the test code snippet shown below; I'm not able to make it work.

On the other hand, Configuration.withoutProperty works with the PropertyPath aliases.

Object class to compare:

public class Person {
  private String name;
  private List<String> aliases;

  public Person() {
  }

  public Person(String name, List<String> aliases) {
    this.name = name;
    this.aliases = aliases;
    this.addresses = addresses;
  }

  public String getName() {
    return this.name;
  }

  public void setName(String name) {
    this.name = name;
  }

  public List<String> getAliases() {
    return this.aliases;
  }

  public void setAliases(List<String> aliases) {
    this.aliases = aliases;
  }

Test class:

@RunWith(JUnit4.class)
public class Test {
  @Test
  public void testIncludeCollectionAttribute() {
    Person a = new Person(
      "Gulen Chongtham",
      Arrays.asList(new String[] {"Hola Espanyol", "Vicky Boss"})
    );

    Person b = new Person(
      "Gulen Chongthamm",
      Arrays.asList(new String[] {"Hola Espanyol", "Vicky Boss", "Roger Harper"})
    );

    ObjectDiffer differ = ObjectDifferFactory.getInstance(
      new Configuration()
        .withPropertyPath(PropertyPath.buildWith("aliases"))
    );

    Node root = differ.compare(b, a);
    root.visit(new PrintingVisitor(b, a));

    assertTrue(root.isChanged());
  }
}
@SQiShER
Copy link
Owner

SQiShER commented Jul 28, 2013

Good catch! Looks like that's a bug. The problem is, once you configure included properties, all other properties are implicitly excluded. The current implementation is a little bit too restrictive though, as it also excludes the children of included properties. So even though the aliases are included, the entry Roger Harper is excluded and therefore no change is detected. I'll try to fix this sometime this week.

As a workaround, you could just not include anything specifically (if possible) or use the excludes instead.

SQiShER added a commit that referenced this issue Jul 29, 2013
@SQiShER
Copy link
Owner

SQiShER commented Jul 30, 2013

This is fixed in the latest release.

@SQiShER SQiShER closed this as completed Jul 30, 2013
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants