I have the following method outside the testing method
private DynamicBuild getSkippedBuild() { DynamicBuild build = mock(DynamicBuild.class); when(build.isSkipped()).thenReturn(true); return build; }
but when I call this method, I get the following error
org.mockito.exceptions.misusing.UnfinishedStubbingException: Unfinished stubbing detected here: -> at LINE BEING CALLED FROM Eg thenReturn() may be missing. Examples of correct stubbing: when(mock.isOk()).thenReturn(true); when(mock.isOk()).thenThrow(exception); doThrow(exception).when(mock).someVoidMethod(); Hints: 1. missing thenReturn() 2. you are trying to stub a final method, you naughty developer!
It seems that mockito was not happy when you drowned out of the testing method. Is this not supported?
EDIT: I can get this to work by doing stubbing in the @Test method, but I want to reuse stubbing through @Test s.
Surya source share