Skip to content

Instantly share code, notes, and snippets.

@flaudanum
Created March 9, 2020 16:40
Show Gist options
  • Save flaudanum/6426beb18ca0cf0e6b36a9cc2c89fb2c to your computer and use it in GitHub Desktop.
Save flaudanum/6426beb18ca0cf0e6b36a9cc2c89fb2c to your computer and use it in GitHub Desktop.
Mockito: mock a void method to do nothing
BackendRunner mockedRunner = mock(BackendRunner.class);
// Mock method runProcess() to do nothing
doAnswer(new Answer<Void>() {
public Void answer(InvocationOnMock invocation) {
Object[] args = invocation.getArguments();
System.out.println("called with arguments: " + Arrays.toString(args));
return null;
}
}).when(mockedRunner).runProcess(any());
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment