title: Mock final method in superclass
body: <p>I am creating a new service 'MyService' that extends <a href="https://guava.dev/releases/19.0/api/docs/com/google/common/util/concurrent/AbstractScheduledService.html" rel="nofollow noreferrer">AbstractScheduledService</a> and MyService inherits a final method <em>isRunning()</em> from it.</p>
  <pre><code>public class MyService extends AbstractScheduledService {}
  </code></pre>
  <p>I also have a health check for 'MyService' that invokes <em>isRunning()</em> to see if 'MyService' is healthy.</p>
  <pre><code>public class MyServiceHealthcheck {
         MyService myService;
         
         @Inject
         public MyServiceHealthCheck(MyService myService) {
            this.myService = myService;
         }
  
         public boolean isHealthy() {
            return myService.isRunning();
         }
  }
  </code></pre>
  <p>And finally, I am trying to create unit test 'MyServiceHealthcheckTest' for testing MyServiceHealthcheck</p>
  <pre><code>public class MyServiceHealthcheckTest {
         @Mock MyService myService;
  }
  </code></pre>
  <p>The mock is initialized properly and I'm able to get expected value for methods defined in MyService but <em>myService.isRunning()</em> always returns a NullPointerException. What is the best way to mock <em>isRunning()</em> method?</p>