How to mock and throw an InterruptedException when Thread.sleep() is called.
@Component
public class SomeClass
public String myMethod() {
// do Something
try {
Thread.sleep(3000);
} catch (final InterruptedException ignored) {
log.warn("Interrupted!", ignored);
}
return "Hello";
}
}
I would want to throw an InterruptedException when Thread.sleep() is called. How can I do that with JUnit5 and Mockito