What you are doing wrong is that you have created a mock for AbstractWarp and therefore your actual implementation of AbstractWarp.distance
is never being called.
What you need for AbstractWarp
is a spy
instead of a mock
like this:
AbstractWarp warp = spy(new AbstractWarp()); //instead of new AbstractWarp() use whatever other initialization is appropriate
doReturn(loc).when(warp).getLocation();
Note that if you aren't actually going to be calling AbstractWarp.getLocation
, you don't need the spy
at all for AbstractWarp
. A regular class will do just fine