I want to throw a ContentIOException from a method whose signature look like this.
public void putContent(InputStream is) throws ContentIOException.
When I try to throw ContentIOException from Mockito like such:
when(StubbedObject.putContent(contentStream)).thenThrow(ContentIOException.class);
I get the following compilation error:
The method when(T) in the type Mockito is not applicable for the arguments (void).
What am I doing wrong?
Take a look at this reference in the official API. You want to reverse the way your call is made and adjust the argument too, since this is a
voidmethod that you expect to throw an exception.