Reputation: 1892
I have a problem. In my JUnit test i want to test the insertion in my db done by hibernate. I got an entity which avec a Setlist and i want to see if the list inserted is equals to the list i've set.
assertEquals(listDerogationLinux, derogation.getListDerogationLinux());
The problem is that hibernate use PersistentSet and i use HashMap so when i try to compare them i got an AassertionError :
java.lang.AssertionError: expected: java.util.HashSet<[...]> but was: org.hibernate.collection.internal.PersistentSet<[...]>
I've tried a lot a things but the only thing that work is to make a new hashSet with the PersistentSet but it is really ugly ...
assertTrue(new HashSet<DerogationLinux>(derogation.getListDerogationLinux()).equals(listDerogationLinux));
Is there a better way ?
Upvotes: 2
Views: 1899
Reputation: 1160
Try to call equals on PersistentSet instead of HashSet. It should work.
persistentSet.equals(hashSet)
Upvotes: 2