I'm using
jMock to do test-driven development with mock objects on a
Spring MVC Java web application using Hibernate 3.2.5.ga.
I'm running into a problem with the fact that SessionFactory.getCurrentSession() returns org.hibernate.classic.Session, rather than org.hibernate.Session. Here's my test:
Code:
context.checking(new Expectations() {{
one (mockFactory).getCurrentSession(); // expect getCurrentSession() to be called on mock SessionFactory
will(returnValue(mockSession)); // force mock SessionFactory to return mock Session
one (mockSession).load("Foo", "fooId"); // expect load(...) to be called on mock Session
will(returnValue(stubFoo)); // force mock Session to return stub domain object
}});
fooRepository.load("fooId");
context.assertIsSatisfied();
If I declare mockSession as org.hibernate.classic.Session, then everything works fine, but if I declare it as org.hibernate.Session, then I get the error:
Code:
java.lang.IllegalStateException: tried to return an incompatible value: expected a org.hibernate.classic.Session but returned a $Proxy6
Maybe I'm being too persnickety, but having to refer to the "classic' Session in my test code bothers me, since
new code should use org.hibernate.Session (and my test code will break when I upgrade to a version of Hibernate that drops backwards compatibility with Hibernate 2).
Any ideas?