Search...
FAQs
Subscribe
Pie
FAQs
Recent topics
Flagged topics
Hot topics
Best topics
Search...
Search within Struts
Search Coderanch
Advance search
Google search
Register / Login
Post Reply
Bookmark Topic
Watch Topic
New Topic
programming forums
Java
Mobile
Certification
Databases
Caching
Books
Engineering
Micro Controllers
OS
Languages
Paradigms
IDEs
Build Tools
Frameworks
Application Servers
Open Source
This Site
Careers
Other
Pie Elite
all forums
this forum made possible by our volunteer staff, including ...
Marshals:
Campbell Ritchie
Jeanne Boyarsky
Ron McLeod
Paul Clapham
Liutauras Vilda
Sheriffs:
paul wheaton
Rob Spoor
Devaka Cooray
Saloon Keepers:
Stephan van Hulst
Tim Holloway
Carey Brown
Frits Walraven
Tim Moores
Bartenders:
Mikalai Zaikin
Forum:
Struts
Easy Mock - Hibernate Session Factory issue?
Mohamed Farouk
Ranch Hand
Posts: 249
posted 13 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
Hello friends
Can you help me a bit why easy mock is throwing this exception?
java.lang.IllegalStateException: missing behavior definition for the preceding method call getSession() at org.easymock.internal.MockInvocationHandler.invoke(MockInvocationHandler.java:41) at org.easymock.internal.ObjectMethodsFilter.invoke(ObjectMethodsFilter.java:72) at $Proxy0.getSession(Unknown Source) at com.betaglobal.bid2rent.dao.TestUserDAOImpl.testValidateLogin(TestUserDAOImpl.java:53) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) at java.lang.reflect.Method.invoke(Method.java:597) at junit.framework.TestCase.runTest(TestCase.java:168) at junit.framework.TestCase.runBare(TestCase.java:134) at junit.framework.TestResult$1.protect(TestResult.java:110) at junit.framework.TestResult.runProtected(TestResult.java:128) at junit.framework.TestResult.run(TestResult.java:113) at junit.framework.TestCase.run(TestCase.java:124) at junit.framework.TestSuite.runTest(TestSuite.java:232) at junit.framework.TestSuite.run(TestSuite.java:227) at org.junit.internal.runners.JUnit38ClassRunner.run(JUnit38ClassRunner.java:81) at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:46) at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197)
public class TestUserDAOImpl extends TestCase { private UserDAO userDAO; private Bid2RentHibernateSessionFactory hibernateSessionFactoryMock; private Session sessionMock; private Criteria criteriaMock; private SessionFactory factoryMock; protected Long id; @Before public void setUp() throws Exception { hibernateSessionFactoryMock = createMock(Bid2RentHibernateSessionFactory.class); criteriaMock = createMock(Criteria.class); sessionMock = createMock(Session.class); factoryMock = createMock(SessionFactory.class); userDAO = new UserDAOImpl(hibernateSessionFactoryMock); } @Test public void testValidateLogin() { String username = "mohamed"; String password = "farouk"; User user = new User(); user.setId(1l); user.setUsername(username); user.setPassword(password); expect(hibernateSessionFactoryMock.getSession()).andReturn(sessionMock); expect(criteriaMock.add(Restrictions.eq("username", username))) .andReturn(criteriaMock); expect(criteriaMock.add(Restrictions.eq("password", password))) .andReturn(criteriaMock); expect(criteriaMock.uniqueResult()).andReturn(user); userDAO.validateLogin(username, password); verify(hibernateSessionFactoryMock,sessionMock,criteriaMock); } }
SCJP, SCWCD, SCBCD, SCEA 5
David Newton
Author
Posts: 12617
I like...
posted 13 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
Don't you have to replay (or something like that; I haven't used it in awhile) before you can run code against the mock?
Don't get me started about those stupid
light bulbs
.
reply
reply
Bookmark Topic
Watch Topic
New Topic
Boost this thread!
Similar Threads
Creating one-to-one mapping: ConstraintViolationException
little help with start ejb testing
Junit test: cannot find test Method although that it is already defined in the test class
Newbie having problems with StrutsMocktestCase
Jboss rar JNDI lookup
More...