Hi,
I just started to use PowerMock and seems that I finally found the solution to test some old legacy code that implements the ActiveRecord pattern using static finder methods.
Example:
I have the following constructor in a Base class:
protected AbstractDBO() {
final Field[] fields = this.getClass().getDeclaredFields();
if (fields != null) {
for (Field field : fields) {
oldValueMap.put(field.getName(), null);
}
}
}
The Disk classed inherits from AbstractDBO and implements a static finder Method (
public static Disk findBy(DiskId id) {
return byId(Disk.class, id.getValue());
}
The static mock is defined like this:
PowerMock.mockStaticNice(DBO_Disk.class);
expect(DBO_Disk.findBy(new DiskId(BigDecimal.ONE))).andReturn(newDiskObject);
The goal should be to mock all calls to the static finder methods.
But I get: java.lang.IllegalStateException: missing behavior definition for the preceding method call getDeclaredFields()
Any ideas what I'm doing wrong ?
Regards
Roger
--
You received this message because you are subscribed to the Google Groups "PowerMock" group.
To view this discussion on the web visit https://groups.google.com/d/msg/powermock/-/DJZPtGWRCeIJ.
To post to this group, send email to powe...@googlegroups.com.
To unsubscribe from this group, send email to powermock+...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/powermock?hl=en.