title: Mockito - How to inject mocks if superclass contains field with same name and type as child class
body: <p>Is it possible to inject mocks in the superclass fields which are having the same name and type as the child class. </p>
  
  <p>In my situation, I have a controller class</p>
  
  <pre><code>abstract class BaseController {
      protected AccessManager accessManager;
  }
  </code></pre>
  
  <p>It is extended by a class like below:</p>
  
  <pre><code>class ApiController&lt;T&gt; extends BaseController {
  
  }
  </code></pre>
  
  <p>And finally, a more specialized controller extends it like this:</p>
  
  <pre><code>class PersonController extends ApiController&lt;Person&gt; {
       private AccessManager accessManager;
  }
  </code></pre>
  
  <p>I am writing unit tests for <code>PersonController</code> and while testing it, some of its methods call the <code>BaseController</code>'s method, which delegates calls it's <code>protected</code> member object, which is always <code>null</code>.</p>
  
  <p>I have tried using <code>@InjectMocks</code> and used <code>ReflectionTestUtils.setField</code> to set the protected field of the <code>BaseController</code>, but those methods only end up setting the field on <code>PersonController</code> class because their names and types are same. </p>
  
  <p>I have spent a lot of time in this but not able to solve it. Please help.
  Thanks</p>