Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Hibernate+GroovyTestcase: Unable to figure out the error in the code below ..

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)
     }
}
like image 784
Phoenix Avatar asked Dec 20 '25 06:12

Phoenix


1 Answers

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)
like image 54
jhericks Avatar answered Dec 22 '25 21:12

jhericks



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!