I am trying to use the Mockito function for deep stamping using a method doReturn.
When I use a method when, as in the deep stubbing example, it works fine:
Foo mock = mock(Foo.class, RETURNS_DEEP_STUBS);
when(mock.getBar().getName()).thenReturn("deep");
But when I try to do the same with doReturn, I get WrongTypeOfReturnValue:
doReturn("deep").when(mock).getBar().getName();
I tried this too, but then I get UnfinishedStubbingException:
doReturn("deep").when(mock.getBar()).getName();
doReturn("deep").when(mock.getBar().getName());
How can I use the deep stamping function using the method doReturn?
(I know that the use of deep stubbing is not encouraged by some, including the Mockito developers. I'm not sure if I agree with their position on this issue. Let me leave this discussion out of this problem.)
source
share