Hi John,

UserFactory is a class and I am using EasyMocks class extensions.

import static org.easymock.classextension.EasyMock.*;


Thanks,
Pieter


On Wed, Dec 16, 2009 at 9:38 PM, John Krasnay <[email protected]> wrote:

> 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: [email protected]
> For additional commands, e-mail: [email protected]
>
>


-- 
Pieter Claassen
musmato.com

Reply via email to