The tutorials provide an example of how to write an expectation with JMock too:
http://www.appfuse.org/display/APF/Services#Services-managertest

Just as every JUnit test needs one or more assertions, a test with JMock needs an expectation.

If you stick with JMock (the default), then you just need to write something like this for each test:

// set expected behavior on dao
        dao.expects(once()).method("get")
                .with(eq(id))
                .will(returnValue(move));

Alex

On 17 Dec 2007, at 13:42, Peter Schneider-Manzell wrote:

Yes, you need a expectation for every call on a mock executed during a test.

I would recommend to use EasyMock instead of JMock.
It's very easy to use, e.g. creating a mock:

GameDAO gameDAO = EasyMock.createStricktMock (GameDAO.class);

If you call a method e.g. public Game getGame(Long id) on gameDAO, simply add something like

Game game = new Game();
EasyMock.expect(gameDAO.getGame(1L)).andReturn(game);

to replay the Mock, use EasyMock.replay(gameDAO);

In order to verify a mock, call EasyMock.verify(gameDAO);

Bye,

Peter

2007/12/17, Struts2 Fan <[EMAIL PROTECTED] >:

I have no expectation for the moveDao, must I define an expectation for each
Dao I have used in methods?

--
View this message in context: 
http://www.nabble.com/-Appfuse2.0--Best-Practise-Design-Pattern-for-Multiple-Dao-Access-from-managers-tp14116309s2369p14370264.html
Sent from the AppFuse - User mailing list archive at Nabble.com.

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



Reply via email to