Q:

How to mock a protected method of 3rd party code

Using Mockito I want to mock a property of a class so I can verify the output
public class MyClass extends ThirdPartyFramework {
  Output goesHere;

  @Override
  protected setup(){
    goesHere = new Output();
  }

  //...      
}

public abstract class ThirdPartyFramework {
  protected setup(){...}
  //...
}

I need to inject a mock of the Output class so I can validate that my code wrote the correct output.

But I can't just @InjectMock because the setup() method is called
mid-runtime and overwrites my injection.
And I can't just make setup public in MyClass because the test code I'm working
with is generic and needs to work for all subclasses of
ThirdPartyFramework, so I only have a reference to ThirdPartyFramework, meaning setup() is protected.

A:

I ended up solving this by wrapping ThirdPartyFramework and placing that class in the same package as the ThirdPartyFramework class.
That way I could mock the protected methods with Mockito. Then I was able to use @InjectMock to inject a mock of the Output object and control its method calls via that mock.

