I have a static method that is mocked using PowerMock to throw an exception. (It deletes files.) Unfortunately, during my @After
(after-each-test) method, I need
This took me a while to figure out, so I am answering my own question.
AFAIK, you need to "undo" each mock. Mockito.reset()
will not work with Class>
references. At the end of the test method, add:
// Undo the mock above because we need to call PathUtils.removeFile() within @After.
PowerMockito.doCallRealMethod().when(PathUtils.class);
PathUtils.removeFile(Mockito.any(File.class));