-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 
Author Message
 Post subject: "Classic" Sessions causing mock testing problems
PostPosted: Wed Jan 16, 2008 12:54 pm 
Newbie

Joined: Wed Jan 16, 2008 11:38 am
Posts: 1
Location: White Plains, NY
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?


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.