I use festAssertions in my tests and I noticed that using assertThat(object).isEqualTo(otherObject) yields different results than assertThat(object.equals(otherObject)).isTrue(); in tests where hibernate objects are tested.
I had to do workaround and now test looks really ugly but I cannot use
assertThat(collection).contains(object1, object2) because that just does not work!
Here is partial code(look at last line):
seasonRate, seasonRate1 are created and persisted. Then retrieved from db and checked against originals. Nothing fancy, but does not work with festAssertions.
Do you have any idea how to fix that and if it is some error on my side or not?
(...)
session.save(seasonRate);
session.save(seasonRate2);
session.getTransaction().commit();
session.close();
session = sessionFactory.getCurrentSession();
session.beginTransaction();
RateRepositoryHibernate rateRepositoryHibernate= new RateRepositoryHibernate(new StubHibernateSessionFactory(sessionFactory));
// when
final Collection<Rate> allRatesForRoom = rateRepositoryHibernate.getAllRatesForRoom(room);
// then
assertThat(allRatesForRoom.size()).isEqualTo(EXPECTED_RATES);
for(Rate rate : allRatesForRoom)
{
if(rate.getRateName().equals("season name 2"))
{
assertThat(rate.equals(seasonRate2)).isTrue();
}
if(rate.getRateName().equals("season name"))
{
assertThat(rate.equals(seasonRate)).isTrue();
}
}
//assertThat(allRatesForRoom).contains(seasonRate, seasonRate2); // this does not work somehow
It turns out that this is not festAssertions issue because after changes to code I cannot reproduce that bug and
.containsmethod works nicely.My changes were related to current session concept and I probably had some bad code.
If you happen to face similar issue then you should look for problems in your hibernate related code and configuration but not inside festAssertions.