I am getting a test failure on the test below. Specifically it complains for "expect(mockSession.save(hibernateTransitInfo)).andReturn(hibernateTransitInfo)" and it complains "incompatible return type"
Test code
void testCreateTransitFileInfo()
{
HibernateTransitInfo hibernateTransitInfo =
new HibernateTransitInfo(relationshipId: "12345")
expect(mockSessionFactory.currentSession).andReturn(mockSession)
expect(mockSession.save(hibernateTransitInfo)).andReturn(hibernateTransitInfo)
replayAll()
transitFileDao.createHibernateTransitInfo(hibernateTransitInfo)
verifyAll()
}
Actual DaoImplementation
@Repository("transitFileDao")
class TransitFileDaoImpl implements TransitFileDao{
@Autowired
SessionFactory sessionFactory
Session getCurrentSession()
{
return sessionFactory.currentSession
}
void createHibernateTransitInfo(HibernateTransitInfo hibernateTransitInfo)
{
currentSession.save(hibernateTransitInfo)
}
}
The return type of session.save(X) is a Serializable representing the identifier of the newly created X, so it should return the id of your HibernateTransitInfo, not the HibernateTransitInfo itself.
If I had to guess, I would say you want to do:
expect(mockSession.save(hibernateTransitInfo)).andReturn("1")
However, I'm pretty sure that this would also work, since you don't appear to care about the return value:
expect(mockSession.save(hibernateTransitInfo)).andReturn(null)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With