title: Junit Testing for Thread.sleep() in Java
body: <p>I wanted to write unit test cases for the function to test if the Thread.sleep() function is working. </p>
  
  <p>Can someone please provide a piece of code which would help me achieve this task? : </p>
  
  <pre><code>public class A implements B {
  
   public int func(String A) throws ApplicationException {
  
      int ctr = 0;
      int ans = 0;
  
      for (int i=0;i&lt;100020;i++) {
          try {
                ++ctr;
                if(ctr%50==0)
                {
                     try
                     {
                            Thead.sleep(1000);
                     }
                     catch(java.lang.InterruptedException ie)
                     {
                          System.out.println(ie);
                     }
  
                }
          } 
          catch (Exception e) {
  
          } 
          finally {
  
          }
      }
  
      return ans;
    }
  }
  </code></pre>