One can use AspectJ for enforcing some (design) rules.
- like every controller method need some special annotations
- every service/frontend/dto class must be located in a service/fronten/dto pacakge
- more mature thinks like: checking that setters do not have any logic.
Inject Mocks in classes that otherwise would create new instances by using new.
Assume you have this code:
public void sendInvitationEmail(String address) {
InvitationEmail email = new InvitationEmail();
email.sendTo(address).send();
}
And need to replace email
by an mock. Then you could use an Aspect (@Pointcut("call(InvitationEmail.new(..))")
) to "inject" a mock. -- @See Blog JMock and AspectJ by Daniel Roop, as well as Spring Roo`s @MockStaticEntityMethods (Mock Static Methods using Spring Aspect)