RequestValidationAspect { @Around("execution(public * org.meridor.perspective.shell.common.request.Request+.getPayload(..))") public Object getPayload(ProceedingJoinPoint joinPoint) throws Throwable { Object request = joinPoint.getTarget(); Set<String> validationErrors = objectValidator.validate(request); if (!validationErrors.isEmpty()) { throw new InvalidRequestException(validationErrors); } return joinPoint.proceed(); } @Autowired  RequestValidationAspect(ObjectValidator objectValidator); @Around("execution(* org.meridor.perspective.shell.common.request.Request+.getPayload(..))") Object getPayload(ProceedingJoinPoint joinPoint);  }
@Test(expected = InvalidRequestException.class) public void testInvalidRequest() { requestProvider.get(MockRequest.class).getPayload(); }
@Test public void testValidRequest() { MockRequest mockRequest = requestProvider.get(MockRequest.class); mockRequest.setPayload("test"); assertThat(mockRequest.getPayload(), equalTo("test")); }