title: Spy a method from parent class in a class with injected mocks with Mockito
body: <p>I'm using Mockito in a Java project with Spring and Struts and I'm having problems with testing actions.</p>
  
  <p>I'm not using the Struts2 jUnit plugin to save time with the tests using this approach: <a href="https://stackoverflow.com/a/11051902/1591100">Strut 2.3.1.2 Unit test, how to remove Spring codependency vs NPE with getContext()</a>.</p>
  
  <p>The problem is when in my action, when <em>getText()</em> is called I've got a NullPointerException.</p>
  
  <p>I'm trying to spy this method, that's inherited from <em>ActionSupport</em> but I don't find a way because the action is annotated with <em>InjectMocks</em> in the test.</p>
  
  <p>Here's a simplied example of the classes:</p>
  
  <p>Parent:</p>
  
  <pre><code>public class ActionSupport {
      public String getText(String  aTextName){
          return this.getTextProvider().getText(aTextName);
      }
  }
  </code></pre>
  
  <p>My action:</p>
  
  <pre><code>public class MyAction extends ActionSupport {
      @Autowired private IMyService myService;
  
      public String execute(){
          getText("SomeText");
          myService.something();
          return SUCCESS;
      }
  }
  </code></pre>
  
  <p>Test:</p>
  
  <pre><code>@RunWith(MockitoJUnitRunner.class)
  public class MyClassTest {
      @Mock private IMyService myService;
      @InjectMocks private MyAction myAction;
  
      @Before
      public void before() {
          MockitoAnnotations.initMocks(this);
      }
  
      @Test
      public void test() {
          myAction.execute();
      }
  }
  </code></pre>
  
  <p>I'm getting this exception:</p>
  
  <pre><code>java.lang.NullPointerException
      at com.opensymphony.xwork2.util.TextParseUtil.translateVariables(TextParseUtil.java:167)
      at com.opensymphony.xwork2.util.TextParseUtil.translateVariables(TextParseUtil.java:126)
      at com.opensymphony.xwork2.util.TextParseUtil.translateVariables(TextParseUtil.java:48)
      at com.opensymphony.xwork2.util.LocalizedTextUtil.getDefaultMessage(LocalizedTextUtil.java:663)
      at com.opensymphony.xwork2.util.LocalizedTextUtil.findText(LocalizedTextUtil.java:534)
      at com.opensymphony.xwork2.util.LocalizedTextUtil.findText(LocalizedTextUtil.java:362)
      at com.opensymphony.xwork2.TextProviderSupport.getText(TextProviderSupport.java:208)
      at com.opensymphony.xwork2.TextProviderSupport.getText(TextProviderSupport.java:123)
      at com.opensymphony.xwork2.ActionSupport.getText(ActionSupport.java:103)
      at es.MyAction.execute(MyAction.java:148)
  </code></pre>
  
  <p>And if I annotate <em>MyAction</em> with <em>@Spy</em> maintaining <em>@InjectMocks</em> I've got an <em>StackOverflowError</em>.</p>
  
  <p>How can I spy only <em>ActionSupport.getText()</em> and let <em>mockito</em> inject mocks on my action?</p>