tags:

views:

38

answers:

1

My unit test framework replaces business service components with Mock objects using EasyMock.createMock(Interace).

These components are accessed several layers down in the class under test so I don't wish to modify either the interface definition nor the class undertest.

I then use EasyMock.expect(...) to drive the behavoir of the collaborating objects. This works great as long as the methods don't return void.

How can I drive the behavior when there are void results. Ie.

EasyMock.expect(object.Method( EasyMock.isA(arg1) ).andAnswer( new IAnswer()){
    public void anser(){
   ... do seomething meaningful with arg1...
    }).anyTimes();
+1  A: 

You can use expectLastCall().andReturn("something");.

You don't mention which version of EasyMock you're using, but I think this feature has been around for a while anyway.

Read more in the documentation.

Epcylon
Thanks! (That works). I'm sure I'm using the lastest version since installed it a couple of days ago.