Hibernate + GroovyTestcase: No se puede averiguar el error en el siguiente código.

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"

Código de prueba

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)
     }
}

preguntado el 08 de noviembre de 11 a las 17:11

1 Respuestas

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)

respondido 09 nov., 11:00

No es la respuesta que estás buscando? Examinar otras preguntas etiquetadas or haz tu propia pregunta.