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

Default comparator for raw Collections #746

Closed
bartoszwalacik opened this Issue Nov 25, 2018 · 3 comments

Comments

Projects
None yet
2 participants
@bartoszwalacik
Member

bartoszwalacik commented Nov 25, 2018

Currently, JaVers skips comparing fields of Collection type

For example, in this class, clients field is ignored:

public class Company {
    private String id; 
    private Collection<Person> clients;
    private List<Person> partners;
}

and only this warnign is logged. Expected behaviour would be using List comparator.

10:19:40.332 [main] WARN  o.j.c.d.a.CollectionChangeFakeAppender - Collections: Field Collection<Person> clients; //declared in Company
are not equals but can't be compared. Raw Collection properties are not supported. Expected Set, List or any of their subclasses. JaVers uses different algorithms for comparing Sets and Lists and needs to know (statically) which one to test.

bartoszwalacik added a commit that referenced this issue Nov 25, 2018

#747

bartoszwalacik added a commit that referenced this issue Nov 25, 2018

#747
@bartoszwalacik

This comment has been minimized.

Member

bartoszwalacik commented Nov 27, 2018

released in 4.0.0-RC3

@baumgartner

This comment has been minimized.

baumgartner commented Dec 3, 2018

    @Test
    public void equalEntityClientTest() {
        Person e1 = new Person("james", "ignore this");
        List<Person> l1 = new ArrayList<Person>();
        l1.add(e1);
        Company le1 = new Company("1", null, l1, null);

        Person e2 = new Person("james", "");
        List<Person> l2 = new ArrayList<Person>();
        l2.add(e2);
        Company le2 = new Company("1", null, l2, null);
        Diff diff = javers.compare(le1, le2);

        System.out.println(diff);
        assertEquals(0, diff.getChanges().size());
    }

Works with ListCompareAlgorithm.Simple
Assert fails with ListCompareAlgorithm.AS_SET
Exception with ListCompareAlgorithm.LEVENSHTEIN_DISTANCE

java.lang.ClassCastException: java.util.Collections$UnmodifiableSet cannot be cast to java.util.List
	at org.javers.core.diff.appenders.levenshtein.LevenshteinListChangeAppender.calculateChanges(LevenshteinListChangeAppender.java:39)
	at org.javers.core.diff.appenders.levenshtein.LevenshteinListChangeAppender.calculateChanges(LevenshteinListChangeAppender.java:21)
	at org.javers.core.diff.appenders.CollectionAsListChangeAppender.calculateChanges(CollectionAsListChangeAppender.java:32)
	at org.javers.core.diff.appenders.CollectionAsListChangeAppender.calculateChanges(CollectionAsListChangeAppender.java:14)
	at org.javers.core.diff.appenders.CorePropertyChangeAppender.calculateChanges(CorePropertyChangeAppender.java:45)
	at org.javers.core.diff.DiffFactory.appendChanges(DiffFactory.java:151)
	at org.javers.core.diff.DiffFactory.appendPropertyChanges(DiffFactory.java:141)
	at org.javers.core.diff.DiffFactory.createAndAppendChanges(DiffFactory.java:123)
	at org.javers.core.diff.DiffFactory.create(DiffFactory.java:69)
	at org.javers.core.diff.DiffFactory.compare(DiffFactory.java:54)
	at org.javers.core.JaversCore.compare(JaversCore.java:173)
	at javers.test.JaversListTest.equalEntityClientTest(JaversListTest.java:37)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.lang.reflect.Method.invoke(Method.java:498)
	at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:50)

Test-Project: https://github.com/baumgartner/javerstest/blob/master/src/test/java/javers/test/CollectionCompareTest.java

bartoszwalacik added a commit that referenced this issue Dec 5, 2018

#747
#746
fixes
@bartoszwalacik

This comment has been minimized.

Member

bartoszwalacik commented Dec 5, 2018

Fixed in 5.0.1 for all algorithms.

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