Reputation: 193
I have a method which doesn't return any value actually it process a data frame and registers as temp table, when I try to mock that method for testing I get below error.
is a *void method* and it *cannot* be stubbed with a *return value*!
Voids are usually stubbed with Throwables:
doThrow(exception).when(mock).someVoidMethod();
sample code:
val mock_testmethod=mock[objectwrapper](Answers.RETURNS_DEEP_STUBS)
when mock_testmethod.unitmethod(any[String]).thenReturn(dataframe)
I am new with mocking and scala.
Upvotes: 2
Views: 5106
Reputation: 379
What helped was the following:
when(mockedObject.method()).thenReturn(())
The empty braces in the thenReturn
helped me return a Unit.
Upvotes: 0
Reputation: 1006
Actually the error message has given some hints. So you can:
doNothing().when(mock_testmethod).unitmethod(any[String])
Upvotes: 2