views:

80

answers:

1

We have developed some code which analyzes annotated methods and adds some runtime behaviour. I would like to test this. Currently I am hand-coding stubs with certain annotations for setting up my test-case.

Usually I am using a mocking-framework (currently easymock) to avoid hand-coding test-doubles (stubs or mocks). But I haven't found a way to use mocking-frameworks to annotate my test-doubles. This is cumbersome because it involves having a lot of stupid-dummy source code, which is annoying to maintain (reading, writing and refactoring tests).

Something like:


MyAnnotation annoMock = createMock(MyAnnotation.class);
record(annoMock.getSupported()).andReturn(true);
....
annotate(method).with(annoMock);

Does somebody know whether there is such a record-feature especially for annotations (all targets like method,class, fields etc.) for easymock? if not available for easymock is there an alternative mock-library?

A: 

Hi, I'm not aware of a quick and easy way to do what you describe but check out the second answer in a related thread here on SO. Sounds kind of funky to me and I'm not sure if the approach would work with mock objects created with easymock. But if someone succeeds to pull this off it sure would be interesting to hear about it :)

Petri Pellinen