I have a few static util methods in my project, some of them just pass or throw an exception. There are a lot of examples out there on how to mock a static method that has a return type other than void. But how can I mock a static method that returns void to just "doNothing()
"?
The non-void version uses these lines of codes:
@PrepareForTest(StaticResource.class)
...
PowerMockito.mockStatic(StaticResource.class);
...
Mockito.when(StaticResource.getResource("string")).thenReturn("string");
However if applied to a StaticResources
that returns void
, the compile will complain that when(T)
is not applicable for void...
Any ideas?
A workaround would probably be to just have all static methods return some Boolean
for success but I dislike workarounds.