我在测试中使用了 festAssertions,我注意到使用assertThat(object).isEqualTo(otherObject)
产生的结果与assertThat(object.equals(otherObject)).isTrue();
测试休眠对象的测试不同。
我不得不做解决方法,现在测试看起来真的很难看,但我不能使用
assertThat(collection).contains(object1, object2)
,因为那不起作用!
这里是部分代码(看最后一行): seasonRate, seasonRate1 被创建和持久化。然后从数据库中检索并检查原件。没什么花哨的,但不适用于 festAssertions。
您是否知道如何解决该问题以及是否是我这边的一些错误?
(...)
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