• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Devaka Cooray
  • Knute Snortum
  • Paul Clapham
  • Tim Cooke
Sheriffs:
  • Liutauras Vilda
  • Jeanne Boyarsky
  • Bear Bibeault
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Ron McLeod
  • Piet Souris
  • Frits Walraven
Bartenders:
  • Ganesh Patekar
  • Tim Holloway
  • salvin francis

Testing custom annotations  RSS feed

 
Ranch Hand
Posts: 194
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Is there any good way to mock annotated classes?

For example, I'm currently producing a mock with EasyMock. I now need to test how adding a custom annotation to the mocked class changes the behavior of the class under test that uses the annotated & mocked class.

I don't see how I would do this using EasyMock or jMock (or any dynamic mock tool since I believe it would fundamentally require creating a mock out of multiple interfaces (assuming the annotation can be treated as an interface)).

But handing coding multiple versions of the same mock so that the source has different annotations seems wrong.

Is there a better way for conducting tests where the class under test needs to interact with custom annotations on another class?
 
author
Posts: 11962
5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Originally posted by Eric Nielsen:
For example, I'm currently producing a mock with EasyMock. I now need to test how adding a custom annotation to the mocked class changes the behavior of the class under test that uses the annotated & mocked class.

But handing coding multiple versions of the same mock so that the source has different annotations seems wrong.


How big a job would it be to implement a static (hand-written) test double? Once you've done that, you could simply have different (empty) subclasses of the static test double that you stamp with different annotations.
 
Eric Nielsen
Ranch Hand
Posts: 194
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I believe it should be fairly easy. I'd need to hand-code an implementation of one of the underlying frameworks interfaces (ActionInvocation in Struts 2), but given that all I need it to do is return success codes since the behavior I'm testing is entirely annotation driven.... Then annotate ~4 sublcasses for testing... Its easy enough, just feels very wrong to make that 'many' extra test only classes
 
Lasse Koskela
author
Posts: 11962
5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Right. You could also check out whether JRetroFit would simplify the job further.
 
Consider Paul's rocket mass heater.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!