title: How to test a method using sleep() with Java?
body: <p>I have the following method and I am struggling to get 100% code coverage. </p>
  
  <pre><code>public final class SleepingHelper {
      public static void sleepInMillis(Duration timeOfNextTry) {
          try {
              Thread.sleep(timeOfNextTry.toMillis());
          } catch (InterruptedException e) {
              e.printStackTrace();
          }
      }
  }
  </code></pre>
  
  <p>The question is how can I force <code>Thread.sleep</code> to throw an exception? </p>
  
  <p>Edit: since it was marked as duplicate, I am still wondering what I would assert in the test ? The other question Is more generic.</p>