title: Integration tests for AspectJ
body: <p>I am trying to write Integratation  tests for Custom Aspect. Here is the Aspect Class Snippet.</p>
  
  <pre><code>@Aspect
  @Component
  public class SampleAspect {
  
      private static Logger log = LoggerFactory.getLogger(SampleAspect.class);
  
     private int count;
  
     public int getCount(){
        return count;
     }
  
      public void setCount(){
        this.count= count;
      }
  
  
      @Around("execution(* org.springframework.data.mongodb.core.MongoOperations.*(..)) || execution(* org.springframework.web.client.RestOperations.*(..))")
      public Object intercept(final ProceedingJoinPoint point) throws Throwable {
          logger.info("invoked Cutom aspect");
           setCount(1);
           return point.proceed();
  
      }
  
  }
  </code></pre>
  
  <p>So the above aspect intercepts whenever jointpoint matches the pointcut. Its working fine. But my question is how to perform Integration test.</p>
  
  <p>What I have done is I created the attribute  "count" in Aspect for tracking and asserted it in my Junit. I am not sure if this is good or is there a better way of doing integration testing on aspects.</p>
  
  <p>Here is the snippet of Junit what I have done. I presented in bad way but I hope its undestandable of what I have done for Integration testing.</p>
  
  <pre><code>@Test
  public void testSamepleAspect(){
     sampleAspect.intercept(mockJointPoint);
     Assert.assertEquals(simpleAspect.getCount(),1);
  }
  </code></pre>