Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
Specifying behaviour when different parameters passed to mock object method call in Mockito
// Cover all `otherwise` cases first
doThrow(new IllegalArgumentException()).when(mockMessageSource).getMessage(any(String.class), any(Locale.class));
// after that specify requested legal case
doReturn("Merhaba Hayye").when(mockMessageSource).getMessage("hello.message.key", new Locale("tr"));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment