java - How to test Aspect in Spring MVC application - Stack Overflow
Mon Nov 30 2020 14:45:29 GMT+0000 (Coordinated Universal Time)
Saved by
@edwgarci
@Aspect
public class ThrowOnNullFirstArgAspect {
@Pointcut("" +
"within(@org.springframework.stereotype.Controller *) || " +
"within(@(@org.springframework.stereotype.Controller *) *)")
private void isController() {}
@Around("isController()")
public Object executeAroundController(ProceedingJoinPoint point) throws Throwable {
throwIfNullFirstArgIsPassed(point);
return point.proceed();
}
private void throwIfNullFirstArgIsPassed(ProceedingJoinPoint point) {
if (!(point.getSignature() instanceof MethodSignature)) {
return;
}
if (point.getArgs().length > 0 && point.getArgs()[0] == null) {
throw new IllegalStateException("The first argument is not allowed to be null");
}
}
}
content_copyCOPY
testing aop 1/2
https://stackoverflow.com/questions/36744607/how-to-test-aspect-in-spring-mvc-application
Comments