AuditAspect { @Around("anySaveMethod() && args(entity)") public Object auditSave(ProceedingJoinPoint joinPoint, AbstractAuditableEntity<?> entity) throws Throwable { setAuditFields(entity); return joinPoint.proceed(); }  @Pointcut("execution(* com.ocs.dynamo.service.BaseService+.save(..))") static void anySaveMethod(); @Around("anySaveMethod() && args(entity)") Object auditSave(ProceedingJoinPoint joinPoint, AbstractAuditableEntity<?> entity);  }
@Test public void testSaveNew() throws Throwable { MyAuditableEntity entity = new MyAuditableEntity(); aspect.auditSave(joinPoint, entity); assertEquals("Kevin", entity.getCreatedBy()); assertEquals("Kevin", entity.getChangedBy()); assertNotNull(entity.getCreatedBy()); assertNotNull(entity.getChangedOn()); }
@Test public void testSaveExisting() throws Throwable { MyAuditableEntity entity = new MyAuditableEntity(); entity.setId(33); entity.setCreatedBy("Stuart"); entity.setChangedBy("Stuart"); aspect.auditSave(joinPoint, entity); assertEquals("Stuart", entity.getCreatedBy()); assertEquals("Kevin", entity.getChangedBy()); assertNotNull(entity.getCreatedBy()); assertNotNull(entity.getChangedOn()); }