Tagebuch eines Technikers

Tuesday, May 20, 2008

JMock 1 short how-to

This document is a nice resource on how to perform a unit test with JMock (which is part of AppFuse).

For some small remarks on how to build the test, here is a portion of the code I used:
 List<Home> homes = new ArrayList<Home>();

// set expected behavior on dao
mock.expects(once()).method("findInPerimeter").with(eq(center),
eq(radius / Constants.KM_PER_DEGREE)).will(returnValue(homes));

List<Home> result = manager.findInPerimeter(center, radius);
assertEquals(result, homes);
This tells the mock that we expect the next method call of the proxied object (in this case a dao) to be of parameter findInPerimeter with the given parameters and to have a result of returnValue. manager uses this proxy to verify the call.

No comments: