title: Injecting mocks with Mockito does not work
body: <p>I'm using Mockito to test my Spring project, but the <code>@InjectMocks</code> seems not working in injecting a mocked service into another Spring service(bean).</p>
  <p>Here is my Spring service that I want to test:</p>
  <pre><code>@Service
  public class CreateMailboxService {   
      @Autowired UserInfoService mUserInfoService; // this should be mocked
      @Autowired LogicService mLogicService;  // this should be autowired by Spring
  
      public void createMailbox() {
          // do mething
          System.out.println(&quot;test 2: &quot; + mUserInfoService.getData());
      }
  
  }
  </code></pre>
  <p>And below is the service that I want to mock:</p>
  <pre><code>@Service
  public class UserInfoService {
      public String getData() {
          return &quot;original text&quot;;
      }
  }
  </code></pre>
  <p>My test code is here:</p>
  <pre><code>@RunWith(SpringJUnit4ClassRunner.class)
  @ContextConfiguration(locations = { &quot;file:src/main/webapp/WEB-INF/spring/root-context.xml&quot; })
  public class CreateMailboxServiceMockTest {
  
      @Mock
      UserInfoService mUserInfoService;
  
      @InjectMocks
      @Autowired
      CreateMailboxService mCreateMailboxService;
  
      @Before
      public void setup() {
          MockitoAnnotations.initMocks(this);
      }
  
      @Test
      public void deleteWithPermission() {
          when(mUserInfoService.getData()).thenReturn(&quot;mocked text&quot;);
      
          System.out.println(&quot;test 1: &quot; + mUserInfoService.getData());
      
          mCreateMailboxService.createMailbox();
      }
  }
  </code></pre>
  <p>but the result would like</p>
  <pre><code>test 1: mocked text
  test 2: original text  // I want this be &quot;mocked text&quot;, too
  </code></pre>
  <p>it seems that the <em>CreateMailboxService</em> didn't get the mocked <em>UserInfoService</em> but using Spring's autowired bean.
  Why is my <code>@InjectMocks</code> not working?</p>