title: Mock Protected Parent Method When the Parent is in a Different Package and the Child Class is Abstract
body: <p>I need to mock a protected method in the parent class of my class under test but the parent class is in a different package. I thought that the solution would be to use <code>PowerMockito.spy()</code> but I cannot instantiate the type Child because it is abstract. There's gotta be a solution for this issue without refactoring.</p>
  
  <p>Here's the Dependencies.</p>
  
  <pre><code>        &lt;dependency org="org.powermock" name="powermock-core" rev="1.6.4"/&gt;
          &lt;dependency org="org.powermock" name="powermock-module-junit4" rev="1.6.4"/&gt;
          &lt;dependency org="org.powermock" name="powermock-api-mockito" rev="1.6.4"/&gt; 
  </code></pre>
  
  <p>This is legacy code so I cannot refactor, but here's the simplified code.</p>
  
  <p><strong>Parent.java</strong></p>
  
  <pre><code>package parent;
  
  public class Parent {
  
      // Want to mock this protected parent method from different package
      protected String foo() {
  
          String someValue = null;
  
          // Logic setting someValue
  
          return someValue;
      }
  }
  </code></pre>
  
  <p><strong>Child.java</strong></p>
  
  <pre><code>package child;
  
  import parent.Parent;
  
  public abstract class Child extends Parent {
  
      String fooString = null;
  
      public String boo() {
  
          this.fooString = this.foo();
  
          String booString = null;
  
          // Logic setting booString
  
          return booString;
      }
  }
  </code></pre>