Is UserFactory an interface or an implementation class?
jk
On Wed, Dec 16, 2009 at 09:02:16PM +0100, pieter claassen wrote:
I am trying to mock my DAO's, but I am not sure if I understand easymock
correctly.
In my WicketSession I store a user ID and use this to retrieve the current
logged in user from the database (by calling Spring injected
userFactory.getById((String)userId)).
Below is my setUp() for Junit. But the first expect line actually ends up
calling the UserFactory.getID() method. Considering that the factory has no
real connection, this call will obviously fail.
Here is my question: I thought the mock framework hijacks the actually call
and replaces the result with the dummy return value? Is there a way to stop
it from calling the method?
Thanks,
Pieter
public void setUp() {
mockContext = new AnnotApplicationContextMock();
UserFactory mockuserfactory=createMock(UserFactory.class);
User user=new User();
expect(mockuserfactory.getID(user)).andReturn(1L);
expect(mockuserfactory.getById(1L)).andReturn(user);
replay(mockuserfactory);
mockContext.putBean(userFactory, mockuserfactory);
MockWicketApplication webapp = new MockWicketApplication();
webapp.setMockContext(mockContext);
tester = new WicketTester(webapp);
tester.setupRequestAndResponse();
WicketSession session = (WicketSession) tester.getWicketSession();
session.setUser(user);
}
--
Pieter Claassen
musmato.com
-
To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org
For additional commands, e-mail: users-h...@wicket.apache.org