Is there a way to verify that a non-accessible parent class overridden method is called in a child class overriding method? For example given
I know this isn't a new question as I have searched online and found multiple threads, but none have solutions (at least when the method is non-accessible) and the threads are fairly old now.
public class ChildTest {
@Test
public void testMethod() { Parent parent = spy(new Parent());
Child child = spy(new Child());
Whitebox.invokeMethod(child, "method", ...);
// Attempt 1 fails as child and parent are not linked
Mockito.verify(parent, Mockito.times(1));
Whitebox.invokeMethod(parent, "method", ...);
// Attempt 2 fails as it doesn't realise this is a reference to the parent's method even with the cast
Mockito.verify(child, Mockito.times(1));
Whitebox.invokeMethod((Parent)child, "method", ...);
}
}
I know one suggestion is to refactor and use composition instead of extending, but I would like to know if there is a way to do it without refactoring, or if there are any plans for this?
Thanks