title: @Autowire combined with @InjectMocks
body: <p>I have a Spring boot project which has a suite of unit tests which use mockito's @InjectMocks to both instantiate the class being tested and inject any mocks which may be present into it.</p>
  
  <p>In other words if I have this</p>
  
  <blockquote>
    <p>@InjectMocks 
    MyClass myClass;</p>
  </blockquote>
  
  <p>Then I do not need</p>
  
  <blockquote>
    <p>MyClass myClass = New MyClass();<br>
    or 
    @Autowired
    MyClass myClass;</p>
  </blockquote>
  
  <p>Until now this setup worked fine.</p>
  
  <p>However more recently it has become necessary to have access to the projects spring boot properties when running tests. This means it has been necessary to use the SpringBoot task runner inside tests so that any instances of @Autowire (including those which instantiate the Environment class) work.</p>
  
  <p>I discovered that if @InjectMocks is used to instantiate a class then any instances of @Autowired inside the class do not work (the object they should create is null). This means no Environment class and no access to Spring properties.</p>
  
  <p>Instead i have to add @Autowired to the @InjectMocks annotation</p>
  
  <p>so this</p>
  
  <blockquote>
    <p>@InjectMocks 
    MyClass myClass;</p>
  </blockquote>
  
  <p>becomes this</p>
  
  <blockquote>
    <p>@Autowired<br>
    @InjectMocks 
    MyClass myClass;</p>
  </blockquote>
  
  <p>My question is simple.
  Is there anything wrong with doing this?
  Does it double instantiate myClass or do anything that may causes glitches</p>