ThreadUtils { public void sleepThread(int secondsToSleep) { try { Thread.sleep(secondsToSleep * ONE_SECOND_IN_MILLISECONDS); } catch (InterruptedException e) { Thread.currentThread().interrupt(); throw new CloudRuntimeException(e); } }  void sleepThread(int secondsToSleep);  }
@Test public void sleepThreadTest() throws InterruptedException { PowerMockito.doNothing().when(Thread.class); Thread.sleep(Mockito.anyLong()); spy.sleepThread(2); PowerMockito.verifyStatic(); Thread.sleep(Mockito.eq(2 * ONE_SECOND_IN_MILLISECONDS)); }
@Test(expected = CloudRuntimeException.class) public void sleepThreadTestCatchInterruptedException() throws InterruptedException { PowerMockito.doThrow(new InterruptedException()).when(Thread.class); Thread.sleep(Mockito.anyLong()); spy.sleepThread(2); PowerMockito.verifyStatic(); Thread.sleep(Mockito.eq(2 * ONE_SECOND_IN_MILLISECONDS)); }