I’m writing unit tests now. I need to simulate long-run method with Mockito to test my implementation’s timeout handling. Is it possible with Mockito?
Something like this:
when(mockedService.doSomething(a, b)).thenReturn(c).after(5000L);
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
You could simply put the thread to sleep for the desired time. Watch out tho – such things can really slow down your automated test execution, so you might want to isolate such tests in a separate suite
It would look similar to this: