Skip to content

Instantly share code, notes, and snippets.

@baybatu
Last active October 3, 2017 11:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save baybatu/ec8cf3c0229667536f79d8bd79057f23 to your computer and use it in GitHub Desktop.
Save baybatu/ec8cf3c0229667536f79d8bd79057f23 to your computer and use it in GitHub Desktop.
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