I've just started using DynaMock objects in my testing and for the most
part I really like them. I've run into a situation that I would like to
test with a dynamic Mock object, but I'm not sure if a dynamic Mock object
can do what I want. I'm trying to test an object that has the following
behavior:
1. My test object registers itself with a model object to be notified of
changes in the model.
2. A method is invoked on the test object which causes the test object to
store a value into the model object.
3. The model object notifies interested parties that something about it
has changed.
I've created a dynamic Mock object for the model such that it expects to
have its notification registration method called with a particular type of
object. The mocked model also expects to have one of its setters called
with a specific value. What I haven't figured out how to do is test the
model notification behavior. What I would like to be able to do is ask
the Mock for the object which was sent to it for the registration method.
I could then simulate a call on that handler method and verify that the
handler did the things it was supposed to do. Something like this:
Mock mockModel = new Mock(Model.class);
mockModel.expectAndCapture("addValueChangeHandler", new
IsInstanceOf(AspectChangeHandler.class));
...
AspectChangeHandler configuredHandler =
mockModel.capturedValueFor("addValueChangeHandler");
configuredHandler.aspectChanged();
...
I'm contemplating making some extensions to a new subclass of Mock to
handle this situation, but I'm wondering if there is some other way to
accomplish the same thing using the standard dynamic mock capabilities.
Of course, I could always code up a MockModel class to work the way I
want, but if I can do something with dynamic mock objects I would like to
use it.
On a related note, are there any good examples of dynamic mock usage? I'm
looking for examples which might show how to fully exploit its power.
Thanks.
--
James Howe
|