title: How to test an SpringBoot aspect method with JUnit?
body: <p>I use Springboot and I want test my new custom annotation by JUnit.</p>
  <p>My original code with my <code>@CronLogger</code> custom annotation on <code>importData</code> method:</p>
  <pre><code>@Service
  @RequiredArgsConstructor
  @Slf4j
  public class ImportTask {
    @Async
    @Scheduled(cron = &quot;${import}&quot;)
    @SchedulerLock(name = &quot;import&quot;)
    @CronLogger()
    public void importData() {
      ...
    }
  }
  </code></pre>
  <p><strong>My custom annotation:</strong></p>
  <pre><code>@Retention(RetentionPolicy.RUNTIME)
  @Target(ElementType.METHOD)
  public @interface CronLogger {
   
  }
  </code></pre>
  <p><strong>My custom Aspect method:</strong></p>
  <pre><code>@Aspect
  @Component
  @EnableAspectJAutoProxy
  public class CronLoggerAspect {
      
      private static final Logger log = LoggerFactory.getLogger(CronLoggerAspect.class);
      
      @Around(&quot;@annotation(CronLogger)&quot;)
      public Object trace(ProceedingJoinPoint joinPoint) throws Throwable {
          System.out.println(&quot;CronLogger&quot;);
          log.debug(&quot;CronLogger&quot;);
          return joinPoint.proceed();
      }
  }
  </code></pre>
  <p><strong>My JUnit test:</strong></p>
  <pre><code>@Slf4j
  @ExtendWith(MockitoExtension.class)
  @Import(AnnotationAwareAspectJAutoProxyCreator.class) // activate aspect
  class ImportTaskTest {
  
      @InjectMocks
      private ImportTask importTask;
  
      @Test
      void importData() throws JSchException, SftpException, SftpTransfertException {
          // execute test
          importTask.importData();
      }
  
  }
  </code></pre>
  <p>the result is OK but whitout execute Aspect method code.</p>