Issue
I am new at Junit. I try to write some test codes but I have a question about using "Mockito.when". I know that a test method must has just one assertion. Can I use "Mockito.when" more than once in a test method ? Is it bad practice if I write "Mockito.when" down more than once?
Solution
Well, using frameworks to mock dependencies is already "not-so-good" practice. It means, that your code is not decomposed to use stubs for testing. But in practice we almost always have some code that is "not-so-good". That is why using frameworks like mockito is completely fine: it is much better to test existing code than trying to make it perfect forever. So the answer is simple: you are free to make any number of "when" (or even "assert") statements while your tests are easy to read and maintain. Just make sure that every test is focused on just one test-case.
Answered By - Artyomcool