我有以下代码:
我该如何使用JMockit测试,以确保当Thread.sleep()抛出InterruptedException时,会调用Thread.currentThread().interrupt()方法?
class Sleeper {
public void sleep(long duration) {
try {
Thread.sleep(duration);
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
}
}
}
我该如何使用JMockit测试,以确保当Thread.sleep()抛出InterruptedException时,会调用Thread.currentThread().interrupt()方法?
@Test public void callThreadSleepOnceSomewhere(@Mocked Thread unused) throws Exception { new Expectations() {{ Thread.sleep(anyLong); times = 1; }}; // your code calling Thread.sleep(...) once }
- AntiTiming