I've found it useful to initialise my mock objects to be very tight in
their expectations, so I can be sure that calls to verify() actually
do the right thing. The generic code to do this is as
follows:
public void clearExpectations() {
Field[] fields
= this.getClass().getDeclaredFields();
try {
for (int i = 0; i
< fields.length; i++) {
Field field = fields[i];
if
(field.getType() == ExpectationCounter.class) {
ExpectationCounter counter = ((ExpectationCounter)
field.get(this));
counter.setFailOnVerify();
counter.setExpectNothing();
}
if (field.getType() ==
ExpectationList.class) {
ExpectationList list =
((ExpectationList) field.get(this));
list.setFailOnVerify();
list.setExpectNothing();
}
}
}
catch (IllegalArgumentException e) {
}
catch
(IllegalAccessException e) {
}
}
Regards,
-Darren