I am testing a method which contain sleep in side it.What is the way to stop invoke sleep() as it makes testing slow??
public void fun(Integer timeToWait) {
TimeLimiter timeLimiter = new SimpleTimeLimiter();
try {
timeLimiter.callWithTimeout(() -> {
while (true) {
if (avrageIsAboveThanDesired) {
return true;
}
sleep(ofSeconds(REQUEST_STATUS_CHECK_INTERVAL));
}
}, timeToWait, TimeUnit.MINUTES, true);
} catch (UncheckedTimeoutException e) {
logger.error("Timed out waiting Instances to be in Running State", e);
} catch (WingsException e) {
throw e;
} catch (Exception e) {
throw new InvalidRequestException("Error while waiting Instaces to be in Running State", e);
}
}