title: Inject mock object using SpringJUnit4ClassRunner and Mockito into Aspect Class
body: <p>I have a test class with <code>@RunWith(SpringJUnit4ClassRunner.class)</code> and this to initialize mockito:  </p>
  
  <pre><code>@Before
  public void initMocks() {
      MockitoAnnotations.initMocks(this);
  }
  </code></pre>
  
  <p>Now I have an @Autowired field to get aspect advising it, but cannot inject mocks.</p>
  
  <p>My aspect:</p>
  
  <pre><code>@Autowired
  private MyMock myMock;
  @Around("execution(* xxx.MyService.aspectMethod(..))")
  public void process(ProceedingJoinPoint joinPoint) throws Throwable {
      myMock.mockMethod();
  }
  </code></pre>
  
  <p>My test class:   </p>
  
  <pre><code>@RunWith(SpringJUnit4ClassRunner.class)
  @EnableAspectJAutoProxy(proxyTargetClass = true)
  public class MyTest {
  
      @Autowired
      private MyService myService;
      @Mock
      private MyMock myMock;
      @InjectMocks
      private MyAspectClass;
  
      @Before
      public void initMocks() {
          MockitoAnnotations.initMocks(this);
      }    
  
  
      public void shouldXXXX() {
  
          doThrow(Exception.class).when(myMock).mockMethod();
          myService.aspectMethod();
  
          ....
      }
  
      ...
  }
  </code></pre>
  
  <p>The issue is that the aspect triggered is not the same of what I'm mocking.</p>