Any methods Mockito 4.11.0 tries to stub on a class which extends an abstract groovy (2.4.21) class result in NPE for me. The following example is how I am trying to stub two methods on the Demo class, but since Demo extends an abstract class all I get are NPE, even for the method “bar()” native to Demo. Removing the word “abstract” causes the test code to execute green. Can someone help me understand what I am doing wrong here and how I can mock classes which extend groovy abstract classes?
import org.junit.Test
import org.mockito.Mockito
import static org.mockito.Mockito.when
class Demo extends Foo {
boolean bar() {
return false
}
}
abstract class Foo {
Boolean isValid() {
return true
}
}
class DemoTest {
@Test
void testMe() {
Demo demo = Mockito.mock(Demo.class)
when(demo.isValid()).thenReturn(false) // will throw NPE
when(demo.bar()).thenReturn(false) // will throw NPE
}
}