You should be able to use the doThrow()|doAnswer()|doNothing()|doReturn() family of methods to perform the appropriate action when testing methods that return void, including seters. Therefore, instead of
when(mockedObject.someMethod()).thenReturn(something)
you would use doAnswer() to return a custom response object, although it is not very elegant, and you might be better off using a stub:
doAnswer(new Answer() { public Object answer(InvocationOnMock invocation) { //whatever code you want to run when the method is called return null; }}).when(mockedObject).someMethod(); }
If you are trying to return different values ββfrom the same getter request, you can also look at consecutive consecutive calls to mockito, which will allow you, for example, throw an error for the first method call and then return the object from the second call.
see http://docs.mockito.googlecode.com/hg/org/mockito/Mockito.html#12 for more information on the two.
source share