How do I test private annotation aspect in spring boot ?
Example:
@Aspect
@Component
@Slf4j
public class AspectClass {
@AfterReturning(value = "@annotation(CustomAnnotation)")
private void privateMethod(JoinPoint joinPoint)
{
// Test this part
System.out.println("Want to test this");
}
}
@Retention(RetentionPolicy.RUNTIME)
@Target({ ElementType.METHOD, ElementType.TYPE })
public @interface CustomAnnotation {
String methodName() default "";
}
Expect to test the private method in Aspect with annotation trigger
If your application is spring-boot-web then you can use your existing Application.java or you have to ceate a new ApplicationTest.java that atleast have the following
Sample Test:
Expected output: