Код: Выделить всё
public void myMethod() {
try {
Thread.sleep(400);
} catch (InterruptedException e) {
throw new RuntimeException(e);
}
}
Есть ли способ заставить код прерваться с помощью Thread.interrupt() или аналогичного?
Я начал пытаться и используйте шпиона:
Код: Выделить всё
Thread threadSpy = spy(new Thread());
threadSpy.interrupt();
assertThatExceptionOfType(RuntimeException.class);
Подробнее здесь: https://stackoverflow.com/questions/791 ... ito-when-t